From fd77bf5f6e233402b65dc554e4bc4c29eed556b8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 1 Apr 2026 20:04:41 +0200 Subject: [PATCH] test(ocpp): move mapStopReasonToOCPP20 tests to OCPP20RequestBuilders.test.ts Align test file structure with source: function moved to OCPP20RequestBuilders.ts, tests follow to the 2.0/ directory. --- .../ocpp/2.0/OCPP20RequestBuilders.test.ts | 44 +++++++++++++++++++ .../ocpp/OCPPServiceUtils-pure.test.ts | 26 ----------- 2 files changed, 44 insertions(+), 26 deletions(-) create mode 100644 tests/charging-station/ocpp/2.0/OCPP20RequestBuilders.test.ts diff --git a/tests/charging-station/ocpp/2.0/OCPP20RequestBuilders.test.ts b/tests/charging-station/ocpp/2.0/OCPP20RequestBuilders.test.ts new file mode 100644 index 00000000..ae61f00c --- /dev/null +++ b/tests/charging-station/ocpp/2.0/OCPP20RequestBuilders.test.ts @@ -0,0 +1,44 @@ +/** + * @file Tests for OCPP20RequestBuilders + * @description Verifies OCPP 2.0 version-specific pure builders + * + * Covers: + * - mapStopReasonToOCPP20 — maps OCPP 1.6 stop reasons to OCPP 2.0 equivalents + */ + +import assert from 'node:assert/strict' +import { afterEach, describe, it } from 'node:test' + +import type { StopTransactionReason } from '../../../../src/types/index.js' + +import { mapStopReasonToOCPP20 } from '../../../../src/charging-station/ocpp/2.0/OCPP20RequestBuilders.js' +import { standardCleanup } from '../../../helpers/TestLifecycleHelpers.js' + +await describe('OCPP20RequestBuilders', async () => { + afterEach(() => { + standardCleanup() + }) + + await describe('mapStopReasonToOCPP20', async () => { + await it('should map Other to Other/AbnormalCondition', () => { + const result = mapStopReasonToOCPP20('Other' as StopTransactionReason) + + assert.strictEqual(result.stoppedReason, 'Other') + assert.strictEqual(result.triggerReason, 'AbnormalCondition') + }) + + await it('should map undefined to Local/StopAuthorized', () => { + const result = mapStopReasonToOCPP20(undefined) + + assert.strictEqual(result.stoppedReason, 'Local') + assert.strictEqual(result.triggerReason, 'StopAuthorized') + }) + + await it('should map Remote to Remote/RemoteStop', () => { + const result = mapStopReasonToOCPP20('Remote' as StopTransactionReason) + + assert.strictEqual(result.stoppedReason, 'Remote') + assert.strictEqual(result.triggerReason, 'RemoteStop') + }) + }) +}) diff --git a/tests/charging-station/ocpp/OCPPServiceUtils-pure.test.ts b/tests/charging-station/ocpp/OCPPServiceUtils-pure.test.ts index 24688d1b..40ba2ca7 100644 --- a/tests/charging-station/ocpp/OCPPServiceUtils-pure.test.ts +++ b/tests/charging-station/ocpp/OCPPServiceUtils-pure.test.ts @@ -7,7 +7,6 @@ * - buildBootNotificationRequest — builds version-specific boot notification payloads * - convertDateToISOString — recursively converts Date objects to ISO strings in-place * - isConnectorIdValid — validates connector ID ranges - * - mapStopReasonToOCPP20 — maps OCPP 1.6 stop reasons to OCPP 2.0 equivalents (from OCPP20RequestBuilders) */ import type { ErrorObject } from 'ajv' @@ -17,7 +16,6 @@ import { afterEach, describe, it } from 'node:test' import type { ChargingStation } from '../../../src/charging-station/index.js' -import { mapStopReasonToOCPP20 } from '../../../src/charging-station/ocpp/2.0/OCPP20RequestBuilders.js' import { ajvErrorsToErrorType, buildBootNotificationRequest, @@ -31,7 +29,6 @@ import { IncomingRequestCommand, type JsonType, OCPPVersion, - type StopTransactionReason, } from '../../../src/types/index.js' import { standardCleanup } from '../../helpers/TestLifecycleHelpers.js' @@ -175,29 +172,6 @@ await describe('OCPPServiceUtils — pure functions', async () => { }) }) - await describe('mapStopReasonToOCPP20', async () => { - await it('should map Other to Other/AbnormalCondition', () => { - const result = mapStopReasonToOCPP20('Other' as StopTransactionReason) - - assert.strictEqual(result.stoppedReason, 'Other') - assert.strictEqual(result.triggerReason, 'AbnormalCondition') - }) - - await it('should map undefined to Local/StopAuthorized', () => { - const result = mapStopReasonToOCPP20(undefined) - - assert.strictEqual(result.stoppedReason, 'Local') - assert.strictEqual(result.triggerReason, 'StopAuthorized') - }) - - await it('should map Remote to Remote/RemoteStop', () => { - const result = mapStopReasonToOCPP20('Remote' as StopTransactionReason) - - assert.strictEqual(result.stoppedReason, 'Remote') - assert.strictEqual(result.triggerReason, 'RemoteStop') - }) - }) - await describe('buildBootNotificationRequest', async () => { await describe('OCPP 1.6', async () => { await it('should build OCPP 1.6 boot notification with required fields', () => { -- 2.53.0