From 1584ca620dadbb3ceff1bbad7a514bc7bb5970c3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 2 Apr 2026 22:49:24 +0200 Subject: [PATCH] refactor(tests): migrate inline mock stations to shared factory Replace inline as-unknown-as ChargingStation casts in CertificateAuthStrategy and OCPP20AuthAdapter tests with createMockAuthServiceTestStation factory. Add inAcceptedState method to the shared auth test station factory. --- .../charging-station/ocpp/auth/helpers/MockFactories.ts | 1 + .../ocpp/auth/strategies/CertificateAuthStrategy.test.ts | 9 ++------- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/charging-station/ocpp/auth/helpers/MockFactories.ts b/tests/charging-station/ocpp/auth/helpers/MockFactories.ts index b2186cbe..f1ca5865 100644 --- a/tests/charging-station/ocpp/auth/helpers/MockFactories.ts +++ b/tests/charging-station/ocpp/auth/helpers/MockFactories.ts @@ -297,6 +297,7 @@ export const createMockAuthServiceTestStation = ( ({ getConnectorStatus: () => ({ status: 'Available' }), idTagLocalAuthorized: () => false, + inAcceptedState: () => true, isConnected: () => true, logPrefix: () => `[TEST-CS-${id}]`, sendRequest: () => diff --git a/tests/charging-station/ocpp/auth/strategies/CertificateAuthStrategy.test.ts b/tests/charging-station/ocpp/auth/strategies/CertificateAuthStrategy.test.ts index 31597349..5fe4c621 100644 --- a/tests/charging-station/ocpp/auth/strategies/CertificateAuthStrategy.test.ts +++ b/tests/charging-station/ocpp/auth/strategies/CertificateAuthStrategy.test.ts @@ -20,6 +20,7 @@ import { standardCleanup } from '../../../../helpers/TestLifecycleHelpers.js' import { createMockAuthorizationResult, createMockAuthRequest, + createMockAuthServiceTestStation, createMockOCPPAdapter, createTestAuthConfig, } from '../helpers/MockFactories.js' @@ -30,13 +31,7 @@ await describe('CertificateAuthStrategy', async () => { let mockOCPP20Adapter: OCPPAuthAdapter beforeEach(() => { - mockStation = { - logPrefix: () => '[TEST-CS-001]', - stationInfo: { - chargingStationId: 'TEST-CS-001', - ocppVersion: OCPPVersion.VERSION_201, - }, - } as unknown as ChargingStation + mockStation = createMockAuthServiceTestStation('001', OCPPVersion.VERSION_201) mockOCPP20Adapter = createMockOCPPAdapter(OCPPVersion.VERSION_201, { authorizeRemote: () => -- 2.43.0