From: Jérôme Benoit Date: Wed, 12 Nov 2025 13:57:19 +0000 (+0100) Subject: test: fix tests X-Git-Tag: ocpp-server@v2.2.0~52^2 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=8e8c0ed6d9752b16bdc147cb13fdcfe05a201a21;p=e-mobility-charging-stations-simulator.git test: fix tests Signed-off-by: Jérôme Benoit --- diff --git a/tests/ChargingStationFactory.ts b/tests/ChargingStationFactory.ts index 93490b3e..accdc49f 100644 --- a/tests/ChargingStationFactory.ts +++ b/tests/ChargingStationFactory.ts @@ -2,6 +2,7 @@ import { millisecondsToSeconds } from 'date-fns' import type { ChargingStation } from '../src/charging-station/index.js' +import { getConfigurationKey } from '../src/charging-station/ConfigurationKeyUtils.js' import { IdTagsCache } from '../src/charging-station/IdTagsCache.js' import { AvailabilityType, @@ -15,8 +16,9 @@ import { OCPPVersion, RegistrationStatusEnumType, type SampledValueTemplate, + StandardParametersKey, } from '../src/types/index.js' -import { clone, Constants } from '../src/utils/index.js' +import { clone, Constants, convertToBoolean } from '../src/utils/index.js' /** * Options to customize the construction of a ChargingStation test instance @@ -139,6 +141,13 @@ export function createChargingStation (options: ChargingStationOptions = {}): Ch return undefined }, getHeartbeatInterval: () => heartbeatInterval, + getLocalAuthListEnabled: (): boolean => { + const localAuthListEnabled = getConfigurationKey( + chargingStation, + StandardParametersKey.LocalAuthListEnabled + ) + return localAuthListEnabled != null ? convertToBoolean(localAuthListEnabled.value) : false + }, getWebSocketPingInterval: () => websocketPingInterval, hasEvses: useEvses, idTagsCache: IdTagsCache.getInstance(), @@ -169,6 +178,10 @@ export function createChargingStation (options: ChargingStationOptions = {}): Ch key: OCPP20OptionalVariableName.HeartbeatInterval, value: millisecondsToSeconds(heartbeatInterval).toString(), }, + { + key: StandardParametersKey.LocalAuthListEnabled, + value: 'true', + }, ], ...options.ocppConfiguration, }, @@ -227,6 +240,7 @@ export function createChargingStation (options: ChargingStationOptions = {}): Ch maximumAmperage: 16, maximumPower: 12000, ocppVersion: OCPPVersion.VERSION_16, + remoteAuthorization: true, templateIndex, templateName: 'test-template.json', ...options.stationInfo, diff --git a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStartTransaction.test.ts b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStartTransaction.test.ts index 17e34a75..27dd75a2 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStartTransaction.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStartTransaction.test.ts @@ -51,7 +51,7 @@ await describe('E01 - Remote Start Transaction', async () => { remoteStartId: 1, } - const response = await (incomingRequestService as any).handleRequestRequestStartTransaction( + const response = await (incomingRequestService as any).handleRequestStartTransaction( mockChargingStation, validRequest ) @@ -72,7 +72,7 @@ await describe('E01 - Remote Start Transaction', async () => { remoteStartId: 42, } - const response = await (incomingRequestService as any).handleRequestRequestStartTransaction( + const response = await (incomingRequestService as any).handleRequestStartTransaction( mockChargingStation, requestWithRemoteStartId ) @@ -96,7 +96,7 @@ await describe('E01 - Remote Start Transaction', async () => { remoteStartId: 3, } - const response = await (incomingRequestService as any).handleRequestRequestStartTransaction( + const response = await (incomingRequestService as any).handleRequestStartTransaction( mockChargingStation, requestWithGroupToken ) @@ -120,7 +120,7 @@ await describe('E01 - Remote Start Transaction', async () => { // Should throw OCPPError for invalid evseId await expect( - (incomingRequestService as any).handleRequestRequestStartTransaction( + (incomingRequestService as any).handleRequestStartTransaction( mockChargingStation, invalidEvseRequest ) @@ -138,7 +138,7 @@ await describe('E01 - Remote Start Transaction', async () => { remoteStartId: 100, } - await (incomingRequestService as any).handleRequestRequestStartTransaction( + await (incomingRequestService as any).handleRequestStartTransaction( mockChargingStation, firstRequest ) @@ -153,7 +153,7 @@ await describe('E01 - Remote Start Transaction', async () => { remoteStartId: 101, } - const response = await (incomingRequestService as any).handleRequestRequestStartTransaction( + const response = await (incomingRequestService as any).handleRequestStartTransaction( mockChargingStation, secondRequest ) @@ -173,7 +173,7 @@ await describe('E01 - Remote Start Transaction', async () => { remoteStartId: 200, } - const response = await (incomingRequestService as any).handleRequestRequestStartTransaction( + const response = await (incomingRequestService as any).handleRequestStartTransaction( mockChargingStation, validRequest ) diff --git a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStopTransaction.test.ts b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStopTransaction.test.ts index dcf17b50..51deb676 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStopTransaction.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStopTransaction.test.ts @@ -111,9 +111,10 @@ await describe('E02 - Remote Stop Transaction', async () => { remoteStartId, } - const startResponse = await ( - incomingRequestService as any - ).handleRequestRequestStartTransaction(mockChargingStation, startRequest) + const startResponse = await (incomingRequestService as any).handleRequestStartTransaction( + mockChargingStation, + startRequest + ) expect(startResponse.status).toBe(RequestStartStopStatusEnumType.Accepted) expect(startResponse.transactionId).toBeDefined() @@ -133,7 +134,7 @@ await describe('E02 - Remote Stop Transaction', async () => { } // Execute stop transaction - const response = await (incomingRequestService as any).handleRequestRequestStopTransaction( + const response = await (incomingRequestService as any).handleRequestStopTransaction( mockChargingStation, stopRequest ) @@ -170,7 +171,7 @@ await describe('E02 - Remote Stop Transaction', async () => { transactionId: transactionId2 as `${string}-${string}-${string}-${string}-${string}`, } - const response = await (incomingRequestService as any).handleRequestRequestStopTransaction( + const response = await (incomingRequestService as any).handleRequestStopTransaction( mockChargingStation, stopRequest ) @@ -201,7 +202,7 @@ await describe('E02 - Remote Stop Transaction', async () => { nonExistentTransactionId as `${string}-${string}-${string}-${string}-${string}`, } - const response = await (incomingRequestService as any).handleRequestRequestStopTransaction( + const response = await (incomingRequestService as any).handleRequestStopTransaction( mockChargingStation, stopRequest ) @@ -222,7 +223,7 @@ await describe('E02 - Remote Stop Transaction', async () => { transactionId: '' as `${string}-${string}-${string}-${string}-${string}`, } - const response = await (incomingRequestService as any).handleRequestRequestStopTransaction( + const response = await (incomingRequestService as any).handleRequestStopTransaction( mockChargingStation, invalidRequest ) @@ -245,7 +246,7 @@ await describe('E02 - Remote Stop Transaction', async () => { transactionId: tooLongTransactionId as `${string}-${string}-${string}-${string}-${string}`, } - const response = await (incomingRequestService as any).handleRequestRequestStopTransaction( + const response = await (incomingRequestService as any).handleRequestStopTransaction( mockChargingStation, invalidRequest ) @@ -286,7 +287,7 @@ await describe('E02 - Remote Stop Transaction', async () => { transactionId: testTransactionId as `${string}-${string}-${string}-${string}-${string}`, } - const response = await (incomingRequestService as any).handleRequestRequestStopTransaction( + const response = await (incomingRequestService as any).handleRequestStopTransaction( mockChargingStation, stopRequest ) @@ -335,9 +336,10 @@ await describe('E02 - Remote Stop Transaction', async () => { remoteStartId: 999, } - const startResponse = await ( - incomingRequestService as any - ).handleRequestRequestStartTransaction(failingChargingStation, startRequest) + const startResponse = await (incomingRequestService as any).handleRequestStartTransaction( + failingChargingStation, + startRequest + ) const transactionId = startResponse.transactionId as string @@ -346,7 +348,7 @@ await describe('E02 - Remote Stop Transaction', async () => { transactionId: transactionId as `${string}-${string}-${string}-${string}-${string}`, } - const response = await (incomingRequestService as any).handleRequestRequestStopTransaction( + const response = await (incomingRequestService as any).handleRequestStopTransaction( failingChargingStation, stopRequest ) @@ -367,7 +369,7 @@ await describe('E02 - Remote Stop Transaction', async () => { transactionId: transactionId as `${string}-${string}-${string}-${string}-${string}`, } - const response = await (incomingRequestService as any).handleRequestRequestStopTransaction( + const response = await (incomingRequestService as any).handleRequestStopTransaction( mockChargingStation, stopRequest ) @@ -399,7 +401,7 @@ await describe('E02 - Remote Stop Transaction', async () => { transactionId: transactionId as `${string}-${string}-${string}-${string}-${string}`, } - const response = await (incomingRequestService as any).handleRequestRequestStopTransaction( + const response = await (incomingRequestService as any).handleRequestStopTransaction( mockChargingStation, stopRequestWithCustomData ) @@ -423,7 +425,7 @@ await describe('E02 - Remote Stop Transaction', async () => { transactionId: transactionId as `${string}-${string}-${string}-${string}-${string}`, } - const response = await (incomingRequestService as any).handleRequestRequestStopTransaction( + const response = await (incomingRequestService as any).handleRequestStopTransaction( mockChargingStation, stopRequest )