]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
test(ui-common): cover buildStatusNotificationPayload 1.6/2.0.x branches (#1834)...
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Mon, 15 Jun 2026 19:34:42 +0000 (21:34 +0200)
committerGitHub <noreply@github.com>
Mon, 15 Jun 2026 19:34:42 +0000 (21:34 +0200)
* 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

index 08237589f56b3a4ab37bedb34f9a2c59fcc330ae..95eac4fdaff2f19825cd4d35819f34bfbb24e460 100644 (file)
@@ -224,6 +224,21 @@ await describe('payloadBuilders', async () => {
       assert.strictEqual((result as Record<string, unknown>).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(
         () =>