]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
test(ocpp2.0): add Heartbeat, NotifyReport, StatusNotification response tests
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 3 Mar 2026 18:24:40 +0000 (19:24 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 3 Mar 2026 18:24:40 +0000 (19:24 +0100)
Grouped in single file as all three handlers are
trivial (log-only). Completes OCPP 2.0 response
handler coverage from 20% to 100%.

tests/charging-station/ocpp/2.0/OCPP20ResponseService-SimpleHandlers.test.ts [new file with mode: 0644]

diff --git a/tests/charging-station/ocpp/2.0/OCPP20ResponseService-SimpleHandlers.test.ts b/tests/charging-station/ocpp/2.0/OCPP20ResponseService-SimpleHandlers.test.ts
new file mode 100644 (file)
index 0000000..e352f9c
--- /dev/null
@@ -0,0 +1,91 @@
+/**
+ * @file Tests for OCPP20ResponseService simple response handlers
+ * @description Verifies Heartbeat, NotifyReport, and StatusNotification response handling
+ */
+
+import { afterEach, beforeEach, describe, it, mock } from 'node:test'
+
+import type { MockChargingStation } from '../../ChargingStationTestUtils.js'
+
+import { OCPP20ResponseService } from '../../../../src/charging-station/ocpp/2.0/OCPP20ResponseService.js'
+import {
+  type OCPP20HeartbeatResponse,
+  type OCPP20NotifyReportResponse,
+  OCPP20RequestCommand,
+  type OCPP20StatusNotificationResponse,
+  OCPPVersion,
+} from '../../../../src/types/index.js'
+import { Constants } from '../../../../src/utils/index.js'
+import { standardCleanup } from '../../../helpers/TestLifecycleHelpers.js'
+import { TEST_CHARGING_STATION_BASE_NAME } from '../../ChargingStationTestConstants.js'
+import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
+
+/**
+ * Create a mock station suitable for simple response handler tests.
+ * Uses ocppStrictCompliance: false to bypass AJV validation.
+ * @returns A mock station configured for simple handler tests
+ */
+function createSimpleHandlerStation (): MockChargingStation {
+  const { station } = createMockChargingStation({
+    baseName: TEST_CHARGING_STATION_BASE_NAME,
+    connectorsCount: 1,
+    heartbeatInterval: Constants.DEFAULT_HEARTBEAT_INTERVAL,
+    stationInfo: {
+      ocppStrictCompliance: false,
+      ocppVersion: OCPPVersion.VERSION_201,
+    },
+    websocketPingInterval: Constants.DEFAULT_WEBSOCKET_PING_INTERVAL,
+  })
+  return station as MockChargingStation
+}
+
+await describe('Simple response handlers', async () => {
+  let responseService: OCPP20ResponseService
+  let mockStation: MockChargingStation
+
+  beforeEach(() => {
+    mock.timers.enable({ apis: ['setInterval', 'setTimeout'] })
+    responseService = new OCPP20ResponseService()
+    mockStation = createSimpleHandlerStation()
+  })
+
+  afterEach(() => {
+    standardCleanup()
+  })
+
+  await describe('G02 - HeartbeatResponse handler', async () => {
+    await it('should handle Heartbeat response without throwing', async () => {
+      const payload: OCPP20HeartbeatResponse = { currentTime: new Date() }
+      await responseService.responseHandler(
+        mockStation,
+        OCPP20RequestCommand.HEARTBEAT,
+        payload as unknown as Parameters<typeof responseService.responseHandler>[2],
+        {} as Parameters<typeof responseService.responseHandler>[3]
+      )
+    })
+  })
+
+  await describe('B07 - NotifyReportResponse handler', async () => {
+    await it('should handle NotifyReport response without throwing', async () => {
+      const payload: OCPP20NotifyReportResponse = {}
+      await responseService.responseHandler(
+        mockStation,
+        OCPP20RequestCommand.NOTIFY_REPORT,
+        payload as unknown as Parameters<typeof responseService.responseHandler>[2],
+        {} as Parameters<typeof responseService.responseHandler>[3]
+      )
+    })
+  })
+
+  await describe('G01 - StatusNotificationResponse handler', async () => {
+    await it('should handle StatusNotification response without throwing', async () => {
+      const payload: OCPP20StatusNotificationResponse = {}
+      await responseService.responseHandler(
+        mockStation,
+        OCPP20RequestCommand.STATUS_NOTIFICATION,
+        payload as unknown as Parameters<typeof responseService.responseHandler>[2],
+        {} as Parameters<typeof responseService.responseHandler>[3]
+      )
+    })
+  })
+})