From f9e8ddfabec327b1ef2d0b76652fed9b1f334408 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 15 Jun 2026 21:34:42 +0200 Subject: [PATCH] test(ui-common): cover buildStatusNotificationPayload 1.6/2.0.x branches (#1834) (#1904) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * test(ui-common): cover buildStatusNotificationPayload 1.6/2.0.x branches (#1834) Audit pass over the describe('buildStatusNotificationPayload') block added by PR #1902. Adds the only two production-callsite-tied cases the existing 9 tests miss. No production code change. T2.1 — OCPP 1.6 with errorCode and evseId together: - Tied to ui/cli/src/commands/ocpp.ts:191-203 (1.6 requires --error-code, passes evseId) and ui/web/src/skins/classic/components/charging-stations /CSConnector.vue:172-173 (selectedErrorCode defaults to NO_ERROR). - Existing tests cover errorCode-without-evseId and evseId-without- errorCode but never both flags together — the actual production path. T2.2 — undefined ocppVersion with errorCode and evseId: - Tied to ui/web/src/core/UIClient.ts:141-155 + ui/web/src/shared/composables/useConnectorActions.ts:113-122 where setConnectorStatus is unconditionally invoked with both options even when props.ocppVersion is OCPPVersion | undefined. - Existing 'undefined version' test omits both options; this asserts the 1.6 fallthrough preserves them. 3-angle audit found other proposals (cross-enum mismatch guard, marking existing cases [SYNTHETIC], structural refactor into nested describes) but they did not survive cross-validation: the first requires a runtime guard in payloadBuilders.ts (out of scope per task spec), the second is subjective, the third is cosmetic per AGENTS.md 'small verifiable changes'. * test(ui-common): align buildStatusNotificationPayload test names with style guide Address review feedback on #1904. Both new test names violated tests/TEST_STYLE_GUIDE.md "should [verb] in lowercase" describing observable behavior: - T2.1 carried a callsite traceability annotation '(CLI + Web UI 1.6 path)' in the title. - T2.2 used the implementation-internal term 'fall through' plus a '(Web UI undefined-version path)' annotation. Renamed to mirror the existing sibling tests in the same describe block: - T2.1: 'should pass errorCode and evseId through for OCPP 1.6 when both are provided' (mirrors 'should pass evseId through for OCPP 1.6 without errorCode'). - T2.2: 'should default to OCPP 1.6 shape with errorCode and evseId when ocppVersion is undefined' (mirrors 'should default to OCPP 1.6 shape when ocppVersion is undefined'). Callsite traceability lives in the commit message + PR body, not the test title — matches the convention of all 9 prior cases in the same describe. No assertion change. 116/116 tests pass. --- ui/common/tests/payloadBuilders.test.ts | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/ui/common/tests/payloadBuilders.test.ts b/ui/common/tests/payloadBuilders.test.ts index 08237589..95eac4fd 100644 --- a/ui/common/tests/payloadBuilders.test.ts +++ b/ui/common/tests/payloadBuilders.test.ts @@ -224,6 +224,21 @@ await describe('payloadBuilders', async () => { assert.strictEqual((result as Record).errorCode, undefined) }) + await it('should pass errorCode and evseId through for OCPP 1.6 when both are provided', () => { + const result = buildStatusNotificationPayload( + connectorId, + OCPP16ChargePointStatus.AVAILABLE, + OCPPVersion.VERSION_16, + { errorCode: OCPP16ChargePointErrorCode.NO_ERROR, evseId: 2 } + ) + assert.deepStrictEqual(result, { + connectorId, + errorCode: OCPP16ChargePointErrorCode.NO_ERROR, + evseId: 2, + status: OCPP16ChargePointStatus.AVAILABLE, + }) + }) + await it('should default to OCPP 1.6 shape when ocppVersion is undefined', () => { const result = buildStatusNotificationPayload( connectorId, @@ -236,6 +251,21 @@ await describe('payloadBuilders', async () => { }) }) + await it('should default to OCPP 1.6 shape with errorCode and evseId when ocppVersion is undefined', () => { + const result = buildStatusNotificationPayload( + connectorId, + OCPP16ChargePointStatus.AVAILABLE, + undefined, + { errorCode: OCPP16ChargePointErrorCode.NO_ERROR, evseId: 2 } + ) + assert.deepStrictEqual(result, { + connectorId, + errorCode: OCPP16ChargePointErrorCode.NO_ERROR, + evseId: 2, + status: OCPP16ChargePointStatus.AVAILABLE, + }) + }) + await it('should throw for unsupported OCPP version', () => { assert.throws( () => -- 2.53.0