Skip to content

test(ui-common): cover buildStatusNotificationPayload 1.6/2.0.x branches (#1834) - #1902

Merged
jerome-benoit merged 2 commits into
mainfrom
test/1834-payload-builders-status-notification-coverage
Jun 15, 2026
Merged

jerome-benoit merged 2 commits into
mainfrom
test/1834-payload-builders-status-notification-coverage

Conversation

@jerome-benoit

Copy link
Copy Markdown
Contributor

Summary

ui/common/src/utils/payloadBuilders.ts exports
buildStatusNotificationPayload (introduced by #1834 to share the
OCPP 1.6 vs 2.0.x branching between CLI and Web UI). Its sibling
builders (buildAuthorizePayload, buildStartTransactionPayload,
buildStopTransactionPayload, buildIdToken, isOCPP20x) all have
describe blocks in ui/common/tests/payloadBuilders.test.ts, but
buildStatusNotificationPayload had none. The S3 regression-focus gate
was therefore vacuous for this builder.

This PR adds a dedicated describe('buildStatusNotificationPayload')
block matching the existing file style. Production code in
payloadBuilders.ts is not touched.

New cases (9)

# Branch Scenario
1 OCPP 1.6 explicit errorCode → {connectorId, status, errorCode}
2 OCPP 1.6 errorCode omitted → payload omits errorCode (no NoError default)
3 OCPP 1.6 evseId pass-through with errorCode
4 OCPP 1.6 ocppVersion = undefined falls through to 1.6 shape
5 OCPP 1.6 unsupported version ('3.0') → throws via assertOCPP16OrUndefined
6 OCPP 2.0.1 evseId provided → {connectorId, connectorStatus, evseId}, no status/errorCode
7 OCPP 2.0 no evseId → {connectorId, connectorStatus}
8 OCPP 2.0.1 errorCode option ignored (1.6-only field)
9 dispatch same input, different ocppVersion → different shape in the documented way

OCPP enum constants are used directly
(OCPP16ChargePointStatus, OCPP16ChargePointErrorCode,
OCPP20ConnectorStatusEnumType, OCPPVersion) per the AGENTS.md
OCPP-conventions rule "Avoid string literals when an enumeration exists".

Spec-vs-reality findings (for maintainer review)

While writing the tests against the function's actual behaviour, two
points in the original test plan diverge from what the code does. Per
the task instructions ("verify against the function's actual behaviour,
do NOT invent" and "if you find a real bug while writing tests, STOP,
document it in the PR description"), I am surfacing these without
modifying production code.

Finding A — errorCode omitted (no NoError default)

Plan (test #2): "OCPP 1.6 with errorCode omitted → defaults to
NoError."

Actual (payloadBuilders.ts):

return {
  connectorId,
  status,
  ...(options?.errorCode != null && { errorCode: options.errorCode }),
  ...(options?.evseId != null && { evseId: options.evseId }),
}

When errorCode is omitted, the field is dropped from the payload;
no default is applied. Test case #2 asserts the actual behaviour
(errorCode absent), not the planned default.

If the maintainer's intent is that the simulator-emitted OCPP 1.6
StatusNotification should carry an explicit errorCode: "NoError"
(per OCPP 1.6 §6.31 where errorCode is required on the wire), this is
a small follow-up worth a separate PR. I did not change behaviour here.

Finding B — no runtime status validation

Plan (tests #3 and #5): "invalid status enum → throws / returns
rejection per the function contract."

Actual: the function takes
status: ChargePointStatus = OCPP16ChargePointStatus | OCPP20ConnectorStatusEnumType
and passes the value straight into the returned object. The only
runtime-rejection contract is assertOCPP16OrUndefined(version), which
throws for unsupported ocppVersion values such as '3.0'. There is
no runtime validation of status itself — type-level only.

I did not introduce as any / // @ts-ignore casts to fabricate a
runtime-invalid status (per AGENTS.md type-safety conventions and the
explicit task constraint). Instead, case #5 tests the actual rejection
contract — unsupported version — which is also exercised by the sibling
builder tests (buildAuthorizePayload, line 62-67).

If the maintainer wants runtime enum validation for status and/or
errorCode, that is a behaviour change and belongs in a separate PR.

Quality gates

Command Result
pnpm --filter ui-common typecheck exit 0
pnpm --filter ui-common lint exit 0
pnpm --filter ui-common test 114 pass / 0 fail (was 105, +9 new)
pnpm --filter ui-common test:coverage see below

Coverage report (lcov, src/utils/payloadBuilders.ts)

SF:src/utils/payloadBuilders.ts
FN:9,buildAuthorizePayload                FNDA:5
FN:15,buildIdToken                        FNDA:2
FN:19,buildStartTransactionPayload        FNDA:5
FN:44,buildStatusNotificationPayload      FNDA:10
FN:55,buildStopTransactionPayload         FNDA:4
FN:67,isOCPP20x                           FNDA:28
FN:73,assertOCPP16OrUndefined             FNDA:12
FNF:8     FNH:8     (functions:  100%)
BRF:32    BRH:32    (branches:   100%)
LF:162    LH:162    (lines:      100%)
end_of_record

buildStatusNotificationPayload (line 44) is now hit 10 times
across the new test cases, fully covering both the OCPP 1.6 and OCPP
2.0.x branches plus the version-dispatch path.

Out of scope

  • No production code change in payloadBuilders.ts.
  • Spec-vs-reality findings A and B above are documented, not fixed.

Severity

MAJOR — test hygiene gap closed; S3 regression-focus gate now non-vacuous
for buildStatusNotificationPayload.

…hes (#1834)

Adds a describe('buildStatusNotificationPayload') block matching the
existing payloadBuilders.test.ts style. Cases (9):

OCPP 1.6
- explicit errorCode: payload carries {connectorId, status, errorCode}
- errorCode omitted: payload omits errorCode (no NoError default)
- evseId pass-through with errorCode
- ocppVersion=undefined falls through to 1.6 shape
- unsupported version (e.g. '3.0') throws via assertOCPP16OrUndefined

OCPP 2.0.x
- VERSION_201 + evseId: {connectorId, connectorStatus, evseId}, no
  status / errorCode fields
- VERSION_20 without evseId: {connectorId, connectorStatus}
- errorCode option ignored (1.6-only field)

Cross-version
- same input, different ocppVersion: shapes differ in the documented
  way (status vs connectorStatus, errorCode/evseId presence)

Uses OCPP enum constants directly (OCPP16ChargePointStatus,
OCPP16ChargePointErrorCode, OCPP20ConnectorStatusEnumType,
OCPPVersion) per the OCPP enumeration-naming convention. Production
code in payloadBuilders.ts is unchanged.
@hyperspace-pr-bot

Copy link
Copy Markdown
Contributor

Summary

The following content is AI-generated and provides a summary of the pull request:


test(ui-common): Add test coverage for buildStatusNotificationPayload

Test

🧪 Adds a dedicated describe('buildStatusNotificationPayload') block to ui/common/tests/payloadBuilders.test.ts, closing a test coverage gap for the OCPP 1.6 vs 2.0.x branching logic introduced in #1834. No production code is modified.

Changes

  • ui/common/tests/payloadBuilders.test.ts: Imports OCPP16ChargePointErrorCode, OCPP16ChargePointStatus, OCPP20ConnectorStatusEnumType, and buildStatusNotificationPayload. Adds 9 new test cases covering:
    • OCPP 1.6: explicit errorCode, omitted errorCode (field dropped, no default), evseId pass-through, undefined version falling through to 1.6 shape, and unsupported version throwing via assertOCPP16OrUndefined
    • OCPP 2.0.x: evseId included, evseId omitted, errorCode option correctly ignored (1.6-only field)
    • Dispatch: same connector input with different ocppVersion values produces distinct payload shapes

Notable findings (documented, not fixed)

  • errorCode omitted → field dropped (no NoError default): the current implementation conditionally spreads errorCode only when present; the test asserts actual behaviour.
  • No runtime status validation: the function relies on TypeScript types only; runtime rejection is limited to unsupported ocppVersion values (tested in case Update issue templates #5).

Quality gates

Check Result
typecheck ✅ exit 0
lint ✅ exit 0
test ✅ 114 pass / 0 fail (+9 new)
coverage (payloadBuilders.ts) ✅ 100% functions, branches, lines

GitHub Issues

  • #1834: fix(ui): allow changing status of individual connectors

  • 🔄 Regenerate and Update Summary
  • ✏️ Insert as PR Description (deletes this comment)
  • 🗑️ Delete comment
PR Bot Information

Version: 1.23.0

@hyperspace-pr-bot hyperspace-pr-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR adds solid test coverage for buildStatusNotificationPayload. Two issues were flagged: the assert.throws validator should use a RegExp instead of a bare .includes() boolean (which can mask failures), and the "pass evseId through for OCPP 1.6" test conflates two behaviours — the evseId-only OCPP 1.6 path is never independently exercised since the test always pairs it with errorCode.

PR Bot Information

Version: 1.23.0

Comment thread ui/common/tests/payloadBuilders.test.ts Resolved
Comment thread ui/common/tests/payloadBuilders.test.ts Resolved
…ation

Address review comment on #1902: the prior test 'should pass evseId
through for OCPP 1.6 when provided' passed both errorCode and evseId
together, so the evseId-only OCPP 1.6 branch was never independently
exercised. The errorCode-only path is already covered by the case
'should build OCPP 1.6 payload with status and explicit errorCode',
and the combined case is trivial composition of the two via the
spread syntax in the function body.

Test renamed to 'should pass evseId through for OCPP 1.6 without
errorCode' and now only passes options.evseId, asserting errorCode is
absent from the resulting payload.
@jerome-benoit
jerome-benoit merged commit 8fc0b49 into main Jun 15, 2026
44 checks passed
jerome-benoit added a commit that referenced this pull request Jun 15, 2026
…hes (#1834) (#1904)

* 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.
@jerome-benoit
jerome-benoit deleted the test/1834-payload-builders-status-notification-coverage branch June 15, 2026 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant