From 454427f5cd65568d839e1fd3ba201ed52eadef16 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 28 Feb 2026 17:56:29 +0100 Subject: [PATCH] fix(test-isolation): replace mock.reset() with mock.restoreAll() in auth tests - Replace incorrect mock.reset() with mock.restoreAll() in 7 auth test files - Remove duplicate table rows in TEST_STYLE_GUIDE.md (lines 287-296) Ensures proper mock cleanup between tests to prevent cross-test pollution. --- tests/TEST_STYLE_GUIDE.md | 10 ---------- .../ocpp/auth/OCPPAuthIntegration.test.ts | 2 +- .../ocpp/auth/adapters/OCPP16AuthAdapter.test.ts | 2 +- .../ocpp/auth/adapters/OCPP20AuthAdapter.test.ts | 2 +- .../ocpp/auth/cache/InMemoryAuthCache.test.ts | 2 +- .../auth/strategies/CertificateAuthStrategy.test.ts | 2 +- .../ocpp/auth/strategies/LocalAuthStrategy.test.ts | 2 +- .../ocpp/auth/strategies/RemoteAuthStrategy.test.ts | 2 +- 8 files changed, 7 insertions(+), 17 deletions(-) diff --git a/tests/TEST_STYLE_GUIDE.md b/tests/TEST_STYLE_GUIDE.md index db9bde70..886c407b 100644 --- a/tests/TEST_STYLE_GUIDE.md +++ b/tests/TEST_STYLE_GUIDE.md @@ -284,16 +284,6 @@ The following utilities are available for reuse across test files: | `waitForCondition()` | `helpers/StationHelpers.ts` | Async condition waiting with timeout | | `cleanupChargingStation()` | `helpers/StationHelpers.ts` | Proper station cleanup for afterEach | | Auth factories | `ocpp/auth/helpers/MockFactories.ts` | Auth-specific mock creation | -| ----------------------------- | ------------------------------------ | ----------------------------------------- | -| `createMockChargingStation()` | `ChargingStationTestUtils.ts` | Lightweight mock station stub | -| `createChargingStation()` | `ChargingStationFactory.ts` | Full test station with OCPP services | -| `createConnectorStatus()` | `helpers/StationHelpers.ts` | ConnectorStatus factory with defaults | -| `MockWebSocket` | `mocks/MockWebSocket.ts` | WebSocket simulation with message capture | -| `MockIdTagsCache` | `mocks/MockCaches.ts` | In-memory IdTags cache mock | -| `MockSharedLRUCache` | `mocks/MockCaches.ts` | In-memory LRU cache mock | -| `waitForCondition()` | `helpers/StationHelpers.ts` | Async condition waiting with timeout | -| `cleanupChargingStation()` | `helpers/StationHelpers.ts` | Proper station cleanup for afterEach | -| Auth factories | `ocpp/auth/helpers/MockFactories.ts` | Auth-specific mock creation | **DO NOT duplicate these utilities.** Import and reuse them. diff --git a/tests/charging-station/ocpp/auth/OCPPAuthIntegration.test.ts b/tests/charging-station/ocpp/auth/OCPPAuthIntegration.test.ts index 4fd434ce..be49d700 100644 --- a/tests/charging-station/ocpp/auth/OCPPAuthIntegration.test.ts +++ b/tests/charging-station/ocpp/auth/OCPPAuthIntegration.test.ts @@ -51,7 +51,7 @@ await describe('OCPP Authentication Integration Tests', async () => { }) afterEach(() => { - mock.reset() + mock.restoreAll() }) await describe('OCPP 1.6 Authentication Flow', async () => { diff --git a/tests/charging-station/ocpp/auth/adapters/OCPP16AuthAdapter.test.ts b/tests/charging-station/ocpp/auth/adapters/OCPP16AuthAdapter.test.ts index be24f97d..75032da5 100644 --- a/tests/charging-station/ocpp/auth/adapters/OCPP16AuthAdapter.test.ts +++ b/tests/charging-station/ocpp/auth/adapters/OCPP16AuthAdapter.test.ts @@ -57,7 +57,7 @@ await describe('OCPP16AuthAdapter', async () => { }) afterEach(() => { - mock.reset() + mock.restoreAll() }) await describe('constructor', async () => { diff --git a/tests/charging-station/ocpp/auth/adapters/OCPP20AuthAdapter.test.ts b/tests/charging-station/ocpp/auth/adapters/OCPP20AuthAdapter.test.ts index 41f8c8e0..1871c139 100644 --- a/tests/charging-station/ocpp/auth/adapters/OCPP20AuthAdapter.test.ts +++ b/tests/charging-station/ocpp/auth/adapters/OCPP20AuthAdapter.test.ts @@ -44,7 +44,7 @@ await describe('OCPP20AuthAdapter', async () => { }) afterEach(() => { - mock.reset() + mock.restoreAll() }) await describe('constructor', async () => { diff --git a/tests/charging-station/ocpp/auth/cache/InMemoryAuthCache.test.ts b/tests/charging-station/ocpp/auth/cache/InMemoryAuthCache.test.ts index 247d1791..54ca9e4b 100644 --- a/tests/charging-station/ocpp/auth/cache/InMemoryAuthCache.test.ts +++ b/tests/charging-station/ocpp/auth/cache/InMemoryAuthCache.test.ts @@ -39,7 +39,7 @@ await describe('InMemoryAuthCache - G03.FR.01 Conformance', async () => { }) afterEach(() => { - mock.reset() + mock.restoreAll() }) await describe('G03.FR.01.001 - Cache Hit Behavior', async () => { diff --git a/tests/charging-station/ocpp/auth/strategies/CertificateAuthStrategy.test.ts b/tests/charging-station/ocpp/auth/strategies/CertificateAuthStrategy.test.ts index 9ce11570..195ebf8b 100644 --- a/tests/charging-station/ocpp/auth/strategies/CertificateAuthStrategy.test.ts +++ b/tests/charging-station/ocpp/auth/strategies/CertificateAuthStrategy.test.ts @@ -57,7 +57,7 @@ await describe('CertificateAuthStrategy', async () => { }) afterEach(() => { - mock.reset() + mock.restoreAll() }) await describe('constructor', async () => { diff --git a/tests/charging-station/ocpp/auth/strategies/LocalAuthStrategy.test.ts b/tests/charging-station/ocpp/auth/strategies/LocalAuthStrategy.test.ts index 0c5e0438..50ae6b7d 100644 --- a/tests/charging-station/ocpp/auth/strategies/LocalAuthStrategy.test.ts +++ b/tests/charging-station/ocpp/auth/strategies/LocalAuthStrategy.test.ts @@ -38,7 +38,7 @@ await describe('LocalAuthStrategy', async () => { }) afterEach(() => { - mock.reset() + mock.restoreAll() }) await describe('constructor', async () => { diff --git a/tests/charging-station/ocpp/auth/strategies/RemoteAuthStrategy.test.ts b/tests/charging-station/ocpp/auth/strategies/RemoteAuthStrategy.test.ts index 6f485b12..2d57bec1 100644 --- a/tests/charging-station/ocpp/auth/strategies/RemoteAuthStrategy.test.ts +++ b/tests/charging-station/ocpp/auth/strategies/RemoteAuthStrategy.test.ts @@ -44,7 +44,7 @@ await describe('RemoteAuthStrategy', async () => { }) afterEach(() => { - mock.reset() + mock.restoreAll() }) await describe('constructor', async () => { -- 2.43.0