From 458423e20644057822b32e4ded64117f431ae799 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 3 Mar 2026 19:24:40 +0100 Subject: [PATCH] test(ocpp2.0): add Heartbeat, NotifyReport, StatusNotification response tests Grouped in single file as all three handlers are trivial (log-only). Completes OCPP 2.0 response handler coverage from 20% to 100%. --- ...PP20ResponseService-SimpleHandlers.test.ts | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 tests/charging-station/ocpp/2.0/OCPP20ResponseService-SimpleHandlers.test.ts 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 index 00000000..e352f9c9 --- /dev/null +++ b/tests/charging-station/ocpp/2.0/OCPP20ResponseService-SimpleHandlers.test.ts @@ -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[2], + {} as Parameters[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[2], + {} as Parameters[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[2], + {} as Parameters[3] + ) + }) + }) +}) -- 2.53.0