From f0b5650d9da93debffc7eb92c530e73d9b8f56b8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 1 Apr 2026 19:25:46 +0200 Subject: [PATCH] test(ocpp): harmonize test constants and assertion messages Replace hardcoded station IDs, tokens, and transaction IDs with shared constants from ChargingStationTestConstants.ts across 8 test files. Add TEST_TRANSACTION_UUID constant. Add descriptive messages to 55 assert.ok() numeric comparison calls across 20+ test files per TEST_STYLE_GUIDE.md requirements. --- .../ChargingStationTestConstants.ts | 1 + .../ocpp/1.6/OCPP16Constants.test.ts | 2 +- ...comingRequestService-Configuration.test.ts | 2 +- .../OCPP16Integration-Configuration.test.ts | 5 +- .../ocpp/1.6/OCPP16ServiceUtils.test.ts | 18 +++--- .../ocpp/2.0/Asn1DerUtils.test.ts | 5 +- .../ocpp/2.0/OCPP20CertificateManager.test.ts | 62 ++++++++++++------- ...ngRequestService-CertificateSigned.test.ts | 7 ++- ...gRequestService-ChangeAvailability.test.ts | 5 +- ...ngRequestService-DeleteCertificate.test.ts | 7 ++- ...comingRequestService-GetBaseReport.test.ts | 12 ++-- ...ncomingRequestService-GetVariables.test.ts | 7 ++- ...gRequestService-InstallCertificate.test.ts | 7 ++- ...mingRequestService-RemoteStartAuth.test.ts | 2 +- ...estService-RequestStartTransaction.test.ts | 2 +- ...ncomingRequestService-SetVariables.test.ts | 4 +- .../OCPP20RequestService-CallChain.test.ts | 10 ++- .../OCPP20RequestService-HeartBeat.test.ts | 3 +- ...PP20RequestService-SignCertificate.test.ts | 9 ++- ...0RequestService-StatusNotification.test.ts | 5 +- .../OCPP20ResponseService-CacheUpdate.test.ts | 35 ++++++----- ...20ResponseService-TransactionEvent.test.ts | 26 ++++---- .../2.0/OCPP20ServiceUtils-AuthCache.test.ts | 23 +++---- .../OCPP20ServiceUtils-ReconnectDelay.test.ts | 7 +-- ...CPP20ServiceUtils-TransactionEvent.test.ts | 2 +- ...0ServiceUtils-enforceMessageLimits.test.ts | 2 +- .../ocpp/OCPPServiceOperations.test.ts | 20 ++++-- .../ocpp/auth/cache/InMemoryAuthCache.test.ts | 39 ++++++------ .../ocpp/auth/utils/AuthHelpers.test.ts | 4 +- 29 files changed, 202 insertions(+), 131 deletions(-) diff --git a/tests/charging-station/ChargingStationTestConstants.ts b/tests/charging-station/ChargingStationTestConstants.ts index bbf770ff..0ee64e3e 100644 --- a/tests/charging-station/ChargingStationTestConstants.ts +++ b/tests/charging-station/ChargingStationTestConstants.ts @@ -64,6 +64,7 @@ export const TEST_ID_TAG_BLOCKED = 'BLOCKED_TAG' */ export const TEST_TRANSACTION_ID = 1 export const TEST_TRANSACTION_ID_STRING = 'tx-ocpp20-1' +export const TEST_TRANSACTION_UUID = '00000000-0000-0000-0000-000000000001' export const TEST_TRANSACTION_ENERGY_WH = 5000 /** diff --git a/tests/charging-station/ocpp/1.6/OCPP16Constants.test.ts b/tests/charging-station/ocpp/1.6/OCPP16Constants.test.ts index b4665cc2..ba49028b 100644 --- a/tests/charging-station/ocpp/1.6/OCPP16Constants.test.ts +++ b/tests/charging-station/ocpp/1.6/OCPP16Constants.test.ts @@ -188,7 +188,7 @@ await describe('OCPP16Constants', async () => { await it('should contain 56 connector-level transitions', () => { const transitions = OCPP16Constants.ChargePointStatusConnectorTransitions - assert.ok(transitions.length >= 56) + assert.ok(transitions.length >= 56, 'should contain at least 56 connector-level transitions') }) await it('should have transitions with correct structure', () => { diff --git a/tests/charging-station/ocpp/1.6/OCPP16IncomingRequestService-Configuration.test.ts b/tests/charging-station/ocpp/1.6/OCPP16IncomingRequestService-Configuration.test.ts index 324991c7..b336fd20 100644 --- a/tests/charging-station/ocpp/1.6/OCPP16IncomingRequestService-Configuration.test.ts +++ b/tests/charging-station/ocpp/1.6/OCPP16IncomingRequestService-Configuration.test.ts @@ -128,7 +128,7 @@ await describe('OCPP16IncomingRequestService — Configuration', async () => { // Assert assert.notStrictEqual(response.configurationKey, undefined) assert.notStrictEqual(response.unknownKey, undefined) - assert.ok(response.configurationKey.length >= 2) + assert.ok(response.configurationKey.length >= 2, 'should return at least 2 configuration keys') const heartbeatKey = response.configurationKey.find( k => k.key === (OCPP16StandardParametersKey.HeartbeatInterval as string) ) diff --git a/tests/charging-station/ocpp/1.6/OCPP16Integration-Configuration.test.ts b/tests/charging-station/ocpp/1.6/OCPP16Integration-Configuration.test.ts index 6e9a2513..a2d76894 100644 --- a/tests/charging-station/ocpp/1.6/OCPP16Integration-Configuration.test.ts +++ b/tests/charging-station/ocpp/1.6/OCPP16Integration-Configuration.test.ts @@ -239,7 +239,10 @@ await describe('OCPP16 Integration — Configuration Management', async () => { const getResponse = testableService.handleRequestGetConfiguration(station, {}) // Assert — All visible keys returned with correct values - assert.ok(getResponse.configurationKey.length >= 3) + assert.ok( + getResponse.configurationKey.length >= 3, + 'should return at least 3 configuration keys' + ) assert.strictEqual(getResponse.unknownKey.length, 0) const heartbeat = getResponse.configurationKey.find( diff --git a/tests/charging-station/ocpp/1.6/OCPP16ServiceUtils.test.ts b/tests/charging-station/ocpp/1.6/OCPP16ServiceUtils.test.ts index 6fcc6822..630ef092 100644 --- a/tests/charging-station/ocpp/1.6/OCPP16ServiceUtils.test.ts +++ b/tests/charging-station/ocpp/1.6/OCPP16ServiceUtils.test.ts @@ -43,6 +43,7 @@ import { OCPPVersion, } from '../../../../src/types/index.js' import { standardCleanup } from '../../../helpers/TestLifecycleHelpers.js' +import { TEST_CHARGING_STATION_BASE_NAME, TEST_ID_TAG } from '../../ChargingStationTestConstants.js' import { createMockChargingStation } from '../../ChargingStationTestUtils.js' import { getTestAuthCache } from '../auth/helpers/MockFactories.js' import { createCommandsSupport, createMeterValuesTemplate } from './OCPP16TestUtils.js' @@ -581,7 +582,10 @@ await describe('OCPP16ServiceUtils — pure functions', async () => { assert.strictEqual(result.chargingSchedulePeriod.length, 2) // Should be sorted by startPeriod const periods = result.chargingSchedulePeriod - assert.ok(periods[0].startPeriod <= periods[1].startPeriod) + assert.ok( + periods[0].startPeriod <= periods[1].startPeriod, + 'periods should be sorted by startPeriod' + ) }) }) @@ -856,8 +860,6 @@ await describe('OCPP16ServiceUtils — pure functions', async () => { // ─── updateAuthorizationCache ────────────────────────────────────────── await describe('updateAuthorizationCache', async () => { - const TEST_ID_TAG = 'TEST_RFID_001' - afterEach(() => { OCPPAuthServiceFactory.clearAllInstances() }) @@ -867,7 +869,7 @@ await describe('OCPP16ServiceUtils — pure functions', async () => { const { station } = createMockChargingStation({ ocppVersion: OCPPVersion.VERSION_16, stationInfo: { - chargingStationId: 'CS_CACHE_TEST_01', + chargingStationId: TEST_CHARGING_STATION_BASE_NAME, ocppVersion: OCPPVersion.VERSION_16, }, }) @@ -891,7 +893,7 @@ await describe('OCPP16ServiceUtils — pure functions', async () => { const { station } = createMockChargingStation({ ocppVersion: OCPPVersion.VERSION_16, stationInfo: { - chargingStationId: 'CS_CACHE_TEST_02', + chargingStationId: TEST_CHARGING_STATION_BASE_NAME, ocppVersion: OCPPVersion.VERSION_16, }, }) @@ -915,7 +917,7 @@ await describe('OCPP16ServiceUtils — pure functions', async () => { const { station } = createMockChargingStation({ ocppVersion: OCPPVersion.VERSION_16, stationInfo: { - chargingStationId: 'CS_CACHE_TEST_03', + chargingStationId: TEST_CHARGING_STATION_BASE_NAME, ocppVersion: OCPPVersion.VERSION_16, }, }) @@ -941,7 +943,7 @@ await describe('OCPP16ServiceUtils — pure functions', async () => { const { station } = createMockChargingStation({ ocppVersion: OCPPVersion.VERSION_16, stationInfo: { - chargingStationId: 'CS_CACHE_TEST_04', + chargingStationId: TEST_CHARGING_STATION_BASE_NAME, ocppVersion: OCPPVersion.VERSION_16, }, }) @@ -966,7 +968,7 @@ await describe('OCPP16ServiceUtils — pure functions', async () => { const { station } = createMockChargingStation({ ocppVersion: OCPPVersion.VERSION_16, stationInfo: { - chargingStationId: 'CS_CACHE_TEST_05', + chargingStationId: TEST_CHARGING_STATION_BASE_NAME, ocppVersion: OCPPVersion.VERSION_16, }, }) diff --git a/tests/charging-station/ocpp/2.0/Asn1DerUtils.test.ts b/tests/charging-station/ocpp/2.0/Asn1DerUtils.test.ts index 8387c1e5..7083c0f9 100644 --- a/tests/charging-station/ocpp/2.0/Asn1DerUtils.test.ts +++ b/tests/charging-station/ocpp/2.0/Asn1DerUtils.test.ts @@ -105,7 +105,10 @@ await describe('ASN.1 DER encoding utilities', async () => { for (const line of contentLines.slice(0, -1)) { assert.strictEqual(line.length, 64) } - assert.ok(contentLines[contentLines.length - 1].length <= 64) + assert.ok( + contentLines[contentLines.length - 1].length <= 64, + 'last line length should be at most 64 characters' + ) }) }) }) diff --git a/tests/charging-station/ocpp/2.0/OCPP20CertificateManager.test.ts b/tests/charging-station/ocpp/2.0/OCPP20CertificateManager.test.ts index c0f1fb8d..3327bea3 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20CertificateManager.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20CertificateManager.test.ts @@ -15,6 +15,7 @@ import { InstallCertificateUseEnumType, } from '../../../../src/types/index.js' import { standardCleanup } from '../../../helpers/TestLifecycleHelpers.js' +import { TEST_CHARGING_STATION_HASH_ID } from '../../ChargingStationTestConstants.js' import { EMPTY_PEM_CERTIFICATE, EXPIRED_X509_PEM_CERTIFICATE, @@ -24,12 +25,11 @@ import { VALID_X509_PEM_CERTIFICATE, } from './OCPP20CertificateTestData.js' -const TEST_STATION_HASH_ID = 'test-station-hash-12345' const TEST_CERT_TYPE = InstallCertificateUseEnumType.CSMSRootCertificate await describe('I02-I04 - ISO15118 Certificate Management', async () => { afterEach(async () => { - await rm(`dist/assets/configurations/${TEST_STATION_HASH_ID}`, { + await rm(`dist/assets/configurations/${TEST_CHARGING_STATION_HASH_ID}`, { force: true, recursive: true, }) @@ -53,7 +53,7 @@ await describe('I02-I04 - ISO15118 Certificate Management', async () => { await it('should store a valid PEM certificate to the correct path', async () => { const result = await manager.storeCertificate( - TEST_STATION_HASH_ID, + TEST_CHARGING_STATION_HASH_ID, TEST_CERT_TYPE, VALID_PEM_CERTIFICATE_EXTENDED ) @@ -63,14 +63,14 @@ await describe('I02-I04 - ISO15118 Certificate Management', async () => { if (result.filePath == null) { assert.fail('Expected filePath to be defined') } - assert.ok(result.filePath.includes(TEST_STATION_HASH_ID)) + assert.ok(result.filePath.includes(TEST_CHARGING_STATION_HASH_ID)) assert.ok(result.filePath.includes('certs')) assert.match(result.filePath, /\.pem$/) }) await it('should reject invalid PEM certificate without BEGIN/END markers', async () => { const result = await manager.storeCertificate( - TEST_STATION_HASH_ID, + TEST_CHARGING_STATION_HASH_ID, TEST_CERT_TYPE, INVALID_PEM_CERTIFICATE_MISSING_MARKERS ) @@ -85,7 +85,7 @@ await describe('I02-I04 - ISO15118 Certificate Management', async () => { await it('should reject empty certificate data', async () => { const result = await manager.storeCertificate( - TEST_STATION_HASH_ID, + TEST_CHARGING_STATION_HASH_ID, TEST_CERT_TYPE, EMPTY_PEM_CERTIFICATE ) @@ -97,7 +97,7 @@ await describe('I02-I04 - ISO15118 Certificate Management', async () => { await it('should create certificate directory structure if not exists', async () => { const result = await manager.storeCertificate( - TEST_STATION_HASH_ID, + TEST_CHARGING_STATION_HASH_ID, InstallCertificateUseEnumType.V2GRootCertificate, VALID_PEM_CERTIFICATE_EXTENDED ) @@ -125,7 +125,7 @@ await describe('I02-I04 - ISO15118 Certificate Management', async () => { serialNumber: 'SN-12345', } - const result = await manager.deleteCertificate(TEST_STATION_HASH_ID, hashData) + const result = await manager.deleteCertificate(TEST_CHARGING_STATION_HASH_ID, hashData) assert.notStrictEqual(result, undefined) assert.notStrictEqual(result.status, undefined) @@ -146,7 +146,7 @@ await describe('I02-I04 - ISO15118 Certificate Management', async () => { serialNumber: 'NON-EXISTENT-SN', } - const result = await manager.deleteCertificate(TEST_STATION_HASH_ID, hashData) + const result = await manager.deleteCertificate(TEST_CHARGING_STATION_HASH_ID, hashData) assert.notStrictEqual(result, undefined) assert.strictEqual(result.status, DeleteCertificateStatusEnumType.NotFound) @@ -178,7 +178,7 @@ await describe('I02-I04 - ISO15118 Certificate Management', async () => { manager = new OCPP20CertificateManager() }) await it('should return list of installed certificates for station', async () => { - const result = await manager.getInstalledCertificates(TEST_STATION_HASH_ID) + const result = await manager.getInstalledCertificates(TEST_CHARGING_STATION_HASH_ID) assert.notStrictEqual(result, undefined) assert.ok(Array.isArray(result.certificateHashDataChain)) @@ -186,7 +186,10 @@ await describe('I02-I04 - ISO15118 Certificate Management', async () => { await it('should filter certificates by type when filter provided', async () => { const filterTypes = [InstallCertificateUseEnumType.CSMSRootCertificate] - const result = await manager.getInstalledCertificates(TEST_STATION_HASH_ID, filterTypes) + const result = await manager.getInstalledCertificates( + TEST_CHARGING_STATION_HASH_ID, + filterTypes + ) assert.notStrictEqual(result, undefined) assert.ok(Array.isArray(result.certificateHashDataChain)) @@ -205,7 +208,10 @@ await describe('I02-I04 - ISO15118 Certificate Management', async () => { InstallCertificateUseEnumType.V2GRootCertificate, InstallCertificateUseEnumType.ManufacturerRootCertificate, ] - const result = await manager.getInstalledCertificates(TEST_STATION_HASH_ID, filterTypes) + const result = await manager.getInstalledCertificates( + TEST_CHARGING_STATION_HASH_ID, + filterTypes + ) assert.notStrictEqual(result, undefined) assert.ok(Array.isArray(result.certificateHashDataChain)) @@ -331,10 +337,14 @@ await describe('I02-I04 - ISO15118 Certificate Management', async () => { manager = new OCPP20CertificateManager() }) await it('should return correct file path for certificate', () => { - const path = manager.getCertificatePath(TEST_STATION_HASH_ID, TEST_CERT_TYPE, 'SERIAL-12345') + const path = manager.getCertificatePath( + TEST_CHARGING_STATION_HASH_ID, + TEST_CERT_TYPE, + 'SERIAL-12345' + ) assert.notStrictEqual(path, undefined) - assert.ok(path.includes(TEST_STATION_HASH_ID)) + assert.ok(path.includes(TEST_CHARGING_STATION_HASH_ID)) assert.ok(path.includes('certs')) assert.ok(path.includes('CSMSRootCertificate')) assert.ok(path.includes('SERIAL-12345')) @@ -343,7 +353,7 @@ await describe('I02-I04 - ISO15118 Certificate Management', async () => { await it('should handle special characters in serial number', () => { const path = manager.getCertificatePath( - TEST_STATION_HASH_ID, + TEST_CHARGING_STATION_HASH_ID, TEST_CERT_TYPE, 'SERIAL:ABC/123' ) @@ -359,13 +369,13 @@ await describe('I02-I04 - ISO15118 Certificate Management', async () => { await it('should return different paths for different certificate types', () => { const csmsPath = manager.getCertificatePath( - TEST_STATION_HASH_ID, + TEST_CHARGING_STATION_HASH_ID, InstallCertificateUseEnumType.CSMSRootCertificate, 'SERIAL-001' ) const v2gPath = manager.getCertificatePath( - TEST_STATION_HASH_ID, + TEST_CHARGING_STATION_HASH_ID, InstallCertificateUseEnumType.V2GRootCertificate, 'SERIAL-001' ) @@ -376,7 +386,11 @@ await describe('I02-I04 - ISO15118 Certificate Management', async () => { }) await it('should return path following project convention', () => { - const path = manager.getCertificatePath(TEST_STATION_HASH_ID, TEST_CERT_TYPE, 'SERIAL-12345') + const path = manager.getCertificatePath( + TEST_CHARGING_STATION_HASH_ID, + TEST_CERT_TYPE, + 'SERIAL-12345' + ) assert.match(path, /configurations/) assert.match(path, /certs/) @@ -393,16 +407,16 @@ await describe('I02-I04 - ISO15118 Certificate Management', async () => { await it('should handle concurrent certificate operations', async () => { const results = await Promise.all([ manager.storeCertificate( - TEST_STATION_HASH_ID, + TEST_CHARGING_STATION_HASH_ID, InstallCertificateUseEnumType.CSMSRootCertificate, VALID_PEM_CERTIFICATE_EXTENDED ), manager.storeCertificate( - TEST_STATION_HASH_ID, + TEST_CHARGING_STATION_HASH_ID, InstallCertificateUseEnumType.V2GRootCertificate, VALID_PEM_CERTIFICATE_EXTENDED ), - manager.getInstalledCertificates(TEST_STATION_HASH_ID), + manager.getInstalledCertificates(TEST_CHARGING_STATION_HASH_ID), ]) assert.strictEqual(results.length, 3) @@ -414,7 +428,11 @@ await describe('I02-I04 - ISO15118 Certificate Management', async () => { await it('should handle very long certificate chains', async () => { const longChain = Array(5).fill(VALID_PEM_CERTIFICATE_EXTENDED).join('\n') - const result = await manager.storeCertificate(TEST_STATION_HASH_ID, TEST_CERT_TYPE, longChain) + const result = await manager.storeCertificate( + TEST_CHARGING_STATION_HASH_ID, + TEST_CERT_TYPE, + longChain + ) assert.notStrictEqual(result, undefined) }) diff --git a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-CertificateSigned.test.ts b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-CertificateSigned.test.ts index cde145f4..c80a3a44 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-CertificateSigned.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-CertificateSigned.test.ts @@ -298,8 +298,11 @@ await describe('I04 - CertificateSigned', async () => { assert.fail('Expected statusInfo to be defined') } assert.strictEqual(typeof response.statusInfo.reasonCode, 'string') - assert.ok(response.statusInfo.reasonCode.length > 0) - assert.ok(response.statusInfo.reasonCode.length <= 20) + assert.ok(response.statusInfo.reasonCode.length > 0, 'reasonCode should not be empty') + assert.ok( + response.statusInfo.reasonCode.length <= 20, + 'reasonCode length should be at most 20 characters' + ) }) }) diff --git a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-ChangeAvailability.test.ts b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-ChangeAvailability.test.ts index 2b885e2b..b1bcf904 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-ChangeAvailability.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-ChangeAvailability.test.ts @@ -54,7 +54,10 @@ await describe('G03 - ChangeAvailability', async () => { const evseStatus = station.getEvseStatus(1) assert.strictEqual(evseStatus?.availability, OCPP20OperationalStatusEnumType.Inoperative) await flushMicrotasks() - assert.ok(requestHandlerMock.mock.callCount() >= 1) + assert.ok( + requestHandlerMock.mock.callCount() >= 1, + 'request handler should have been called at least once' + ) const args = requestHandlerMock.mock.calls[0].arguments as [unknown, string] assert.strictEqual(args[1], OCPP20RequestCommand.STATUS_NOTIFICATION) }) diff --git a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-DeleteCertificate.test.ts b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-DeleteCertificate.test.ts index 54be6174..9ca69b2f 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-DeleteCertificate.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-DeleteCertificate.test.ts @@ -260,8 +260,11 @@ await describe('I04 - DeleteCertificate', async () => { assert.fail('Expected statusInfo to be defined') } assert.strictEqual(typeof response.statusInfo.reasonCode, 'string') - assert.ok(response.statusInfo.reasonCode.length > 0) - assert.ok(response.statusInfo.reasonCode.length <= 20) + assert.ok(response.statusInfo.reasonCode.length > 0, 'reasonCode should not be empty') + assert.ok( + response.statusInfo.reasonCode.length <= 20, + 'reasonCode length should be at most 20 characters' + ) }) }) diff --git a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-GetBaseReport.test.ts b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-GetBaseReport.test.ts index c163af83..2bfdc5b0 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-GetBaseReport.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-GetBaseReport.test.ts @@ -209,7 +209,7 @@ await describe('B07 - Get Base Report', async () => { ) assert.ok(Array.isArray(reportData)) - assert.ok(reportData.length > 0) + assert.ok(reportData.length > 0, 'report data should not be empty') // Check that each report data item has the expected structure for (const item of reportData) { @@ -228,7 +228,7 @@ await describe('B07 - Get Base Report', async () => { const reportData = testableService.buildReportData(station, ReportBaseEnumType.FullInventory) assert.ok(Array.isArray(reportData)) - assert.ok(reportData.length > 0) + assert.ok(reportData.length > 0, 'report data should not be empty') // Check for station info variables const modelVariable = reportData.find( @@ -257,7 +257,7 @@ await describe('B07 - Get Base Report', async () => { const reportData = testableService.buildReportData(station, ReportBaseEnumType.SummaryInventory) assert.ok(Array.isArray(reportData)) - assert.ok(reportData.length > 0) + assert.ok(reportData.length > 0, 'report data should not be empty') // Check for availability state variable const availabilityVariable = reportData.find( @@ -323,7 +323,7 @@ await describe('B07 - Get Base Report', async () => { await it('should handle GetBaseReport with EVSE structure', () => { // Create a station with EVSEs const { station: stationWithEvses } = createMockChargingStation({ - baseName: 'CS-EVSE-001', + baseName: TEST_CHARGING_STATION_BASE_NAME, connectorsCount: 3, evseConfiguration: { evsesCount: 3 }, stationInfo: { @@ -340,14 +340,14 @@ await describe('B07 - Get Base Report', async () => { ) assert.ok(Array.isArray(reportData)) - assert.ok(reportData.length > 0) + assert.ok(reportData.length > 0, 'report data should not be empty') // Check if EVSE components are included when EVSEs exist const evseComponents = reportData.filter( (item: ReportDataType) => item.component.name === (OCPP20ComponentName.EVSE as string) ) if (stationWithEvses.hasEvses) { - assert.ok(evseComponents.length > 0) + assert.ok(evseComponents.length > 0, 'should include EVSE components') } }) diff --git a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-GetVariables.test.ts b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-GetVariables.test.ts index 6743d2ac..6789d323 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-GetVariables.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-GetVariables.test.ts @@ -324,7 +324,7 @@ await describe('B06 - Get Variables', async () => { setStrictLimits(station, 100, limit) const response = incomingRequestService.handleRequestGetVariables(station, request) const actualSize = Buffer.byteLength(JSON.stringify(response.getVariableResult), 'utf8') - assert.ok(actualSize > limit) + assert.ok(actualSize > limit, 'response size should exceed limit') assert.strictEqual(response.getVariableResult.length, request.getVariableData.length) response.getVariableResult.forEach(r => { assert.strictEqual(r.attributeStatus, GetVariableStatusEnumType.Rejected) @@ -594,7 +594,10 @@ await describe('B06 - Get Variables', async () => { if (result.attributeValue == null) { assert.fail('Expected attributeValue to be defined') } - assert.ok(result.attributeValue.length <= 3) + assert.ok( + result.attributeValue.length <= 3, + 'attributeValue should be truncated to at most 3 characters' + ) resetReportingValueSize(station) }) }) diff --git a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-InstallCertificate.test.ts b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-InstallCertificate.test.ts index a995279b..1bef26db 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-InstallCertificate.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-InstallCertificate.test.ts @@ -258,8 +258,11 @@ await describe('I03 - InstallCertificate', async () => { assert.fail('Expected statusInfo to be defined') } assert.strictEqual(typeof response.statusInfo.reasonCode, 'string') - assert.ok(response.statusInfo.reasonCode.length > 0) - assert.ok(response.statusInfo.reasonCode.length <= 20) + assert.ok(response.statusInfo.reasonCode.length > 0, 'reasonCode should not be empty') + assert.ok( + response.statusInfo.reasonCode.length <= 20, + 'reasonCode length should be at most 20 characters' + ) }) }) }) diff --git a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RemoteStartAuth.test.ts b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RemoteStartAuth.test.ts index 6c46f17b..02a6c7b4 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RemoteStartAuth.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RemoteStartAuth.test.ts @@ -422,7 +422,7 @@ await describe('G03 - Remote Start Pre-Authorization', async () => { // Then: Charging station should have required configuration assert.notStrictEqual(mockStation, undefined) assert.notStrictEqual(mockStation.getNumberOfEvses(), 0) - assert.ok(mockStation.getNumberOfEvses() > 0) + assert.ok(mockStation.getNumberOfEvses() > 0, 'should have at least one EVSE') assert.strictEqual(mockStation.stationInfo?.ocppVersion, OCPPVersion.VERSION_201) }) }) diff --git a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStartTransaction.test.ts b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStartTransaction.test.ts index 0b9326b6..ea4e6d94 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStartTransaction.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStartTransaction.test.ts @@ -518,7 +518,7 @@ await describe('F01 & F02 - Remote Start Transaction', async () => { if (response.transactionId == null) { assert.fail('Expected transactionId to be defined') } - assert.ok(response.transactionId.length > 0) + assert.ok(response.transactionId.length > 0, 'transactionId should not be empty') }) await describe('REQUEST_START_TRANSACTION event listener', async () => { diff --git a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-SetVariables.test.ts b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-SetVariables.test.ts index 3794aff6..71261d59 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-SetVariables.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-SetVariables.test.ts @@ -516,11 +516,11 @@ await describe('B05 - Set Variables', async () => { postCalcLimit.toString(), false ) - assert.ok(preEstimate < postCalcLimit) + assert.ok(preEstimate < postCalcLimit, 'pre-estimate should be less than post-calc limit') const response: { setVariableResult: OCPP20SetVariableResultType[] } = testableService.handleRequestSetVariables(mockStation, request) const actualSize = Buffer.byteLength(JSON.stringify(response.setVariableResult), 'utf8') - assert.ok(actualSize > postCalcLimit) + assert.ok(actualSize > postCalcLimit, 'actual response size should exceed post-calc limit') assert.strictEqual(response.setVariableResult.length, request.setVariableData.length) response.setVariableResult.forEach(r => { assert.strictEqual(r.attributeStatus, SetVariableStatusEnumType.Rejected) diff --git a/tests/charging-station/ocpp/2.0/OCPP20RequestService-CallChain.test.ts b/tests/charging-station/ocpp/2.0/OCPP20RequestService-CallChain.test.ts index 4b9fa3a5..3f536b00 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20RequestService-CallChain.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20RequestService-CallChain.test.ts @@ -120,7 +120,10 @@ await describe('OCPP 2.0 Request Call Chain — requestHandler → buildRequestP assert.strictEqual(sendMessageMock.mock.calls.length, 1) const sentPayload = sendMessageMock.mock.calls[0] .arguments[2] as OCPP20TransactionEventRequest - assert.ok(sentPayload.transactionInfo.transactionId.length > 0) + assert.ok( + sentPayload.transactionInfo.transactionId.length > 0, + 'transactionId should not be empty' + ) }) await it('should default triggerReason to Authorized for Started when not provided', async () => { @@ -164,7 +167,10 @@ await describe('OCPP 2.0 Request Call Chain — requestHandler → buildRequestP assert.strictEqual(sendMessageMock.mock.calls.length, 1) const sentPayload = sendMessageMock.mock.calls[0] .arguments[2] as OCPP20TransactionEventRequest - assert.ok(sentPayload.transactionInfo.transactionId.length > 0) + assert.ok( + sentPayload.transactionInfo.transactionId.length > 0, + 'transactionId should not be empty' + ) assert.strictEqual(sentPayload.eventType, OCPP20TransactionEventEnumType.Started) }) }) diff --git a/tests/charging-station/ocpp/2.0/OCPP20RequestService-HeartBeat.test.ts b/tests/charging-station/ocpp/2.0/OCPP20RequestService-HeartBeat.test.ts index 2cdbd767..fa326ddf 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20RequestService-HeartBeat.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20RequestService-HeartBeat.test.ts @@ -18,6 +18,7 @@ import { TEST_CHARGE_POINT_MODEL, TEST_CHARGE_POINT_SERIAL_NUMBER, TEST_CHARGE_POINT_VENDOR, + TEST_CHARGING_STATION_BASE_NAME, TEST_FIRMWARE_VERSION, } from '../../ChargingStationTestConstants.js' import { createMockChargingStation } from '../../ChargingStationTestUtils.js' @@ -126,7 +127,7 @@ await describe('G02 - Heartbeat', async () => { // FR: G02.FR.05 await it('should handle HeartBeat request with different charging station configurations', () => { const { station: alternativeChargingStation } = createMockChargingStation({ - baseName: 'CS-ALTERNATIVE-002', + baseName: TEST_CHARGING_STATION_BASE_NAME, connectorsCount: 3, evseConfiguration: { evsesCount: 3 }, heartbeatInterval: 120, diff --git a/tests/charging-station/ocpp/2.0/OCPP20RequestService-SignCertificate.test.ts b/tests/charging-station/ocpp/2.0/OCPP20RequestService-SignCertificate.test.ts index ff987659..5139b6b9 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20RequestService-SignCertificate.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20RequestService-SignCertificate.test.ts @@ -71,7 +71,10 @@ await describe('I02 - SignCertificate Request', async () => { assert.notStrictEqual(response, undefined) assert.strictEqual(response.status, GenericStatus.Accepted) - assert.ok(sendMessageMock.mock.calls.length > 0) + assert.ok( + sendMessageMock.mock.calls.length > 0, + 'sendMessage should have been called at least once' + ) const sentPayload = sendMessageMock.mock.calls[0].arguments[2] as OCPP20SignCertificateRequest assert.notStrictEqual(sentPayload.csr, undefined) @@ -317,8 +320,8 @@ await describe('I02 - SignCertificate Request', async () => { assert.strictEqual(typeof sentPayload, 'object') assert.notStrictEqual(sentPayload.csr, undefined) assert.strictEqual(typeof sentPayload.csr, 'string') - assert.ok(sentPayload.csr.length > 0) - assert.ok(sentPayload.csr.length <= 5500) + assert.ok(sentPayload.csr.length > 0, 'CSR should not be empty') + assert.ok(sentPayload.csr.length <= 5500, 'CSR length should be at most 5500 characters') }) await it('should send SIGN_CERTIFICATE command name', async () => { diff --git a/tests/charging-station/ocpp/2.0/OCPP20RequestService-StatusNotification.test.ts b/tests/charging-station/ocpp/2.0/OCPP20RequestService-StatusNotification.test.ts index 68d70c5f..d42276d3 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20RequestService-StatusNotification.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20RequestService-StatusNotification.test.ts @@ -227,7 +227,10 @@ await describe('G01 - Status Notification', async () => { assert.notStrictEqual(payload, undefined) assert.ok(payload.timestamp instanceof Date) - assert.ok(payload.timestamp.getTime() >= beforeBuild.getTime()) + assert.ok( + payload.timestamp.getTime() >= beforeBuild.getTime(), + 'timestamp should be at or after build start time' + ) }) }) }) diff --git a/tests/charging-station/ocpp/2.0/OCPP20ResponseService-CacheUpdate.test.ts b/tests/charging-station/ocpp/2.0/OCPP20ResponseService-CacheUpdate.test.ts index 704ef1ae..b07202c3 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20ResponseService-CacheUpdate.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20ResponseService-CacheUpdate.test.ts @@ -18,12 +18,13 @@ import { } from '../../../../src/charging-station/ocpp/auth/index.js' import { OCPPVersion } from '../../../../src/types/index.js' import { standardCleanup } from '../../../helpers/TestLifecycleHelpers.js' +import { + TEST_CHARGING_STATION_BASE_NAME, + TEST_TOKEN_ISO14443, +} from '../../ChargingStationTestConstants.js' import { createMockChargingStation } from '../../ChargingStationTestUtils.js' import { getTestAuthCache } from '../auth/helpers/MockFactories.js' -const TEST_IDENTIFIER = 'TEST_RFID_TOKEN_001' -const TEST_STATION_ID = 'CS_CACHE_UPDATE_TEST' - await describe('C10 - TransactionEventResponse Cache Update', async () => { let station: ChargingStation let authService: OCPPAuthServiceImpl @@ -31,10 +32,10 @@ await describe('C10 - TransactionEventResponse Cache Update', async () => { beforeEach(() => { const { station: mockStation } = createMockChargingStation({ - baseName: TEST_STATION_ID, + baseName: TEST_CHARGING_STATION_BASE_NAME, connectorsCount: 1, stationInfo: { - chargingStationId: TEST_STATION_ID, + chargingStationId: TEST_CHARGING_STATION_BASE_NAME, ocppVersion: OCPPVersion.VERSION_201, }, }) @@ -54,14 +55,14 @@ await describe('C10 - TransactionEventResponse Cache Update', async () => { await it('C10.FR.05 - should update cache on TransactionEventResponse with Accepted idTokenInfo', () => { // Act authService.updateCacheEntry( - TEST_IDENTIFIER, + TEST_TOKEN_ISO14443, AuthorizationStatus.ACCEPTED, undefined, IdentifierType.ISO14443 ) // Assert - const cached = authCache.get(TEST_IDENTIFIER) + const cached = authCache.get(TEST_TOKEN_ISO14443) assert.ok(cached != null, 'Cache entry should exist') assert.strictEqual(cached.status, AuthorizationStatus.ACCEPTED) }) @@ -72,14 +73,14 @@ await describe('C10 - TransactionEventResponse Cache Update', async () => { // Act authService.updateCacheEntry( - TEST_IDENTIFIER, + TEST_TOKEN_ISO14443, AuthorizationStatus.ACCEPTED, futureDate, IdentifierType.ISO14443 ) // Assert - const cached = authCache.get(TEST_IDENTIFIER) + const cached = authCache.get(TEST_TOKEN_ISO14443) assert.ok(cached != null, 'Cache entry should exist with explicit TTL') assert.strictEqual(cached.status, AuthorizationStatus.ACCEPTED) }) @@ -87,14 +88,14 @@ await describe('C10 - TransactionEventResponse Cache Update', async () => { await it('C10.FR.08 - should use AuthCacheLifeTime as TTL when cacheExpiryDateTime absent', () => { // Act — no expiryDate, uses config.authorizationCacheLifetime authService.updateCacheEntry( - TEST_IDENTIFIER, + TEST_TOKEN_ISO14443, AuthorizationStatus.ACCEPTED, undefined, IdentifierType.ISO14443 ) // Assert - const cached = authCache.get(TEST_IDENTIFIER) + const cached = authCache.get(TEST_TOKEN_ISO14443) assert.ok(cached != null, 'Cache entry should exist with default TTL') assert.strictEqual(cached.status, AuthorizationStatus.ACCEPTED) }) @@ -158,24 +159,24 @@ await describe('C10 - TransactionEventResponse Cache Update', async () => { // Act authService.updateCacheEntry( - TEST_IDENTIFIER, + TEST_TOKEN_ISO14443, AuthorizationStatus.ACCEPTED, pastDate, IdentifierType.ISO14443 ) // Assert - const cached = authCache.get(TEST_IDENTIFIER) + const cached = authCache.get(TEST_TOKEN_ISO14443) assert.strictEqual(cached, undefined, 'Expired entry must not be cached') }) await it('should not update cache when authorizationCacheEnabled is false', () => { // Arrange — create service with cache disabled const { station: disabledStation } = createMockChargingStation({ - baseName: 'CS_CACHE_DISABLED', + baseName: TEST_CHARGING_STATION_BASE_NAME, connectorsCount: 1, stationInfo: { - chargingStationId: 'CS_CACHE_DISABLED', + chargingStationId: TEST_CHARGING_STATION_BASE_NAME, ocppVersion: OCPPVersion.VERSION_201, }, }) @@ -185,7 +186,7 @@ await describe('C10 - TransactionEventResponse Cache Update', async () => { // Act disabledService.updateCacheEntry( - TEST_IDENTIFIER, + TEST_TOKEN_ISO14443, AuthorizationStatus.ACCEPTED, undefined, IdentifierType.ISO14443 @@ -193,7 +194,7 @@ await describe('C10 - TransactionEventResponse Cache Update', async () => { // Assert const disabledCache = getTestAuthCache(disabledService) - const cached = disabledCache.get(TEST_IDENTIFIER) + const cached = disabledCache.get(TEST_TOKEN_ISO14443) assert.strictEqual(cached, undefined, 'Cache entry should not exist when cache is disabled') }) }) diff --git a/tests/charging-station/ocpp/2.0/OCPP20ResponseService-TransactionEvent.test.ts b/tests/charging-station/ocpp/2.0/OCPP20ResponseService-TransactionEvent.test.ts index ae433626..1dd2826e 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20ResponseService-TransactionEvent.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20ResponseService-TransactionEvent.test.ts @@ -28,12 +28,12 @@ import { setupConnectorWithTransaction, standardCleanup, } from '../../../helpers/TestLifecycleHelpers.js' -import { TEST_CHARGING_STATION_BASE_NAME } from '../../ChargingStationTestConstants.js' +import { + TEST_CHARGING_STATION_BASE_NAME, + TEST_TRANSACTION_UUID, +} from '../../ChargingStationTestConstants.js' import { createMockChargingStation } from '../../ChargingStationTestUtils.js' -/** UUID used as transactionId in all tests — must match connector.transactionId */ -const TEST_TRANSACTION_ID: UUIDv4 = '00000000-0000-0000-0000-000000000001' - interface TestableOCPP20ResponseService { handleResponseTransactionEvent: ( chargingStation: ChargingStation, @@ -96,7 +96,7 @@ await describe('D01 - TransactionEvent Response', async () => { // Override with UUID string so getConnectorIdByTransactionId can find it const connectorStatus = station.getConnectorStatus(1) if (connectorStatus != null) { - connectorStatus.transactionId = TEST_TRANSACTION_ID + connectorStatus.transactionId = TEST_TRANSACTION_UUID } const responseService = new OCPP20ResponseService() testable = createTestableResponseService(responseService) @@ -118,7 +118,7 @@ await describe('D01 - TransactionEvent Response', async () => { status: OCPP20AuthorizationStatusEnumType.Accepted, }, } - const requestPayload = buildTransactionEventRequest(TEST_TRANSACTION_ID) + const requestPayload = buildTransactionEventRequest(TEST_TRANSACTION_UUID) // Act testable.handleResponseTransactionEvent(station, payload, requestPayload) @@ -139,7 +139,7 @@ await describe('D01 - TransactionEvent Response', async () => { status: OCPP20AuthorizationStatusEnumType.Invalid, }, } - const requestPayload = buildTransactionEventRequest(TEST_TRANSACTION_ID) + const requestPayload = buildTransactionEventRequest(TEST_TRANSACTION_UUID) // Act testable.handleResponseTransactionEvent(station, payload, requestPayload) @@ -163,7 +163,7 @@ await describe('D01 - TransactionEvent Response', async () => { status: OCPP20AuthorizationStatusEnumType.Blocked, }, } - const requestPayload = buildTransactionEventRequest(TEST_TRANSACTION_ID) + const requestPayload = buildTransactionEventRequest(TEST_TRANSACTION_UUID) // Act testable.handleResponseTransactionEvent(station, payload, requestPayload) @@ -183,7 +183,7 @@ await describe('D01 - TransactionEvent Response', async () => { const payload: OCPP20TransactionEventResponse = { chargingPriority: 5, } - const requestPayload = buildTransactionEventRequest(TEST_TRANSACTION_ID) + const requestPayload = buildTransactionEventRequest(TEST_TRANSACTION_UUID) // Act testable.handleResponseTransactionEvent(station, payload, requestPayload) @@ -200,7 +200,7 @@ await describe('D01 - TransactionEvent Response', async () => { () => Promise.resolve({} as OCPP20TransactionEventResponse) ) const payload: OCPP20TransactionEventResponse = {} - const requestPayload = buildTransactionEventRequest(TEST_TRANSACTION_ID) + const requestPayload = buildTransactionEventRequest(TEST_TRANSACTION_UUID) // Act testable.handleResponseTransactionEvent(station, payload, requestPayload) @@ -221,7 +221,7 @@ await describe('D01 - TransactionEvent Response', async () => { status: OCPP20AuthorizationStatusEnumType.Expired, }, } - const requestPayload = buildTransactionEventRequest(TEST_TRANSACTION_ID) + const requestPayload = buildTransactionEventRequest(TEST_TRANSACTION_UUID) // Act testable.handleResponseTransactionEvent(station, payload, requestPayload) @@ -242,7 +242,7 @@ await describe('D01 - TransactionEvent Response', async () => { status: OCPP20AuthorizationStatusEnumType.NoCredit, }, } - const requestPayload = buildTransactionEventRequest(TEST_TRANSACTION_ID) + const requestPayload = buildTransactionEventRequest(TEST_TRANSACTION_UUID) // Act testable.handleResponseTransactionEvent(station, payload, requestPayload) @@ -265,7 +265,7 @@ await describe('D01 - TransactionEvent Response', async () => { format: OCPP20MessageFormatEnumType.UTF8, }, } - const requestPayload = buildTransactionEventRequest(TEST_TRANSACTION_ID) + const requestPayload = buildTransactionEventRequest(TEST_TRANSACTION_UUID) // Act testable.handleResponseTransactionEvent(station, payload, requestPayload) diff --git a/tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-AuthCache.test.ts b/tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-AuthCache.test.ts index 8005077c..d815f6d9 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-AuthCache.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-AuthCache.test.ts @@ -23,12 +23,13 @@ import { OCPPVersion, } from '../../../../src/types/index.js' import { standardCleanup } from '../../../helpers/TestLifecycleHelpers.js' +import { + TEST_CHARGING_STATION_BASE_NAME, + TEST_TOKEN_ISO14443, +} from '../../ChargingStationTestConstants.js' import { createMockChargingStation } from '../../ChargingStationTestUtils.js' import { getTestAuthCache } from '../auth/helpers/MockFactories.js' -const TEST_STATION_ID = 'CS_AUTH_CACHE_UTILS_TEST' -const TEST_TOKEN_VALUE = 'RFID_AUTH_CACHE_001' - await describe('OCPP20ServiceUtils.updateAuthorizationCache', async () => { let station: ChargingStation let authService: OCPPAuthServiceImpl @@ -36,10 +37,10 @@ await describe('OCPP20ServiceUtils.updateAuthorizationCache', async () => { beforeEach(() => { const { station: mockStation } = createMockChargingStation({ - baseName: TEST_STATION_ID, + baseName: TEST_CHARGING_STATION_BASE_NAME, connectorsCount: 1, stationInfo: { - chargingStationId: TEST_STATION_ID, + chargingStationId: TEST_CHARGING_STATION_BASE_NAME, ocppVersion: OCPPVersion.VERSION_201, }, }) @@ -47,7 +48,7 @@ await describe('OCPP20ServiceUtils.updateAuthorizationCache', async () => { authService = new OCPPAuthServiceImpl(station) authService.initialize() - OCPPAuthServiceFactory.setInstanceForTesting(TEST_STATION_ID, authService) + OCPPAuthServiceFactory.setInstanceForTesting(TEST_CHARGING_STATION_BASE_NAME, authService) authCache = getTestAuthCache(authService) }) @@ -60,7 +61,7 @@ await describe('OCPP20ServiceUtils.updateAuthorizationCache', async () => { await it('C10.FR.04 - should update cache on AuthorizeResponse via updateAuthorizationCache', () => { // Arrange const idToken: OCPP20IdTokenType = { - idToken: TEST_TOKEN_VALUE, + idToken: TEST_TOKEN_ISO14443, type: OCPP20IdTokenEnumType.ISO14443, } const idTokenInfo = { @@ -71,7 +72,7 @@ await describe('OCPP20ServiceUtils.updateAuthorizationCache', async () => { OCPP20ServiceUtils.updateAuthorizationCache(station, idToken, idTokenInfo) // Assert - const cached = authCache.get(TEST_TOKEN_VALUE) + const cached = authCache.get(TEST_TOKEN_ISO14443) assert.ok(cached != null, 'AuthorizeResponse should update the cache') assert.strictEqual(cached.status, AuthorizationStatus.ACCEPTED) }) @@ -95,17 +96,17 @@ await describe('OCPP20ServiceUtils.updateAuthorizationCache', async () => { await it('should handle auth service initialization failure gracefully', () => { // Arrange const { station: isolatedStation } = createMockChargingStation({ - baseName: 'CS_NO_AUTH_SERVICE', + baseName: TEST_CHARGING_STATION_BASE_NAME, connectorsCount: 1, stationInfo: { - chargingStationId: 'CS_NO_AUTH_SERVICE', + chargingStationId: TEST_CHARGING_STATION_BASE_NAME, ocppVersion: OCPPVersion.VERSION_201, }, }) OCPPAuthServiceFactory.clearAllInstances() const idToken: OCPP20IdTokenType = { - idToken: TEST_TOKEN_VALUE, + idToken: TEST_TOKEN_ISO14443, type: OCPP20IdTokenEnumType.ISO14443, } const idTokenInfo = { diff --git a/tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-ReconnectDelay.test.ts b/tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-ReconnectDelay.test.ts index fd34f17f..d8c428b1 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-ReconnectDelay.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-ReconnectDelay.test.ts @@ -19,11 +19,10 @@ import { } from '../../../../src/types/index.js' import { Constants } from '../../../../src/utils/index.js' import { standardCleanup } from '../../../helpers/TestLifecycleHelpers.js' +import { TEST_CHARGING_STATION_BASE_NAME } from '../../ChargingStationTestConstants.js' import { createMockChargingStation } from '../../ChargingStationTestUtils.js' import { upsertConfigurationKey } from './OCPP20TestUtils.js' -const TEST_STATION_ID = 'CS_RECONNECT_DELAY_TEST' - const DEFAULT_WAIT_MINIMUM_S = 30 const DEFAULT_RANDOM_RANGE_S = 10 const DEFAULT_REPEAT_TIMES = 5 @@ -73,11 +72,11 @@ await describe('OCPP20ServiceUtils.computeReconnectDelay', async () => { beforeEach(() => { const { station: mockStation } = createMockChargingStation({ - baseName: TEST_STATION_ID, + baseName: TEST_CHARGING_STATION_BASE_NAME, connectorsCount: 1, heartbeatInterval: Constants.DEFAULT_HEARTBEAT_INTERVAL, stationInfo: { - chargingStationId: TEST_STATION_ID, + chargingStationId: TEST_CHARGING_STATION_BASE_NAME, ocppVersion: OCPPVersion.VERSION_201, }, }) diff --git a/tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-TransactionEvent.test.ts b/tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-TransactionEvent.test.ts index 95c0a558..89d1459b 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-TransactionEvent.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-TransactionEvent.test.ts @@ -440,7 +440,7 @@ await describe('OCPP20 TransactionEvent ServiceUtils', async () => { assert.fail('Expected evse to be defined') } assert.strictEqual(typeof transactionEvent.evse.id, 'number') - assert.ok(transactionEvent.evse.id > 0) + assert.ok(transactionEvent.evse.id > 0, 'EVSE ID should be positive') // Validate transactionInfo structure assert.strictEqual(typeof transactionEvent.transactionInfo.transactionId, 'string') diff --git a/tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-enforceMessageLimits.test.ts b/tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-enforceMessageLimits.test.ts index 88a76361..de5a4484 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-enforceMessageLimits.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-enforceMessageLimits.test.ts @@ -383,7 +383,7 @@ await describe('OCPP20ServiceUtils.enforceMessageLimits', async () => { assert.strictEqual(capturedReasons.length, 1) assert.strictEqual(capturedReasons[0].reasonCode, ReasonCodeEnumType.TooLargeElement) assert.strictEqual(typeof capturedReasons[0].additionalInfo, 'string') - assert.ok(capturedReasons[0].additionalInfo.length > 0) + assert.ok(capturedReasons[0].additionalInfo.length > 0, 'additionalInfo should not be empty') }) }) }) diff --git a/tests/charging-station/ocpp/OCPPServiceOperations.test.ts b/tests/charging-station/ocpp/OCPPServiceOperations.test.ts index 74434bc8..474e078a 100644 --- a/tests/charging-station/ocpp/OCPPServiceOperations.test.ts +++ b/tests/charging-station/ocpp/OCPPServiceOperations.test.ts @@ -125,7 +125,10 @@ await describe('OCPPServiceOperations', async () => { const result = await stopTransactionOnConnector(station, 1) assert.strictEqual(result.accepted, true) - assert.ok(requestHandler.mock.calls.length >= 1) + assert.ok( + requestHandler.mock.calls.length >= 1, + 'request handler should have been called at least once' + ) assert.strictEqual(requestHandler.mock.calls[0].arguments[1] as string, 'StopTransaction') }) @@ -142,7 +145,10 @@ await describe('OCPPServiceOperations', async () => { const result = await stopTransactionOnConnector(station, 1) assert.strictEqual(result.accepted, true) - assert.ok(requestHandler.mock.calls.length >= 1) + assert.ok( + requestHandler.mock.calls.length >= 1, + 'request handler should have been called at least once' + ) assert.strictEqual(requestHandler.mock.calls[0].arguments[1] as string, 'TransactionEvent') }) @@ -258,7 +264,10 @@ await describe('OCPPServiceOperations', async () => { const result = await startTransactionOnConnector(station, 1, 'TAG001') assert.strictEqual(result.accepted, true) - assert.ok(requestHandler.mock.calls.length >= 1) + assert.ok( + requestHandler.mock.calls.length >= 1, + 'request handler should have been called at least once' + ) assert.strictEqual(requestHandler.mock.calls[0].arguments[1] as string, 'StartTransaction') }) @@ -274,7 +283,10 @@ await describe('OCPPServiceOperations', async () => { const result = await startTransactionOnConnector(station, 1, 'TAG002') assert.strictEqual(result.accepted, true) - assert.ok(requestHandler.mock.calls.length >= 1) + assert.ok( + requestHandler.mock.calls.length >= 1, + 'request handler should have been called at least once' + ) assert.strictEqual(requestHandler.mock.calls[0].arguments[1] as string, 'TransactionEvent') }) diff --git a/tests/charging-station/ocpp/auth/cache/InMemoryAuthCache.test.ts b/tests/charging-station/ocpp/auth/cache/InMemoryAuthCache.test.ts index 532a9051..4b4b7cba 100644 --- a/tests/charging-station/ocpp/auth/cache/InMemoryAuthCache.test.ts +++ b/tests/charging-station/ocpp/auth/cache/InMemoryAuthCache.test.ts @@ -193,7 +193,7 @@ await describe('InMemoryAuthCache - OCPP 2.0.1 Authorization Cache Conformance', cache.get('token-2') const stats = cache.getStats() - assert.ok(stats.expiredEntries >= 2) + assert.ok(stats.expiredEntries >= 2, 'should track at least 2 expired entries') }) }) @@ -271,8 +271,8 @@ await describe('InMemoryAuthCache - OCPP 2.0.1 Authorization Cache Conformance', cache.get('miss') const statsBefore = cache.getStats() - assert.ok(statsBefore.hits > 0) - assert.ok(statsBefore.misses > 0) + assert.ok(statsBefore.hits > 0, 'should have cache hits before clear') + assert.ok(statsBefore.misses > 0, 'should have cache misses before clear') cache.clear() @@ -303,7 +303,10 @@ await describe('InMemoryAuthCache - OCPP 2.0.1 Authorization Cache Conformance', assert.strictEqual(result, undefined) const stats = cache.getStats() - assert.ok(stats.rateLimit.blockedRequests > 0) + assert.ok( + stats.rateLimit.blockedRequests > 0, + 'should have blocked requests in rate limit stats' + ) }) await it('should track rate limit statistics', () => { @@ -316,8 +319,8 @@ await describe('InMemoryAuthCache - OCPP 2.0.1 Authorization Cache Conformance', cache.set(identifier, mockResult) // Should be blocked const stats = cache.getStats() - assert.ok(stats.rateLimit.totalChecks > 0) - assert.ok(stats.rateLimit.blockedRequests > 0) + assert.ok(stats.rateLimit.totalChecks > 0, 'should have total rate limit checks') + assert.ok(stats.rateLimit.blockedRequests > 0, 'should have blocked requests') }) await it('should reset rate limit after window expires', async t => { @@ -428,7 +431,7 @@ await describe('InMemoryAuthCache - OCPP 2.0.1 Authorization Cache Conformance', assert.strictEqual(stats.hits, 1) assert.strictEqual(stats.misses, 1) assert.strictEqual(stats.hitRate, 50) - assert.ok(stats.memoryUsage > 0) + assert.ok(stats.memoryUsage > 0, 'should have positive memory usage') }) await it('should track memory usage estimate', () => { @@ -443,7 +446,7 @@ await describe('InMemoryAuthCache - OCPP 2.0.1 Authorization Cache Conformance', const statsAfter = cache.getStats() const memoryAfter = statsAfter.memoryUsage - assert.ok(memoryAfter > memoryBefore) + assert.ok(memoryAfter > memoryBefore, 'memory usage should increase with more entries') }) await it('should provide rate limit statistics', () => { @@ -456,9 +459,9 @@ await describe('InMemoryAuthCache - OCPP 2.0.1 Authorization Cache Conformance', const stats = cache.getStats() assert.notStrictEqual(stats.rateLimit, undefined) - assert.ok(stats.rateLimit.totalChecks > 0) - assert.ok(stats.rateLimit.blockedRequests > 0) - assert.ok(stats.rateLimit.rateLimitedIdentifiers > 0) + assert.ok(stats.rateLimit.totalChecks > 0, 'should have total rate limit checks') + assert.ok(stats.rateLimit.blockedRequests > 0, 'should have blocked requests') + assert.ok(stats.rateLimit.rateLimitedIdentifiers > 0, 'should have rate limited identifiers') }) }) @@ -804,7 +807,7 @@ await describe('InMemoryAuthCache - OCPP 2.0.1 Authorization Cache Conformance', } const rateLimitsSize = boundedCache.getStats().rateLimit.rateLimitedIdentifiers - assert.ok(rateLimitsSize <= 4) + assert.ok(rateLimitsSize <= 4, 'rate limits size should be at most 4') boundedCache.dispose() }) }) @@ -825,9 +828,9 @@ await describe('InMemoryAuthCache - OCPP 2.0.1 Authorization Cache Conformance', statsCache.get('id-miss') // miss const before = statsCache.getStats() - assert.ok(before.evictions > 0) - assert.ok(before.hits > 0) - assert.ok(before.misses > 0) + assert.ok(before.evictions > 0, 'should have evictions') + assert.ok(before.hits > 0, 'should have cache hits') + assert.ok(before.misses > 0, 'should have cache misses') statsCache.clear() @@ -852,8 +855,8 @@ await describe('InMemoryAuthCache - OCPP 2.0.1 Authorization Cache Conformance', statsCache.get('id-miss') // miss const before = statsCache.getStats() - assert.ok(before.hits > 0) - assert.ok(before.misses > 0) + assert.ok(before.hits > 0, 'should have cache hits before reset') + assert.ok(before.misses > 0, 'should have cache misses before reset') statsCache.resetStats() @@ -878,7 +881,7 @@ await describe('InMemoryAuthCache - OCPP 2.0.1 Authorization Cache Conformance', statsCache.clear() // clears entries but preserves stats const afterClear = statsCache.getStats() - assert.ok(afterClear.hits > 0) // stats preserved + assert.ok(afterClear.hits > 0, 'stats preserved after clear') // stats preserved assert.strictEqual(afterClear.totalEntries, 0) // entries gone statsCache.resetStats() // now zero out diff --git a/tests/charging-station/ocpp/auth/utils/AuthHelpers.test.ts b/tests/charging-station/ocpp/auth/utils/AuthHelpers.test.ts index 0499605e..e3c6091b 100644 --- a/tests/charging-station/ocpp/auth/utils/AuthHelpers.test.ts +++ b/tests/charging-station/ocpp/auth/utils/AuthHelpers.test.ts @@ -38,8 +38,8 @@ await describe('AuthHelpers', async () => { const result = AuthHelpers.calculateTTL(futureDate) assert.notStrictEqual(result, undefined) if (result !== undefined) { - assert.ok(result >= 4) - assert.ok(result <= 5) + assert.ok(result >= 4, 'TTL should be at least 4 seconds') + assert.ok(result <= 5, 'TTL should be at most 5 seconds') } }) -- 2.53.0