]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commit
test(ocpp16): add comprehensive OCPP 1.6 unit and integration tests (#1710)
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 10 Mar 2026 19:44:19 +0000 (20:44 +0100)
committerGitHub <noreply@github.com>
Tue, 10 Mar 2026 19:44:19 +0000 (20:44 +0100)
commit9acc5a0aec9833fa506ef2ced4e265cb15a2d696
tree6c7f224ddd96e7fadf6fe31120eefab8490f9f46
parent0407c5f9f374c5c7c10ce2a273c51b14cd84f5ad
test(ocpp16): add comprehensive OCPP 1.6 unit and integration tests (#1710)

* test(ocpp16): add testable interface layer and test utilities

* test(ocpp16): add constants and service utils tests

* test(ocpp16): add incoming request service tests

* fix(ocpp): break circular dependency in OCPPServiceUtils via dynamic imports

Use dynamic await import() for OCPP16Constants and OCPP20Constants inside
checkConnectorStatusTransition to break the circular dependency chain:
OCPPConstants → utils/index → ErrorUtils → OCPPServiceUtils → OCPP16/20Constants → OCPPConstants

This fixes OCPP16Constants.test.ts (89 tests) without breaking UIHttpServer,
UIWebSocketServer, or AbstractUIService tests.

* test(ocpp16): add integration tests for transactions, charging profiles, configuration, and reservations

* test(ocpp16): fix lint errors, type safety, and spec traceability across all test files

- Add OCPP 1.6 spec section references (§) to all 21 test files
- Fix 129 no-floating-promises: add await to it()/describe() calls
- Fix 17 require-await: remove async from sync callbacks
- Fix 9 no-non-null-assertion: replace ! with proper null checks
- Fix 8 no-unsafe-enum-comparison: use String() wrappers
- Fix 13 TypeScript type errors (requestHandler mocks, SampledValueTemplate, etc.)
- Remove blanket eslint-disable and 89x (t: any) in Constants test
- Add @file JSDoc headers where missing

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
* test(ocpp16): migrate 21 OCPP 1.6 test files from @std/expect to node:assert/strict

Replace all @std/expect imports with node:assert/strict across 21 test
files (~536 expect calls), eliminating the JSR dependency that breaks CI.

Migration patterns applied:
- expect(a).toBe(b) → assert.strictEqual(a, b)
- expect(a).toBeDefined() → assert.notStrictEqual(a, undefined)
- expect(a).toStrictEqual(b) → assert.deepStrictEqual(a, b)
- expect(a).toBeInstanceOf(T) → assert.ok(a instanceof T)
- expect(a).toContain(x) → assert.ok(a.includes(x))
- expect(p).resolves.toBeUndefined() → await assert.doesNotReject(p)
- expect(() => fn()).toThrow() → assert.throws(() => { fn() })

Added 26 null guards (if + assert.fail) after getConnectorStatus() and
nullable field accesses to satisfy both TypeScript strict null checks
and ESLint.

All quality gates pass: 1694 tests, 0 lint errors, 0 TS errors.

* test: migrate all remaining test files from @std/expect to node:assert/strict

Migrate 82 remaining test files (OCPP 2.0, auth, charging-station,
UI server, utils, worker, performance, exception, types) from
@std/expect to node:assert/strict.

Remove @std/expect JSR dependency from package.json to fix CI 404
errors on npm.jsr.io.

All 1694 tests pass, lint clean, TSC clean.

* chore: update lockfile after removing @std/expect dependency

* docs: update test style guide and config to reflect node:assert/strict migration

* test(ocpp16): eliminate as-unknown-as casts and add missing AAA comments

Create typed helpers in OCPP16TestUtils (setMockRequestHandler,
dispatchResponse, createMeterValuesTemplate, createCommandsSupport)
to encapsulate type casts in one place instead of 26 inline casts
across 8 test files.

Add Arrange/Act/Assert comments to 5 tests in
OCPP16ServiceUtils.test.ts that have 3+ logical setup steps.

All 1694 tests pass, lint clean, TSC clean.

* fix(test): use real enum value instead of as-any cast in AuthHelpers.test.ts

Use AuthorizationStatus.NO_CREDIT (unhandled by getStatusMessage
switch) to test the default branch, removing the as-any cast and
eslint-disable comment that caused CI autofix failure.

* [autofix.ci] apply automated fixes

---------

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
108 files changed:
openspec/config.yaml
package.json
pnpm-lock.yaml
src/charging-station/ocpp/1.6/__testable__/index.ts [new file with mode: 0644]
src/charging-station/ocpp/OCPPServiceUtils.ts
tests/TEST_STYLE_GUIDE.md
tests/charging-station/AutomaticTransactionGenerator.test.ts
tests/charging-station/ChargingStation-Configuration.test.ts
tests/charging-station/ChargingStation-Connectors.test.ts
tests/charging-station/ChargingStation-Lifecycle.test.ts
tests/charging-station/ChargingStation-Resilience.test.ts
tests/charging-station/ChargingStation-Transactions.test.ts
tests/charging-station/ChargingStation.test.ts
tests/charging-station/ConfigurationKeyUtils.test.ts
tests/charging-station/Helpers.test.ts
tests/charging-station/IdTagsCache.test.ts
tests/charging-station/SharedLRUCache.test.ts
tests/charging-station/ocpp/1.6/OCPP16Constants.test.ts [new file with mode: 0644]
tests/charging-station/ocpp/1.6/OCPP16IncomingRequestService-ChangeAvailability.test.ts [new file with mode: 0644]
tests/charging-station/ocpp/1.6/OCPP16IncomingRequestService-Configuration.test.ts [new file with mode: 0644]
tests/charging-station/ocpp/1.6/OCPP16IncomingRequestService-Firmware.test.ts [new file with mode: 0644]
tests/charging-station/ocpp/1.6/OCPP16IncomingRequestService-RemoteStartTransaction.test.ts [new file with mode: 0644]
tests/charging-station/ocpp/1.6/OCPP16IncomingRequestService-RemoteStopUnlock.test.ts [new file with mode: 0644]
tests/charging-station/ocpp/1.6/OCPP16IncomingRequestService-Reservation.test.ts [new file with mode: 0644]
tests/charging-station/ocpp/1.6/OCPP16IncomingRequestService-Reset.test.ts [new file with mode: 0644]
tests/charging-station/ocpp/1.6/OCPP16IncomingRequestService-SimpleHandlers.test.ts [new file with mode: 0644]
tests/charging-station/ocpp/1.6/OCPP16IncomingRequestService-SmartCharging.test.ts [new file with mode: 0644]
tests/charging-station/ocpp/1.6/OCPP16IncomingRequestService-TriggerMessage.test.ts [new file with mode: 0644]
tests/charging-station/ocpp/1.6/OCPP16Integration-ChargingProfiles.test.ts [new file with mode: 0644]
tests/charging-station/ocpp/1.6/OCPP16Integration-Configuration.test.ts [new file with mode: 0644]
tests/charging-station/ocpp/1.6/OCPP16Integration-Reservations.test.ts [new file with mode: 0644]
tests/charging-station/ocpp/1.6/OCPP16Integration-Transactions.test.ts [new file with mode: 0644]
tests/charging-station/ocpp/1.6/OCPP16RequestService-Payloads.test.ts [new file with mode: 0644]
tests/charging-station/ocpp/1.6/OCPP16ResponseService-BootAuth.test.ts [new file with mode: 0644]
tests/charging-station/ocpp/1.6/OCPP16ResponseService-SimpleHandlers.test.ts [new file with mode: 0644]
tests/charging-station/ocpp/1.6/OCPP16ResponseService-Transactions.test.ts [new file with mode: 0644]
tests/charging-station/ocpp/1.6/OCPP16SchemaValidation.test.ts [new file with mode: 0644]
tests/charging-station/ocpp/1.6/OCPP16ServiceUtils.test.ts [new file with mode: 0644]
tests/charging-station/ocpp/1.6/OCPP16TestUtils.ts [new file with mode: 0644]
tests/charging-station/ocpp/2.0/OCPP20CertificateManager.test.ts
tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-CertificateSigned.test.ts
tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-ClearCache.test.ts
tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-DeleteCertificate.test.ts
tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-GetBaseReport.test.ts
tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-GetInstalledCertificateIds.test.ts
tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-GetVariables.test.ts
tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-InstallCertificate.test.ts
tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RemoteStartAuth.test.ts
tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStartTransaction.test.ts
tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStopTransaction.test.ts
tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-Reset.test.ts
tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-SetVariables.test.ts
tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-TriggerMessage.test.ts
tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-UnlockConnector.test.ts
tests/charging-station/ocpp/2.0/OCPP20Integration-Certificate.test.ts
tests/charging-station/ocpp/2.0/OCPP20Integration.test.ts
tests/charging-station/ocpp/2.0/OCPP20RequestService-BootNotification.test.ts
tests/charging-station/ocpp/2.0/OCPP20RequestService-HeartBeat.test.ts
tests/charging-station/ocpp/2.0/OCPP20RequestService-ISO15118.test.ts
tests/charging-station/ocpp/2.0/OCPP20RequestService-NotifyReport.test.ts
tests/charging-station/ocpp/2.0/OCPP20RequestService-SignCertificate.test.ts
tests/charging-station/ocpp/2.0/OCPP20RequestService-StatusNotification.test.ts
tests/charging-station/ocpp/2.0/OCPP20ResponseService-BootNotification.test.ts
tests/charging-station/ocpp/2.0/OCPP20ResponseService-SimpleHandlers.test.ts
tests/charging-station/ocpp/2.0/OCPP20ResponseService-TransactionEvent.test.ts
tests/charging-station/ocpp/2.0/OCPP20SchemaValidation.test.ts
tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-TransactionEvent.test.ts
tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-enforceMessageLimits.test.ts
tests/charging-station/ocpp/2.0/OCPP20VariableManager.test.ts
tests/charging-station/ocpp/OCPPServiceUtils-authorization.test.ts
tests/charging-station/ocpp/OCPPServiceUtils-connectorStatus.test.ts
tests/charging-station/ocpp/OCPPServiceUtils-pure.test.ts
tests/charging-station/ocpp/OCPPServiceUtils-validation.test.ts
tests/charging-station/ocpp/auth/OCPPAuthIntegration.test.ts
tests/charging-station/ocpp/auth/adapters/OCPP16AuthAdapter.test.ts
tests/charging-station/ocpp/auth/adapters/OCPP20AuthAdapter.test.ts
tests/charging-station/ocpp/auth/cache/InMemoryAuthCache.test.ts
tests/charging-station/ocpp/auth/factories/AuthComponentFactory.test.ts
tests/charging-station/ocpp/auth/helpers/MockFactories.ts
tests/charging-station/ocpp/auth/services/OCPPAuthServiceFactory.test.ts
tests/charging-station/ocpp/auth/services/OCPPAuthServiceImpl.test.ts
tests/charging-station/ocpp/auth/strategies/CertificateAuthStrategy.test.ts
tests/charging-station/ocpp/auth/strategies/LocalAuthStrategy.test.ts
tests/charging-station/ocpp/auth/strategies/RemoteAuthStrategy.test.ts
tests/charging-station/ocpp/auth/types/AuthTypes.test.ts
tests/charging-station/ocpp/auth/utils/AuthHelpers.test.ts
tests/charging-station/ocpp/auth/utils/AuthValidators.test.ts
tests/charging-station/ocpp/auth/utils/ConfigValidator.test.ts
tests/charging-station/ui-server/UIHttpServer.test.ts
tests/charging-station/ui-server/UIServerSecurity.test.ts
tests/charging-station/ui-server/UIWebSocketServer.test.ts
tests/charging-station/ui-server/ui-services/AbstractUIService.test.ts
tests/exception/BaseError.test.ts
tests/exception/OCPPError.test.ts
tests/performance/storage/MikroOrmStorage.test.ts
tests/performance/storage/MongoDBStorage.test.ts
tests/types/ConfigurationData.test.ts
tests/utils/AsyncLock.test.ts
tests/utils/ChargingStationConfigurationUtils.test.ts
tests/utils/Configuration.test.ts
tests/utils/ConfigurationUtils.test.ts
tests/utils/ElectricUtils.test.ts
tests/utils/ErrorUtils.test.ts
tests/utils/FileUtils.test.ts
tests/utils/MessageChannelUtils.test.ts
tests/utils/StatisticUtils.test.ts
tests/utils/Utils.test.ts
tests/worker/WorkerUtils.test.ts