From: Jérôme Benoit Date: Mon, 16 Mar 2026 12:20:30 +0000 (+0100) Subject: refactor(tests): use union types instead of stack-specific types in common tests X-Git-Tag: ocpp-server@v3.1.1~26 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=b994f09525f85f2d0d54f4b15c39bdd6990895d7;p=e-mobility-charging-stations-simulator.git refactor(tests): use union types instead of stack-specific types in common tests Replace OCPP16RequestCommand → RequestCommand, OCPP16IncomingRequestCommand → IncomingRequestCommand, and OCPP20RequestCommand → RequestCommand in test files outside stack-specific directories. Remove redundant 'as Type' casts that were bridging the gap. --- diff --git a/tests/charging-station/ChargingStation-Resilience.test.ts b/tests/charging-station/ChargingStation-Resilience.test.ts index d9c6394f..525c168f 100644 --- a/tests/charging-station/ChargingStation-Resilience.test.ts +++ b/tests/charging-station/ChargingStation-Resilience.test.ts @@ -7,7 +7,7 @@ import { afterEach, beforeEach, describe, it } from 'node:test' import type { ChargingStation } from '../../src/charging-station/ChargingStation.js' -import { OCPP16RequestCommand, RegistrationStatusEnumType } from '../../src/types/index.js' +import { RegistrationStatusEnumType, RequestCommand } from '../../src/types/index.js' import { standardCleanup } from '../helpers/TestLifecycleHelpers.js' import { TEST_HEARTBEAT_INTERVAL_MS } from './ChargingStationTestConstants.js' import { cleanupChargingStation, createMockChargingStation } from './ChargingStationTestUtils.js' @@ -154,7 +154,7 @@ await describe('ChargingStation Resilience', async () => { station.requests.set(messageId, [ responseCallback, errorCallback, - OCPP16RequestCommand.HEARTBEAT, + RequestCommand.HEARTBEAT, {}, ]) @@ -293,10 +293,10 @@ await describe('ChargingStation Resilience', async () => { station.requests.set('req-1', [ callback1, errorCallback1, - OCPP16RequestCommand.BOOT_NOTIFICATION, + RequestCommand.BOOT_NOTIFICATION, {}, ]) - station.requests.set('req-2', [callback2, errorCallback2, OCPP16RequestCommand.HEARTBEAT, {}]) + station.requests.set('req-2', [callback2, errorCallback2, RequestCommand.HEARTBEAT, {}]) // Act - Cleanup station cleanupChargingStation(station) diff --git a/tests/charging-station/broadcast-channel/ChargingStationWorkerBroadcastChannel.test.ts b/tests/charging-station/broadcast-channel/ChargingStationWorkerBroadcastChannel.test.ts index c8f743cb..902dcd08 100644 --- a/tests/charging-station/broadcast-channel/ChargingStationWorkerBroadcastChannel.test.ts +++ b/tests/charging-station/broadcast-channel/ChargingStationWorkerBroadcastChannel.test.ts @@ -18,7 +18,6 @@ import { GetCertificateStatusEnumType, Iso15118EVCertificateStatusEnumType, OCPP20AuthorizationStatusEnumType, - OCPP20RequestCommand, OCPPVersion, ProcedureName, RequestCommand, @@ -548,7 +547,7 @@ await describe('ChargingStationWorkerBroadcastChannel', async () => { const payload = testableRequestService.buildRequestPayload( station, - OCPP20RequestCommand.GET_15118_EV_CERTIFICATE, + RequestCommand.GET_15118_EV_CERTIFICATE, commandParams ) @@ -569,7 +568,7 @@ await describe('ChargingStationWorkerBroadcastChannel', async () => { const payload = testableRequestService.buildRequestPayload( station, - OCPP20RequestCommand.GET_CERTIFICATE_STATUS, + RequestCommand.GET_CERTIFICATE_STATUS, commandParams ) @@ -584,7 +583,7 @@ await describe('ChargingStationWorkerBroadcastChannel', async () => { const payload = testableRequestService.buildRequestPayload( station, - OCPP20RequestCommand.SIGN_CERTIFICATE, + RequestCommand.SIGN_CERTIFICATE, commandParams ) diff --git a/tests/charging-station/ocpp/OCPPServiceUtils-validation.test.ts b/tests/charging-station/ocpp/OCPPServiceUtils-validation.test.ts index 0921e9f0..9561c1e8 100644 --- a/tests/charging-station/ocpp/OCPPServiceUtils-validation.test.ts +++ b/tests/charging-station/ocpp/OCPPServiceUtils-validation.test.ts @@ -16,12 +16,10 @@ import type { ChargingStation } from '../../../src/charging-station/ChargingStat import { OCPPServiceUtils } from '../../../src/charging-station/ocpp/OCPPServiceUtils.js' import { - type IncomingRequestCommand, + IncomingRequestCommand, type MessageTrigger, - OCPP16IncomingRequestCommand, OCPP16MessageTrigger, - OCPP16RequestCommand, - type RequestCommand, + RequestCommand, } from '../../../src/types/index.js' import { standardCleanup } from '../../helpers/TestLifecycleHelpers.js' @@ -47,14 +45,14 @@ await describe('OCPPServiceUtils — command/trigger validation', async () => { const station = makeStationMock({ commandsSupport: { incomingCommands: { - [OCPP16IncomingRequestCommand.RESET]: true, + [IncomingRequestCommand.RESET]: true, }, }, }) const result = OCPPServiceUtils.isIncomingRequestCommandSupported( station, - OCPP16IncomingRequestCommand.RESET as IncomingRequestCommand + IncomingRequestCommand.RESET ) assert.strictEqual(result, true) @@ -64,14 +62,14 @@ await describe('OCPPServiceUtils — command/trigger validation', async () => { const station = makeStationMock({ commandsSupport: { incomingCommands: { - [OCPP16IncomingRequestCommand.RESET]: false, + [IncomingRequestCommand.RESET]: false, }, }, }) const result = OCPPServiceUtils.isIncomingRequestCommandSupported( station, - OCPP16IncomingRequestCommand.RESET as IncomingRequestCommand + IncomingRequestCommand.RESET ) assert.strictEqual(result, false) @@ -82,7 +80,7 @@ await describe('OCPPServiceUtils — command/trigger validation', async () => { const result = OCPPServiceUtils.isIncomingRequestCommandSupported( station, - OCPP16IncomingRequestCommand.RESET as IncomingRequestCommand + IncomingRequestCommand.RESET ) assert.strictEqual(result, true) @@ -95,7 +93,7 @@ await describe('OCPPServiceUtils — command/trigger validation', async () => { const result = OCPPServiceUtils.isIncomingRequestCommandSupported( station, - OCPP16IncomingRequestCommand.RESET as IncomingRequestCommand + IncomingRequestCommand.RESET ) assert.strictEqual(result, true) @@ -107,15 +105,12 @@ await describe('OCPPServiceUtils — command/trigger validation', async () => { const station = makeStationMock({ commandsSupport: { outgoingCommands: { - [OCPP16RequestCommand.HEARTBEAT]: true, + [RequestCommand.HEARTBEAT]: true, }, }, }) - const result = OCPPServiceUtils.isRequestCommandSupported( - station, - OCPP16RequestCommand.HEARTBEAT as RequestCommand - ) + const result = OCPPServiceUtils.isRequestCommandSupported(station, RequestCommand.HEARTBEAT) assert.strictEqual(result, true) }) @@ -124,15 +119,12 @@ await describe('OCPPServiceUtils — command/trigger validation', async () => { const station = makeStationMock({ commandsSupport: { outgoingCommands: { - [OCPP16RequestCommand.HEARTBEAT]: false, + [RequestCommand.HEARTBEAT]: false, }, }, }) - const result = OCPPServiceUtils.isRequestCommandSupported( - station, - OCPP16RequestCommand.HEARTBEAT as RequestCommand - ) + const result = OCPPServiceUtils.isRequestCommandSupported(station, RequestCommand.HEARTBEAT) assert.strictEqual(result, false) }) @@ -140,10 +132,7 @@ await describe('OCPPServiceUtils — command/trigger validation', async () => { await it('should return true when commandsSupport is undefined', () => { const station = makeStationMock({}) - const result = OCPPServiceUtils.isRequestCommandSupported( - station, - OCPP16RequestCommand.HEARTBEAT as RequestCommand - ) + const result = OCPPServiceUtils.isRequestCommandSupported(station, RequestCommand.HEARTBEAT) assert.strictEqual(result, true) }) @@ -153,10 +142,7 @@ await describe('OCPPServiceUtils — command/trigger validation', async () => { commandsSupport: {}, }) - const result = OCPPServiceUtils.isRequestCommandSupported( - station, - OCPP16RequestCommand.HEARTBEAT as RequestCommand - ) + const result = OCPPServiceUtils.isRequestCommandSupported(station, RequestCommand.HEARTBEAT) assert.strictEqual(result, true) })