]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
refactor(tests): use union types instead of stack-specific types in common tests
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 16 Mar 2026 12:20:30 +0000 (13:20 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 16 Mar 2026 12:20:30 +0000 (13:20 +0100)
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.

tests/charging-station/ChargingStation-Resilience.test.ts
tests/charging-station/broadcast-channel/ChargingStationWorkerBroadcastChannel.test.ts
tests/charging-station/ocpp/OCPPServiceUtils-validation.test.ts

index d9c6394fe84e718aad7dcc2f8482f4e52131974e..525c168fa76f523d78b32d3e1d3ddb00b6587368 100644 (file)
@@ -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)
index c8f743cb697f71174a21276f98e346f2482279ae..902dcd088f1b993e43f5ab72bb9d168cf698ee1c 100644 (file)
@@ -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
       )
 
index 0921e9f0f8feaea65cf4fe67e48da179a8a13a38..9561c1e8fd6a9da93016ff904cae85118d5e5ed7 100644 (file)
@@ -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)
     })