Repository navigation
test(ui-common): cover buildStatusNotificationPayload 1.6/2.0.x branches (#1834) - #1902
Conversation
…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.
SummaryThe following content is AI-generated and provides a summary of the pull request: test(ui-common): Add test coverage for
|
| 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
- Output Template: Default Template
- GithubContextProvider: Bump @typescript-eslint/parser from 5.24.0 to 5.25.0 #2
- LLM:
anthropic--claude-4.6-sonnet - GithubContextProvider: Update issue templates #5
- File Content Strategy: Full file content
- GithubContextProvider: Bump @types/node from 16.11.35 to 17.0.34 #3
- GithubContextProvider: fix(ui): allow changing status of individual connectors #1834
- Summary Prompt: Default Prompt
- Event Trigger:
pull_request.opened - Correlation ID:
57dfb202-f348-4b05-8f9e-bea248ea73b0
There was a problem hiding this comment.
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
- LLM:
anthropic--claude-4.6-sonnet - File Content Strategy: Full file content
- Event Trigger:
pull_request.opened - Correlation ID:
57dfb202-f348-4b05-8f9e-bea248ea73b0 - Agent Instructions:
…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.
…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.
Summary
ui/common/src/utils/payloadBuilders.tsexportsbuildStatusNotificationPayload(introduced by #1834 to share theOCPP 1.6 vs 2.0.x branching between CLI and Web UI). Its sibling
builders (
buildAuthorizePayload,buildStartTransactionPayload,buildStopTransactionPayload,buildIdToken,isOCPP20x) all havedescribeblocks inui/common/tests/payloadBuilders.test.ts, butbuildStatusNotificationPayloadhad none. The S3 regression-focus gatewas therefore vacuous for this builder.
This PR adds a dedicated
describe('buildStatusNotificationPayload')block matching the existing file style. Production code in
payloadBuilders.tsis not touched.New cases (9)
errorCode→{connectorId, status, errorCode}errorCodeomitted → payload omitserrorCode(noNoErrordefault)evseIdpass-through witherrorCodeocppVersion = undefinedfalls through to 1.6 shape'3.0') → throws viaassertOCPP16OrUndefinedevseIdprovided →{connectorId, connectorStatus, evseId}, nostatus/errorCodeevseId→{connectorId, connectorStatus}errorCodeoption ignored (1.6-only field)ocppVersion→ different shape in the documented wayOCPP enum constants are used directly
(
OCPP16ChargePointStatus,OCPP16ChargePointErrorCode,OCPP20ConnectorStatusEnumType,OCPPVersion) per the AGENTS.mdOCPP-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 —
errorCodeomitted (noNoErrordefault)Plan (test #2): "OCPP 1.6 with
errorCodeomitted → defaults toNoError."Actual (
payloadBuilders.ts):When
errorCodeis omitted, the field is dropped from the payload;no default is applied. Test case #2 asserts the actual behaviour
(
errorCodeabsent), 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
errorCodeis required on the wire), this isa 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 | OCPP20ConnectorStatusEnumTypeand passes the value straight into the returned object. The only
runtime-rejection contract is
assertOCPP16OrUndefined(version), whichthrows for unsupported
ocppVersionvalues such as'3.0'. There isno runtime validation of
statusitself — type-level only.I did not introduce
as any/// @ts-ignorecasts to fabricate aruntime-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
statusand/orerrorCode, that is a behaviour change and belongs in a separate PR.Quality gates
pnpm --filter ui-common typecheckpnpm --filter ui-common lintpnpm --filter ui-common testpnpm --filter ui-common test:coverageCoverage report (lcov,
src/utils/payloadBuilders.ts)buildStatusNotificationPayload(line 44) is now hit 10 timesacross 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
payloadBuilders.ts.Severity
MAJOR — test hygiene gap closed; S3 regression-focus gate now non-vacuous
for
buildStatusNotificationPayload.