]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
refactor(test): harmonize test file headers and fix async patterns
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 1 Mar 2026 21:38:38 +0000 (22:38 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 1 Mar 2026 21:38:38 +0000 (22:38 +0100)
- Remove copyright headers from test files (align with JSDoc-only)
- Replace copyright with JSDoc headers in helper/constant files
- Fix AsyncLock.test.ts Promise anti-pattern (proper async/await)
- Add magic number constants to ChargingStationTestConstants.ts
- Fix semantic duplication with TEST_ONE_HOUR_SECONDS

tests/charging-station/ChargingStationTestConstants.ts
tests/charging-station/ocpp/auth/helpers/MockFactories.ts
tests/charging-station/ocpp/auth/utils/ConfigValidator.test.ts
tests/charging-station/ui-server/UIHttpServer.test.ts
tests/charging-station/ui-server/UIServerTestConstants.ts
tests/charging-station/ui-server/UIServerTestUtils.ts
tests/charging-station/ui-server/ui-services/AbstractUIService.test.ts
tests/utils/AsyncLock.test.ts

index d69ec4e8204a7e1285322253a230236e876d4543..47416a0799a7a1f6aafae42898f9b12d94f7fc19 100644 (file)
@@ -22,7 +22,8 @@ export const TEST_CHARGING_STATION_HASH_ID = 'cs-test-hash-001'
 export const TEST_HEARTBEAT_INTERVAL_SECONDS = 60
 export const TEST_HEARTBEAT_INTERVAL_MS = 30000
 export const TEST_AUTHORIZATION_TIMEOUT_MS = 30000
-export const TEST_ONE_HOUR_MS = 3600000
+export const TEST_ONE_HOUR_SECONDS = 3600
+export const TEST_ONE_HOUR_MS = TEST_ONE_HOUR_SECONDS * 1000
 
 /**
  * Charging Station Information
@@ -71,3 +72,30 @@ export const TEST_TRANSACTION_ENERGY_WH = 5000
 export const TEST_TOKEN_ISO14443 = 'TEST_RFID_TOKEN_001'
 export const TEST_TOKEN_EMAID = 'DE*ABC*E123456*1'
 export const TEST_TOKEN_CENTRAL = 'CENTRAL_TOKEN_001'
+
+/**
+ * Cache Configuration Constants
+ * Test values for cache-related timing and limits
+ */
+export const TEST_CACHE_TTL_SECONDS = TEST_ONE_HOUR_SECONDS
+export const TEST_MAX_CACHE_ENTRIES = 1000
+
+/**
+ * Rate Limiting Constants
+ * Test values for rate limiting windows and intervals
+ */
+export const TEST_RATE_LIMIT_WINDOW_MS = 1000
+
+/**
+ * Custom Interval Constants
+ * Test values for custom heartbeat and timeout intervals
+ */
+export const TEST_CUSTOM_HEARTBEAT_INTERVAL_SECONDS = 120
+export const TEST_REJECTED_HEARTBEAT_INTERVAL_SECONDS = TEST_ONE_HOUR_SECONDS
+
+/**
+ * OCPP 2.0 Value Size Limits
+ * Test values for variable value size constraints
+ */
+export const TEST_VALUE_SIZE_LIMIT = 120
+export const TEST_CONFIGURATION_VALUE_SIZE = 60
index 5ec880d3d9afd74fd2bb736ae9d722b34150a226..7c6b9fca7a43f98e2fb905e06b09ab7f2e302d5e 100644 (file)
@@ -1,5 +1,7 @@
-// Copyright Jerome Benoit. 2021-2025. All Rights Reserved.
-
+/**
+ * @file MockFactories
+ * @description Mock factory functions for authentication testing
+ */
 import { expect } from '@std/expect'
 
 import type { ChargingStation } from '../../../../../src/charging-station/ChargingStation.js'
index fb9d91fba91dd5a1a8048fd4b249d7d684a8b718..915a43f9ac69fe462066665f000cf5c6049eee4a 100644 (file)
@@ -2,7 +2,6 @@
  * @file Tests for AuthConfigValidator
  * @description Unit tests for authentication configuration validation
  */
-// Copyright Jerome Benoit. 2021-2025. All Rights Reserved.
 
 import { expect } from '@std/expect'
 import { afterEach, describe, it } from 'node:test'
index 978a5c8d74ea8a3278ad7100c567a5ba5a8a711e..8d4a5950d960d6762cb7aeaef35d49bc7772e419 100644 (file)
@@ -2,7 +2,6 @@
  * @file Tests for UIHttpServer
  * @description Unit tests for HTTP-based UI server and response handling
  */
-// Copyright Jerome Benoit. 2024-2025. All Rights Reserved.
 
 import { expect } from '@std/expect'
 import { afterEach, beforeEach, describe, it } from 'node:test'
index e95ba4d26b7b8f22b66f3d75effde54609294a1b..ca5605c24ae470736cba752244193c89d023a17b 100644 (file)
@@ -1,4 +1,7 @@
-// Copyright Jerome Benoit. 2024-2025. All Rights Reserved.
+/**
+ * @file UI Server test constants
+ * @description Common constants for UI server test suites (WebSocket, HTTP)
+ */
 
 import type { UUIDv4 } from '../../../src/types/index.js'
 
index 8121ad65e611d9ce5ca7be54af34820d499aba82..3d1acce0703b210ff9368c9a24e9f2390b07231f 100644 (file)
@@ -1,5 +1,7 @@
-// Copyright Jerome Benoit. 2024-2025. All Rights Reserved.
-
+/**
+ * @file UIServerTestUtils
+ * @description Test utilities for UI server testing
+ */
 import type { IncomingMessage } from 'node:http'
 
 import { EventEmitter } from 'node:events'
index 238d5a1c5abb7bd2d23c663791cb831f685e35cc..68d0889c101ab186cadb049c4c2f1eaa7db64119 100644 (file)
@@ -2,7 +2,6 @@
  * @file Tests for AbstractUIService
  * @description Unit tests for abstract UI service base class functionality
  */
-// Copyright Jerome Benoit. 2024-2025. All Rights Reserved.
 
 import { expect } from '@std/expect'
 import { afterEach, describe, it } from 'node:test'
index cb5f39cf77fb0c1964ea3422c5bdaf016afeaafd..6106987c1983a1e65986ae65f5681418db510413 100644 (file)
@@ -13,24 +13,23 @@ await describe('AsyncLock', async () => {
   afterEach(() => {
     standardCleanup()
   })
-  await it('should run synchronous functions exclusively in sequence', () => {
+  await it('should run synchronous functions exclusively in sequence', async () => {
     const runs = 10
     const executed: number[] = []
     let count = 0
     const fn = () => {
       executed.push(++count)
     }
+
+    const promises: Promise<void>[] = []
     for (let i = 0; i < runs; i++) {
-      AsyncLock.runExclusive(AsyncLockType.configuration, fn)
-        .then(() => {
-          expect(executed).toStrictEqual(new Array(count).fill(0).map((_, i) => ++i))
-          return undefined
-        })
-        .catch(console.error)
+      promises.push(AsyncLock.runExclusive(AsyncLockType.configuration, fn))
     }
+    await Promise.all(promises)
+    expect(executed).toStrictEqual(new Array(runs).fill(0).map((_, i) => ++i))
   })
 
-  await it('should run asynchronous functions exclusively in sequence', () => {
+  await it('should run asynchronous functions exclusively in sequence', async () => {
     const runs = 10
     const executed: number[] = []
     let count = 0
@@ -40,13 +39,12 @@ await describe('AsyncLock', async () => {
       })
       executed.push(++count)
     }
+
+    const promises: Promise<void>[] = []
     for (let i = 0; i < runs; i++) {
-      AsyncLock.runExclusive(AsyncLockType.configuration, asyncFn)
-        .then(() => {
-          expect(executed).toStrictEqual(new Array(count).fill(0).map((_, i) => ++i))
-          return undefined
-        })
-        .catch(console.error)
+      promises.push(AsyncLock.runExclusive(AsyncLockType.configuration, asyncFn))
     }
+    await Promise.all(promises)
+    expect(executed).toStrictEqual(new Array(runs).fill(0).map((_, i) => ++i))
   })
 })