import { AutomaticTransactionGenerator } from '../../src/charging-station/AutomaticTransactionGenerator.js'
import { BaseError } from '../../src/exception/index.js'
import { type StartTransactionResult } from '../../src/types/index.js'
+import { Constants } from '../../src/utils/Constants.js'
import { flushMicrotasks } from '../helpers/TestLifecycleHelpers.js'
import { createMockChargingStation, standardCleanup } from './ChargingStationTestUtils.js'
getAutomaticTransactionGeneratorStatuses: () => undefined | unknown[]
}
stationExt.getAutomaticTransactionGeneratorConfiguration = () => ({
+ ...Constants.DEFAULT_ATG_CONFIGURATION,
enable: true,
idTagDistribution: 'random',
- maxDelayBetweenTwoTransactions: 30,
- maxDuration: 120,
- minDelayBetweenTwoTransactions: 15,
- minDuration: 60,
- probabilityOfStart: 1,
requireAuthorize: false,
- stopAbsoluteDuration: false,
stopAfterHours: 1,
})
stationExt.getAutomaticTransactionGeneratorStatuses = () => undefined
*/
export const TEST_CUSTOM_HEARTBEAT_INTERVAL_SECONDS = 120
export const TEST_REJECTED_HEARTBEAT_INTERVAL_SECONDS = TEST_ONE_HOUR_SECONDS
+export const TEST_RESERVATION_EXPIRY_MS = TEST_ONE_HOUR_MS
/**
* OCPP 2.0 Value Size Limits
import { Bootstrap } from '../../src/charging-station/Bootstrap.js'
import { SharedLRUCache } from '../../src/charging-station/SharedLRUCache.js'
import { StandardParametersKey } from '../../src/types/index.js'
+import { Constants } from '../../src/utils/Constants.js'
import { standardCleanup } from '../helpers/TestLifecycleHelpers.js'
interface BootstrapStatic {
*/
function createCacheableConfiguration (hash: string): ChargingStationConfiguration {
return {
- automaticTransactionGenerator: { enable: false, maxDuration: 120, minDuration: 60 },
+ automaticTransactionGenerator: { ...Constants.DEFAULT_ATG_CONFIGURATION },
configurationHash: hash,
configurationKey: [
{ key: StandardParametersKey.HeartbeatInterval, readonly: false, value: '60' },
OCPP16StandardParametersKey,
} from '../../../../src/types/index.js'
import { standardCleanup } from '../../../helpers/TestLifecycleHelpers.js'
-import { TEST_ID_TAG } from '../../ChargingStationTestConstants.js'
+import { TEST_ID_TAG, TEST_RESERVATION_EXPIRY_MS } from '../../ChargingStationTestConstants.js'
import {
createOCPP16IncomingRequestTestContext,
type OCPP16IncomingRequestTestContext,
enableReservationProfile(context, true)
const request: OCPP16ReserveNowRequest = {
connectorId: 0,
- expiryDate: new Date(Date.now() + 3600000),
+ expiryDate: new Date(Date.now() + TEST_RESERVATION_EXPIRY_MS),
idTag: TEST_ID_TAG,
reservationId: 10,
}
enableReservationProfile(context, false)
const request: OCPP16ReserveNowRequest = {
connectorId: 0,
- expiryDate: new Date(Date.now() + 3600000),
+ expiryDate: new Date(Date.now() + TEST_RESERVATION_EXPIRY_MS),
idTag: TEST_ID_TAG,
reservationId: 10,
}
}
const request: OCPP16ReserveNowRequest = {
connectorId: 1,
- expiryDate: new Date(Date.now() + 3600000),
+ expiryDate: new Date(Date.now() + TEST_RESERVATION_EXPIRY_MS),
idTag: TEST_ID_TAG,
reservationId: 2,
}
upsertConfigurationKey(station, OCPP16StandardParametersKey.SupportedFeatureProfiles, 'Core')
const request: OCPP16ReserveNowRequest = {
connectorId: 1,
- expiryDate: new Date(Date.now() + 3600000),
+ expiryDate: new Date(Date.now() + TEST_RESERVATION_EXPIRY_MS),
idTag: TEST_ID_TAG,
reservationId: 3,
}
enableReservationProfile(context)
const request: OCPP16ReserveNowRequest = {
connectorId: 99,
- expiryDate: new Date(Date.now() + 3600000),
+ expiryDate: new Date(Date.now() + TEST_RESERVATION_EXPIRY_MS),
idTag: TEST_ID_TAG,
reservationId: 4,
}
setupConnectorWithTransaction,
standardCleanup,
} from '../../../helpers/TestLifecycleHelpers.js'
-import { TEST_ID_TAG } from '../../ChargingStationTestConstants.js'
+import { TEST_ID_TAG, TEST_RESERVATION_EXPIRY_MS } from '../../ChargingStationTestConstants.js'
import { createOCPP16ResponseTestContext, setMockRequestHandler } from './OCPP16TestUtils.js'
await describe('OCPP16ResponseService — StartTransaction and StopTransaction', async () => {
if (connectorStatus != null) {
connectorStatus.reservation = {
connectorId,
- expiryDate: new Date(Date.now() + 3600000),
+ expiryDate: new Date(Date.now() + TEST_RESERVATION_EXPIRY_MS),
idTag: TEST_ID_TAG,
reservationId,
}
createMockUIServerConfiguration,
} from './UIServerTestUtils.js'
+const TEST_TIMEOUT_MS = 30_000
+
class TestableUIMCPServer extends UIMCPServer {
public constructor (config: UIServerConfiguration) {
super(config, createMockBootstrap())
})
await it('should return true when uuid is in pendingMcpRequests', () => {
- const timeout = setTimeout(() => undefined, 30000)
+ const timeout = setTimeout(() => undefined, TEST_TIMEOUT_MS)
const pendingMap = server.getPendingMcpRequestsMap()
pendingMap.set(TEST_UUID, {
reject: (_error: Error) => undefined,
await describe('sendResponse Promise bridge', async () => {
await it('should resolve pending Promise when sendResponse called with matching UUID', () => {
let resolvedPayload: ResponsePayload | undefined
- const timeout = setTimeout(() => undefined, 30000)
+ const timeout = setTimeout(() => undefined, TEST_TIMEOUT_MS)
const pendingMap = server.getPendingMcpRequestsMap()
pendingMap.set(TEST_UUID, {
reject: (_error: Error) => undefined,
await it('should clear timeout when resolving pending request', t => {
const clearTimeoutMock = t.mock.method(globalThis, 'clearTimeout')
- const timeout = setTimeout(() => undefined, 30000)
+ const timeout = setTimeout(() => undefined, TEST_TIMEOUT_MS)
const pendingMap = server.getPendingMcpRequestsMap()
pendingMap.set(TEST_UUID, {
reject: (_error: Error) => undefined,
})
await it('should delete pending entry after resolve', () => {
- const timeout = setTimeout(() => undefined, 30000)
+ const timeout = setTimeout(() => undefined, TEST_TIMEOUT_MS)
const pendingMap = server.getPendingMcpRequestsMap()
pendingMap.set(TEST_UUID, {
reject: (_error: Error) => undefined,
await describe('stop cleanup', async () => {
await it('should reject all pending requests on stop', () => {
const rejectedErrors: Error[] = []
- const timeout1 = setTimeout(() => undefined, 30000)
- const timeout2 = setTimeout(() => undefined, 30000)
+ const timeout1 = setTimeout(() => undefined, TEST_TIMEOUT_MS)
+ const timeout2 = setTimeout(() => undefined, TEST_TIMEOUT_MS)
const pendingMap = server.getPendingMcpRequestsMap()
pendingMap.set(TEST_UUID, {
await it('should clear all timeouts on stop', t => {
const clearTimeoutMock = t.mock.method(globalThis, 'clearTimeout')
- const timeout1 = setTimeout(() => undefined, 30000)
- const timeout2 = setTimeout(() => undefined, 30000)
+ const timeout1 = setTimeout(() => undefined, TEST_TIMEOUT_MS)
+ const timeout2 = setTimeout(() => undefined, TEST_TIMEOUT_MS)
const pendingMap = server.getPendingMcpRequestsMap()
pendingMap.set(TEST_UUID, {
})
await it('should clear pending map on stop', () => {
- const timeout = setTimeout(() => undefined, 30000)
+ const timeout = setTimeout(() => undefined, TEST_TIMEOUT_MS)
const pendingMap = server.getPendingMcpRequestsMap()
pendingMap.set(TEST_UUID, {
buildEvseEntries,
buildEvsesStatus,
} from '../../src/utils/ChargingStationConfigurationUtils.js'
+import { Constants } from '../../src/utils/Constants.js'
import {
cleanupChargingStation,
createMockChargingStation,
await describe('buildChargingStationAutomaticTransactionGeneratorConfiguration', async () => {
await it('should return ATG configuration when present', () => {
- const atgConfiguration = { enable: true, maxDuration: 120, minDuration: 60 }
+ const atgConfiguration = { ...Constants.DEFAULT_ATG_CONFIGURATION, enable: true }
const { station } = createMockChargingStation({ connectorsCount: 0 })
testStation = station
station.automaticTransactionGenerator = {