From: Jérôme Benoit Date: Sun, 1 Mar 2026 21:38:38 +0000 (+0100) Subject: refactor(test): harmonize test file headers and fix async patterns X-Git-Tag: ocpp-server@v3.0.0~42 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=23fe97146e9f2045470a9e4aee511dc08a23e111;p=e-mobility-charging-stations-simulator.git refactor(test): harmonize test file headers and fix async patterns - 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 --- diff --git a/tests/charging-station/ChargingStationTestConstants.ts b/tests/charging-station/ChargingStationTestConstants.ts index d69ec4e8..47416a07 100644 --- a/tests/charging-station/ChargingStationTestConstants.ts +++ b/tests/charging-station/ChargingStationTestConstants.ts @@ -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 diff --git a/tests/charging-station/ocpp/auth/helpers/MockFactories.ts b/tests/charging-station/ocpp/auth/helpers/MockFactories.ts index 5ec880d3..7c6b9fca 100644 --- a/tests/charging-station/ocpp/auth/helpers/MockFactories.ts +++ b/tests/charging-station/ocpp/auth/helpers/MockFactories.ts @@ -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' diff --git a/tests/charging-station/ocpp/auth/utils/ConfigValidator.test.ts b/tests/charging-station/ocpp/auth/utils/ConfigValidator.test.ts index fb9d91fb..915a43f9 100644 --- a/tests/charging-station/ocpp/auth/utils/ConfigValidator.test.ts +++ b/tests/charging-station/ocpp/auth/utils/ConfigValidator.test.ts @@ -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' diff --git a/tests/charging-station/ui-server/UIHttpServer.test.ts b/tests/charging-station/ui-server/UIHttpServer.test.ts index 978a5c8d..8d4a5950 100644 --- a/tests/charging-station/ui-server/UIHttpServer.test.ts +++ b/tests/charging-station/ui-server/UIHttpServer.test.ts @@ -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' diff --git a/tests/charging-station/ui-server/UIServerTestConstants.ts b/tests/charging-station/ui-server/UIServerTestConstants.ts index e95ba4d2..ca5605c2 100644 --- a/tests/charging-station/ui-server/UIServerTestConstants.ts +++ b/tests/charging-station/ui-server/UIServerTestConstants.ts @@ -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' diff --git a/tests/charging-station/ui-server/UIServerTestUtils.ts b/tests/charging-station/ui-server/UIServerTestUtils.ts index 8121ad65..3d1acce0 100644 --- a/tests/charging-station/ui-server/UIServerTestUtils.ts +++ b/tests/charging-station/ui-server/UIServerTestUtils.ts @@ -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' diff --git a/tests/charging-station/ui-server/ui-services/AbstractUIService.test.ts b/tests/charging-station/ui-server/ui-services/AbstractUIService.test.ts index 238d5a1c..68d0889c 100644 --- a/tests/charging-station/ui-server/ui-services/AbstractUIService.test.ts +++ b/tests/charging-station/ui-server/ui-services/AbstractUIService.test.ts @@ -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' diff --git a/tests/utils/AsyncLock.test.ts b/tests/utils/AsyncLock.test.ts index cb5f39cf..6106987c 100644 --- a/tests/utils/AsyncLock.test.ts +++ b/tests/utils/AsyncLock.test.ts @@ -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[] = [] 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[] = [] 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)) }) })