]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
test(ocpp): harmonize test constants and assertion messages
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 1 Apr 2026 17:25:46 +0000 (19:25 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 1 Apr 2026 17:25:46 +0000 (19:25 +0200)
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.

29 files changed:
tests/charging-station/ChargingStationTestConstants.ts
tests/charging-station/ocpp/1.6/OCPP16Constants.test.ts
tests/charging-station/ocpp/1.6/OCPP16IncomingRequestService-Configuration.test.ts
tests/charging-station/ocpp/1.6/OCPP16Integration-Configuration.test.ts
tests/charging-station/ocpp/1.6/OCPP16ServiceUtils.test.ts
tests/charging-station/ocpp/2.0/Asn1DerUtils.test.ts
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-ChangeAvailability.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-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-SetVariables.test.ts
tests/charging-station/ocpp/2.0/OCPP20RequestService-CallChain.test.ts
tests/charging-station/ocpp/2.0/OCPP20RequestService-HeartBeat.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-CacheUpdate.test.ts
tests/charging-station/ocpp/2.0/OCPP20ResponseService-TransactionEvent.test.ts
tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-AuthCache.test.ts
tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-ReconnectDelay.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/OCPPServiceOperations.test.ts
tests/charging-station/ocpp/auth/cache/InMemoryAuthCache.test.ts
tests/charging-station/ocpp/auth/utils/AuthHelpers.test.ts

index bbf770ff7b4871ccef82e6084243d74dea3496a3..0ee64e3e7f42199c3aa89cb85b6dbeb5fa70202a 100644 (file)
@@ -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
 
 /**
index b4665cc2cd5e6dd55a3d75991a25cbce942d4ac2..ba49028b016868ca194f131c31a5ce7c92570a40 100644 (file)
@@ -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', () => {
index 324991c76cb006c0b4a33f743961af513c971d8c..b336fd20da64a5e79056f860629c1f93ea91ede7 100644 (file)
@@ -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)
     )
index 6e9a251321b2f7a48f0db618222aba9cbcda11cc..a2d7689409ba981792eab5a309bfe8b849ac5ed0 100644 (file)
@@ -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(
index 6fcc6822be697da3e563fc36b361d326060644a5..630ef0928ba4211174bf09e06bbd2d1fe850eb36 100644 (file)
@@ -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,
         },
       })
index 8387c1e58d8f982d3f2e4b0df4d6810d64edf32d..7083c0f968222a3da35bb752462a64f6bc09bfef 100644 (file)
@@ -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'
+      )
     })
   })
 })
index c0f1fb8da052348f6cab91fd4460414e2cbbf1fc..3327bea314e8a5e2a82e308cb03b0301f3004a4b 100644 (file)
@@ -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)
     })
index cde145f4f10ff799c3debdc3ea217c125263c9d3..c80a3a44a36fdeef01632d2e4e6ef6b444e770da 100644 (file)
@@ -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'
+      )
     })
   })
 
index 2b885e2b2932b18f32f99258653f0f17f44e938f..b1bcf9046600803e22fc1c931c9da00a2cd93bc7 100644 (file)
@@ -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)
   })
index 54be61744e583c17cd59e365ef324ad68f82ed20..9ca69b2f76a4dd1a7a0a8921e90c32645ae203c1 100644 (file)
@@ -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'
+      )
     })
   })
 
index c163af83bc642ce26e7cac4eb3d3cea195c2ce5f..2bfdc5b00bc48e68fd33de35b178ee184b12c583 100644 (file)
@@ -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')
     }
   })
 
index 6743d2accc8f7260e81fc6a1141e7450e8eb059b..6789d323e378409319fe0feb6fc508a5881deb3a 100644 (file)
@@ -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)
   })
 })
index a995279bb04e473b4082fe56238fe5bd72f67db4..1bef26db7989f06b913e7646c050c673d12edcd4 100644 (file)
@@ -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'
+      )
     })
   })
 })
index 6c46f17b89e32a4306692903442e309ca123699a..02a6c7b48de59f42641794b384c6f8eb522731e2 100644 (file)
@@ -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)
     })
   })
index 0b9326b6ab2b2b0588489a23d3bb1397a56cd6f6..ea4e6d945ec97950b38c1f3ebad41b80f608f685 100644 (file)
@@ -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 () => {
index 3794aff6f93b2b213569c4b3edf95c3af89b6294..71261d5926bd1d94c88668123232c3490aa611ab 100644 (file)
@@ -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)
index 4b9fa3a552ccbe3cfb165d62c130df060f355ec6..3f536b001745447e80a7c3fb33b6407b2530c087 100644 (file)
@@ -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)
     })
   })
index 2cdbd76738d00a63d7dfc3dddc532932381526aa..fa326ddf880eee012692d378e7c552af0e558d89 100644 (file)
@@ -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,
index ff98765945f5a35aef6cd9bafd88bcd923f93a06..5139b6b99c0e032c0883c9ef71f7362f8087e156 100644 (file)
@@ -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 () => {
index 68d70c5f3638047e7ba2f69b6f1ba24222c034c3..d42276d3c251f50e47c91d037eaed27f320f7386 100644 (file)
@@ -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'
+      )
     })
   })
 })
index 704ef1aedf51d465d70eda3f9127deebe36fc748..b07202c321df747aa2ef99f3cd8996fae471bf1f 100644 (file)
@@ -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')
   })
 })
index ae4336260eb165c11c1bab4901e3bbfe3e716583..1dd2826e1bca39b41add3859e5176b384f85febd 100644 (file)
@@ -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)
index 8005077c52860b476d3a16ffafd333bb8cb2c4ef..d815f6d9b5d6a898b152a0e30bcf8310c752de34 100644 (file)
@@ -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 = {
index fd34f17fde8a2e762e9608d7119c698d672b3229..d8c428b1064b0bbcd782ba6b09f2c3b863affa5c 100644 (file)
@@ -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,
       },
     })
index 95c0a55890e598d9b5a431d7456819c3b24aaf3a..89d1459bd37f04c5dc9add6f8a86fd099a995a79 100644 (file)
@@ -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')
index 88a76361c03b8ac23b7f0e394cb39c0a1eaa5d80..de5a44848c7c2b3187377777b7488899f8b86d8c 100644 (file)
@@ -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')
     })
   })
 })
index 74434bc8e9d4f479634cdbc5779bb0de21423757..474e078a7189f9d5d81bc0b4d0d38343b19760ae 100644 (file)
@@ -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')
     })
 
index 532a90518aa551e467c2f7de662b5320f52196fe..4b4b7cba30f9febc892c6319d43c1916c6ee661e 100644 (file)
@@ -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
index 0499605e04b476a158f6c15aa8f03b1b0ffb90bc..e3c6091b2fe94ec06f6ea84c172d9fbe5f44b4f5 100644 (file)
@@ -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')
       }
     })