]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commit
test: use shared response test helpers (#1930)
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Mon, 29 Jun 2026 18:24:09 +0000 (20:24 +0200)
committerGitHub <noreply@github.com>
Mon, 29 Jun 2026 18:24:09 +0000 (20:24 +0200)
commitc2ea863e0d006a9053bae2375febd1e2f2717176
treeeccc1a534b05a12166fd657da32467bc7861c592
parentf4462a877b41271e8375e8bf3c5b1c114b11f6f3
test: use shared response test helpers (#1930)

* test(ui-server): use response drain helpers

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
* test(ocpp): share response service test helpers

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
* test(ocpp): use auth factory test instances

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
* refactor(ocpp): move ResponseService testable wrapper to __testable__

Aligns OCPP 2.0 ResponseService test wiring with the established pattern used
by RequestService and VariableManager:

- New src/charging-station/ocpp/2.0/__testable__/OCPP20ResponseServiceTestable.ts
  exporting createTestableResponseService + TestableOCPP20ResponseService;
  mirrors OCPP20RequestServiceTestable.ts structure (function declarations,
  file-level JSDoc with @example, double-cast through unknown).
- __testable__/index.ts re-exports the new module.
- OCPP20ResponseService-TransactionEvent.test.ts and -ForceTxOnInvalid.test.ts
  now import createTestableResponseService from __testable__/index.js;
  call sites renamed (drops redundant OCPP20 prefix, consistent with
  createTestableRequestService).
- OCPP20ResponseServiceTestUtils.ts now contains only the test-only
  buildTransactionEventRequest payload builder; adopts @file header and
  arrow-style export to harmonize with MockFactories.ts neighbour.

Test-only refactor; no production behavior change.

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
* test(ocpp): factor auth service injection helpers

Centralizes the two patterns used by OCPP 2.0 IncomingRequest tests to
inject mock OCPPAuthService instances into the factory cache:

- injectMockAuthService(station, service) — wraps the station-id lookup +
  OCPPAuthServiceFactory.setInstanceForTesting plumbing; replaces the
  duplicated boilerplate in ClearCache.test.ts and LocalAuthList.test.ts.
- withThrowingAuthServiceFactory(errorMessage, fn) — scoped monkey-patch +
  try/finally restore for the 3 sites that must exercise a failing
  getInstance (factory unavailable, no Authorization Cache support).
  Required because setInstanceForTesting only injects a returned instance;
  it cannot make getInstance itself throw.

Side effect of the helper adoption:

- LocalAuthList.test.ts drops the suite-scoped originalGetInstance save
  and afterEach restore — no longer needed since every monkey-patch is
  now scoped to its own test via withThrowingAuthServiceFactory.
- ClearCache.test.ts drops the local try/finally on the no-cache-support
  test for the same reason.

Test-only refactor; no production behavior change.

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
* test(ocpp): align auth mock helper verbs and drop dead return type

V2-1: harmonize JSDoc verbs across the auth injection helpers — `inject*`
docstrings now start with 'Inject' to match the function name, and the local
`setupMockAuthService` wrappers (which build the mock + inject it) now start
with 'Configure and inject' to reflect their broader role. Avoids the verb
collision between the shared `injectMockAuthService` and the local
`setupMockAuthService` helpers.

V2-2: drop the dead `OCPPAuthService` return type from LocalAuthList's local
`setupMockAuthService` — no call site captured the return value. Also drops
the now-unused `OCPPAuthService` type import.

Test-only refactor; no production behavior change.

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
* test(ocpp): align ClearCache test hook ordering with siblings

Moves the `afterEach` block below `beforeEach` in ClearCache.test.ts to match
the before-then-after ordering used by LocalAuthList, TransactionEvent and
ForceTxOnInvalid test files. Cosmetic; no behavior change.

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
---------

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ocpp/2.0/__testable__/OCPP20ResponseServiceTestable.ts [new file with mode: 0644]
src/charging-station/ocpp/2.0/__testable__/index.ts
tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-ClearCache.test.ts
tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-LocalAuthList.test.ts
tests/charging-station/ocpp/2.0/OCPP20ResponseService-ForceTxOnInvalid.test.ts
tests/charging-station/ocpp/2.0/OCPP20ResponseService-TransactionEvent.test.ts
tests/charging-station/ocpp/2.0/OCPP20ResponseServiceTestUtils.ts [new file with mode: 0644]
tests/charging-station/ocpp/auth/helpers/MockFactories.ts
tests/charging-station/ui-server/UIHttpServer.test.ts
tests/charging-station/ui-server/UIMetricsEndpoint.test.ts