- Refactor OCPPAuthServiceImpl.test.ts: declare mocks at describe level, initialize in beforeEach()
- Refactor OCPPAuthServiceFactory.test.ts: same pattern for consistency
- Refactor InMemoryAuthCache.test.ts: move common mockResult to beforeEach()
Aligns with TEST_STYLE_GUIDE.md recommendation for test isolation pattern.
import { expect } from '@std/expect'
import { afterEach, beforeEach, describe, it, mock } from 'node:test'
+import type { AuthorizationResult } from '../../../../../src/charging-station/ocpp/auth/types/AuthTypes.js'
+
import { InMemoryAuthCache } from '../../../../../src/charging-station/ocpp/auth/cache/InMemoryAuthCache.js'
import {
AuthenticationMethod,
})
await describe('G03.FR.01.001 - Cache Hit Behavior', async () => {
- await it('should return cached result on cache hit', async () => {
- const identifier = 'test-token-001'
- const mockResult = createMockAuthorizationResult({
+ let mockResult: AuthorizationResult
+
+ beforeEach(() => {
+ mockResult = createMockAuthorizationResult({
status: AuthorizationStatus.ACCEPTED,
})
+ })
+
+ await it('should return cached result on cache hit', async () => {
+ const identifier = 'test-token-001'
// Cache the result
await cache.set(identifier, mockResult, 60)
await it('should track cache hits in statistics', async () => {
const identifier = 'test-token-002'
- const mockResult = createMockAuthorizationResult()
await cache.set(identifier, mockResult)
await cache.get(identifier)
maxEntries: 3,
rateLimit: { enabled: false },
})
- const mockResult = createMockAuthorizationResult()
// Fill cache to capacity
await lruCache.set('token-1', mockResult)
})
await describe('G03.FR.01.002 - Cache Miss Behavior', async () => {
+ let mockResult: AuthorizationResult
+
+ beforeEach(() => {
+ mockResult = createMockAuthorizationResult()
+ })
+
await it('should return undefined on cache miss', async () => {
const result = await cache.get('non-existent-token')
})
await it('should calculate hit rate correctly with mixed hits/misses', async () => {
- const mockResult = createMockAuthorizationResult()
-
// 2 sets
await cache.set('token-1', mockResult)
await cache.set('token-2', mockResult)
})
await describe('G03.FR.01.003 - Cache Expiration (TTL)', async () => {
+ let mockResult: AuthorizationResult
+
+ beforeEach(() => {
+ mockResult = createMockAuthorizationResult()
+ })
+
await it('should expire entries after TTL', async () => {
const identifier = 'expiring-token'
- const mockResult = createMockAuthorizationResult()
// Set with 1ms TTL (will expire immediately)
await cache.set(identifier, mockResult, 0.001)
})
await it('should track expired entries in statistics', async () => {
- const mockResult = createMockAuthorizationResult()
-
// Set with very short TTL
await cache.set('token-1', mockResult, 0.001)
await cache.set('token-2', mockResult, 0.001)
defaultTtl: 0.001, // 1ms default
})
- const mockResult = createMockAuthorizationResult()
await cacheWithShortTTL.set('token', mockResult) // No TTL specified
// Wait for expiration
await it('should not expire entries before TTL', async () => {
const identifier = 'long-lived-token'
- const mockResult = createMockAuthorizationResult()
// Set with 60 second TTL
await cache.set(identifier, mockResult, 60)
})
await describe('G03.FR.01.004 - Cache Invalidation', async () => {
+ let mockResult: AuthorizationResult
+
+ beforeEach(() => {
+ mockResult = createMockAuthorizationResult()
+ })
+
await it('should remove entry on invalidation', async () => {
const identifier = 'token-to-remove'
- const mockResult = createMockAuthorizationResult()
await cache.set(identifier, mockResult)
})
await it('should clear all entries', async () => {
- const mockResult = createMockAuthorizationResult()
-
await cache.set('token-1', mockResult)
await cache.set('token-2', mockResult)
await cache.set('token-3', mockResult)
})
await it('should reset statistics on clear', async () => {
- const mockResult = createMockAuthorizationResult()
-
await cache.set('token', mockResult)
await cache.get('token')
await cache.get('miss')
})
await describe('G03.FR.01.005 - Rate Limiting (Security)', async () => {
+ let mockResult: AuthorizationResult
+
+ beforeEach(() => {
+ mockResult = createMockAuthorizationResult()
+ })
+
await it('should block requests exceeding rate limit', async () => {
const identifier = 'rate-limited-token'
- const mockResult = createMockAuthorizationResult()
// Make 3 requests (at limit)
await cache.set(identifier, mockResult)
await it('should track rate limit statistics', async () => {
const identifier = 'token'
- const mockResult = createMockAuthorizationResult()
// Exceed rate limit
await cache.set(identifier, mockResult)
await it('should reset rate limit after window expires', async () => {
const identifier = 'windowed-token'
- const mockResult = createMockAuthorizationResult()
// Fill rate limit
await cache.set(identifier, mockResult)
})
await it('should rate limit per identifier independently', async () => {
- const mockResult = createMockAuthorizationResult()
-
// Fill rate limit for token-1
await cache.set('token-1', mockResult)
await cache.get('token-1')
rateLimit: { enabled: false },
})
- const mockResult = createMockAuthorizationResult()
-
// Make many requests without blocking
for (let i = 0; i < 20; i++) {
await unratedCache.set('token', mockResult)
})
await describe('G03.FR.01.006 - LRU Eviction', async () => {
- await it('should evict least recently used entry when full', async () => {
- const mockResult = createMockAuthorizationResult()
+ let mockResult: AuthorizationResult
+ beforeEach(() => {
+ mockResult = createMockAuthorizationResult()
+ })
+
+ await it('should evict least recently used entry when full', async () => {
// Fill cache to capacity (5 entries)
await cache.set('token-1', mockResult)
await cache.set('token-2', mockResult)
})
await it('should track eviction count in statistics', async () => {
- const mockResult = createMockAuthorizationResult()
-
// Trigger multiple evictions
for (let i = 1; i <= 10; i++) {
await cache.set(`token-${String(i)}`, mockResult)
})
await describe('G03.FR.01.007 - Statistics & Monitoring', async () => {
- await it('should provide accurate cache statistics', async () => {
- const mockResult = createMockAuthorizationResult()
+ let mockResult: AuthorizationResult
+
+ beforeEach(() => {
+ mockResult = createMockAuthorizationResult()
+ })
+ await it('should provide accurate cache statistics', async () => {
await cache.set('token-1', mockResult)
await cache.set('token-2', mockResult)
await cache.get('token-1') // hit
})
await it('should track memory usage estimate', async () => {
- const mockResult = createMockAuthorizationResult()
-
const statsBefore = await cache.getStats()
const memoryBefore = statsBefore.memoryUsage
})
await it('should provide rate limit statistics', async () => {
- const mockResult = createMockAuthorizationResult()
-
// Make some rate-limited requests
await cache.set('token', mockResult)
await cache.set('token', mockResult)
})
await describe('G03.FR.01.008 - Edge Cases', async () => {
- await it('should handle empty identifier gracefully', async () => {
- const mockResult = createMockAuthorizationResult()
+ let mockResult: AuthorizationResult
+ beforeEach(() => {
+ mockResult = createMockAuthorizationResult()
+ })
+
+ await it('should handle empty identifier gracefully', async () => {
await cache.set('', mockResult)
const result = await cache.get('')
await it('should handle very long identifier strings', async () => {
const longIdentifier = 'x'.repeat(1000)
- const mockResult = createMockAuthorizationResult()
await cache.set(longIdentifier, mockResult)
const result = await cache.get(longIdentifier)
})
await it('should handle concurrent operations', async () => {
- const mockResult = createMockAuthorizationResult()
-
// Concurrent sets
await Promise.all([
cache.set('token-1', mockResult),
})
await it('should handle zero TTL (immediate expiration)', async () => {
- const mockResult = createMockAuthorizationResult()
-
await cache.set('token', mockResult, 0)
// Should be immediately expired
})
await it('should handle very large TTL values', async () => {
- const mockResult = createMockAuthorizationResult()
-
// 1 year TTL
await cache.set('token', mockResult, 31536000)
* @description Unit tests for OCPP authentication service factory
*/
import { expect } from '@std/expect'
-import { afterEach, describe, it } from 'node:test'
+import { afterEach, beforeEach, describe, it } from 'node:test'
import type { ChargingStation } from '../../../../../src/charging-station/ChargingStation.js'
})
await describe('getInstance', async () => {
- await it('should create a new instance for a charging station', async () => {
- const mockStation = createMockAuthServiceTestStation('001')
+ let mockStation16: ChargingStation
+ let mockStation20: ChargingStation
- const authService = await OCPPAuthServiceFactory.getInstance(mockStation)
+ beforeEach(() => {
+ mockStation16 = createMockAuthServiceTestStation('getInstance-16')
+ mockStation20 = createMockAuthServiceTestStation('getInstance-20', OCPPVersion.VERSION_20)
+ })
+
+ await it('should create a new instance for a charging station', async () => {
+ const authService = await OCPPAuthServiceFactory.getInstance(mockStation16)
expect(authService).toBeDefined()
expect(typeof authService.authorize).toBe('function')
})
await it('should return cached instance for same charging station', async () => {
- const mockStation = createMockAuthServiceTestStation('002', OCPPVersion.VERSION_20)
-
- const authService1 = await OCPPAuthServiceFactory.getInstance(mockStation)
- const authService2 = await OCPPAuthServiceFactory.getInstance(mockStation)
+ const authService1 = await OCPPAuthServiceFactory.getInstance(mockStation20)
+ const authService2 = await OCPPAuthServiceFactory.getInstance(mockStation20)
expect(authService1).toBe(authService2)
})
await it('should create different instances for different charging stations', async () => {
- const mockStation1 = createMockAuthServiceTestStation('003')
- const mockStation2 = createMockAuthServiceTestStation('004', OCPPVersion.VERSION_20)
-
- const authService1 = await OCPPAuthServiceFactory.getInstance(mockStation1)
- const authService2 = await OCPPAuthServiceFactory.getInstance(mockStation2)
+ const authService1 = await OCPPAuthServiceFactory.getInstance(mockStation16)
+ const authService2 = await OCPPAuthServiceFactory.getInstance(mockStation20)
expect(authService1).not.toBe(authService2)
})
})
await describe('createInstance', async () => {
- await it('should create a new uncached instance', async () => {
- const mockStation = createMockAuthServiceTestStation('005')
+ let mockStation16: ChargingStation
+ let mockStation20: ChargingStation
- const authService1 = await OCPPAuthServiceFactory.createInstance(mockStation)
- const authService2 = await OCPPAuthServiceFactory.createInstance(mockStation)
+ beforeEach(() => {
+ mockStation16 = createMockAuthServiceTestStation('createInstance-16')
+ mockStation20 = createMockAuthServiceTestStation('createInstance-20', OCPPVersion.VERSION_20)
+ })
+
+ await it('should create a new uncached instance', async () => {
+ const authService1 = await OCPPAuthServiceFactory.createInstance(mockStation16)
+ const authService2 = await OCPPAuthServiceFactory.createInstance(mockStation16)
expect(authService1).toBeDefined()
expect(authService2).toBeDefined()
})
await it('should not cache created instances', async () => {
- const mockStation = createMockAuthServiceTestStation('006', OCPPVersion.VERSION_20)
-
const initialCount = OCPPAuthServiceFactory.getCachedInstanceCount()
- await OCPPAuthServiceFactory.createInstance(mockStation)
+ await OCPPAuthServiceFactory.createInstance(mockStation20)
const finalCount = OCPPAuthServiceFactory.getCachedInstanceCount()
expect(finalCount).toBe(initialCount)
})
await describe('clearInstance', async () => {
- await it('should clear cached instance for a charging station', async () => {
- const mockStation = createMockAuthServiceTestStation('007')
+ let mockStation16: ChargingStation
+ let mockStation20: ChargingStation
+ beforeEach(() => {
+ mockStation16 = createMockAuthServiceTestStation('clearInstance-16')
+ mockStation20 = createMockAuthServiceTestStation('clearInstance-20', OCPPVersion.VERSION_20)
+ })
+
+ await it('should clear cached instance for a charging station', async () => {
// Create and cache instance
- const authService1 = await OCPPAuthServiceFactory.getInstance(mockStation)
+ const authService1 = await OCPPAuthServiceFactory.getInstance(mockStation16)
// Clear the cache
- OCPPAuthServiceFactory.clearInstance(mockStation)
+ OCPPAuthServiceFactory.clearInstance(mockStation16)
// Get instance again - should be a new instance
- const authService2 = await OCPPAuthServiceFactory.getInstance(mockStation)
+ const authService2 = await OCPPAuthServiceFactory.getInstance(mockStation16)
expect(authService1).not.toBe(authService2)
})
await it('should not throw when clearing non-existent instance', () => {
- const mockStation = createMockAuthServiceTestStation('008', OCPPVersion.VERSION_20)
-
expect(() => {
- OCPPAuthServiceFactory.clearInstance(mockStation)
+ OCPPAuthServiceFactory.clearInstance(mockStation20)
}).not.toThrow()
})
})
await describe('clearAllInstances', async () => {
- await it('should clear all cached instances', async () => {
- const mockStation1 = createMockAuthServiceTestStation('009')
- const mockStation2 = createMockAuthServiceTestStation('010', OCPPVersion.VERSION_20)
+ let mockStation16: ChargingStation
+ let mockStation20: ChargingStation
+ beforeEach(() => {
+ mockStation16 = createMockAuthServiceTestStation('clearAll-16')
+ mockStation20 = createMockAuthServiceTestStation('clearAll-20', OCPPVersion.VERSION_20)
+ })
+
+ await it('should clear all cached instances', async () => {
// Create multiple instances
- await OCPPAuthServiceFactory.getInstance(mockStation1)
- await OCPPAuthServiceFactory.getInstance(mockStation2)
+ await OCPPAuthServiceFactory.getInstance(mockStation16)
+ await OCPPAuthServiceFactory.getInstance(mockStation20)
// Clear all
OCPPAuthServiceFactory.clearAllInstances()
})
await describe('getCachedInstanceCount', async () => {
- await it('should return the number of cached instances', async () => {
- OCPPAuthServiceFactory.clearAllInstances()
+ let mockStation16: ChargingStation
+ let mockStation20: ChargingStation
- const mockStation1 = createMockAuthServiceTestStation('011')
- const mockStation2 = createMockAuthServiceTestStation('012', OCPPVersion.VERSION_20)
+ beforeEach(() => {
+ OCPPAuthServiceFactory.clearAllInstances()
+ mockStation16 = createMockAuthServiceTestStation('count-16')
+ mockStation20 = createMockAuthServiceTestStation('count-20', OCPPVersion.VERSION_20)
+ })
+ await it('should return the number of cached instances', async () => {
expect(OCPPAuthServiceFactory.getCachedInstanceCount()).toBe(0)
- await OCPPAuthServiceFactory.getInstance(mockStation1)
+ await OCPPAuthServiceFactory.getInstance(mockStation16)
expect(OCPPAuthServiceFactory.getCachedInstanceCount()).toBe(1)
- await OCPPAuthServiceFactory.getInstance(mockStation2)
+ await OCPPAuthServiceFactory.getInstance(mockStation20)
expect(OCPPAuthServiceFactory.getCachedInstanceCount()).toBe(2)
// Getting same instance should not increase count
- await OCPPAuthServiceFactory.getInstance(mockStation1)
+ await OCPPAuthServiceFactory.getInstance(mockStation16)
expect(OCPPAuthServiceFactory.getCachedInstanceCount()).toBe(2)
})
})
await describe('getStatistics', async () => {
- await it('should return factory statistics', async () => {
- OCPPAuthServiceFactory.clearAllInstances()
+ let mockStation16: ChargingStation
+ let mockStation20: ChargingStation
- const mockStation1 = createMockAuthServiceTestStation('013')
- const mockStation2 = createMockAuthServiceTestStation('014', OCPPVersion.VERSION_20)
+ beforeEach(() => {
+ OCPPAuthServiceFactory.clearAllInstances()
+ mockStation16 = createMockAuthServiceTestStation('stats-16')
+ mockStation20 = createMockAuthServiceTestStation('stats-20', OCPPVersion.VERSION_20)
+ })
- await OCPPAuthServiceFactory.getInstance(mockStation1)
- await OCPPAuthServiceFactory.getInstance(mockStation2)
+ await it('should return factory statistics', async () => {
+ await OCPPAuthServiceFactory.getInstance(mockStation16)
+ await OCPPAuthServiceFactory.getInstance(mockStation20)
const stats = OCPPAuthServiceFactory.getStatistics()
expect(stats).toBeDefined()
expect(stats.cachedInstances).toBe(2)
expect(stats.stationIds).toHaveLength(2)
- expect(stats.stationIds).toContain('TEST-CS-013')
- expect(stats.stationIds).toContain('TEST-CS-014')
+ expect(stats.stationIds).toContain('TEST-CS-stats-16')
+ expect(stats.stationIds).toContain('TEST-CS-stats-20')
})
await it('should return empty statistics when no instances cached', () => {
})
await describe('OCPP version handling', async () => {
- await it('should create service for OCPP 1.6 station', async () => {
- const mockStation = createMockAuthServiceTestStation('015')
+ let mockStation16: ChargingStation
+ let mockStation20: ChargingStation
- const authService = await OCPPAuthServiceFactory.getInstance(mockStation)
+ beforeEach(() => {
+ mockStation16 = createMockAuthServiceTestStation('version-16')
+ mockStation20 = createMockAuthServiceTestStation('version-20', OCPPVersion.VERSION_20)
+ })
+
+ await it('should create service for OCPP 1.6 station', async () => {
+ const authService = await OCPPAuthServiceFactory.getInstance(mockStation16)
expect(authService).toBeDefined()
expect(typeof authService.authorize).toBe('function')
})
await it('should create service for OCPP 2.0 station', async () => {
- const mockStation = createMockAuthServiceTestStation('016', OCPPVersion.VERSION_20)
-
- const authService = await OCPPAuthServiceFactory.getInstance(mockStation)
+ const authService = await OCPPAuthServiceFactory.getInstance(mockStation20)
expect(authService).toBeDefined()
expect(typeof authService.authorize).toBe('function')
})
await describe('memory management', async () => {
- await it('should properly manage instance lifecycle', async () => {
- OCPPAuthServiceFactory.clearAllInstances()
+ let mockStations: ChargingStation[]
- const mockStations = Array.from({ length: 5 }, (_, i) =>
+ beforeEach(() => {
+ OCPPAuthServiceFactory.clearAllInstances()
+ mockStations = Array.from({ length: 5 }, (_, i) =>
createMockAuthServiceTestStation(
- String(100 + i),
+ `memory-${String(i)}`,
i % 2 === 0 ? OCPPVersion.VERSION_16 : OCPPVersion.VERSION_20
)
)
+ })
+ await it('should properly manage instance lifecycle', async () => {
// Create instances
for (const station of mockStations) {
await OCPPAuthServiceFactory.getInstance(station)
* @description Unit tests for OCPP authentication service implementation
*/
import { expect } from '@std/expect'
-import { afterEach, describe, it } from 'node:test'
+import { afterEach, beforeEach, describe, it } from 'node:test'
+import type { ChargingStation } from '../../../../../src/charging-station/ChargingStation.js'
import type { OCPPAuthService } from '../../../../../src/charging-station/ocpp/auth/interfaces/OCPPAuthService.js'
import { OCPPAuthServiceImpl } from '../../../../../src/charging-station/ocpp/auth/services/OCPPAuthServiceImpl.js'
})
await describe('constructor', async () => {
- await it('should initialize with OCPP 1.6 charging station', () => {
- const mockStation = createMockAuthServiceTestStation('001')
+ let mockStation16: ChargingStation
+ let mockStation20: ChargingStation
- const authService: OCPPAuthService = new OCPPAuthServiceImpl(mockStation)
+ beforeEach(() => {
+ mockStation16 = createMockAuthServiceTestStation('constructor-16')
+ mockStation20 = createMockAuthServiceTestStation('constructor-20', OCPPVersion.VERSION_20)
+ })
+
+ await it('should initialize with OCPP 1.6 charging station', () => {
+ const authService: OCPPAuthService = new OCPPAuthServiceImpl(mockStation16)
expect(authService).toBeDefined()
expect(typeof authService.authorize).toBe('function')
})
await it('should initialize with OCPP 2.0 charging station', () => {
- const mockStation = createMockAuthServiceTestStation('002', OCPPVersion.VERSION_20)
-
- const authService = new OCPPAuthServiceImpl(mockStation)
+ const authService = new OCPPAuthServiceImpl(mockStation20)
expect(authService).toBeDefined()
})
})
await describe('getConfiguration', async () => {
- await it('should return default configuration', () => {
- const mockStation = createMockAuthServiceTestStation('003')
+ let mockStation: ChargingStation
+
+ beforeEach(() => {
+ mockStation = createMockAuthServiceTestStation('getConfig')
+ })
+ await it('should return default configuration', () => {
const authService = new OCPPAuthServiceImpl(mockStation)
const config = authService.getConfiguration()
})
await describe('updateConfiguration', async () => {
- await it('should update configuration', async () => {
- const mockStation = createMockAuthServiceTestStation('004')
+ let mockStation: ChargingStation
+
+ beforeEach(() => {
+ mockStation = createMockAuthServiceTestStation('updateConfig')
+ })
+ await it('should update configuration', async () => {
const authService = new OCPPAuthServiceImpl(mockStation)
await authService.updateConfiguration({
})
await describe('isSupported', async () => {
- await it('should check if identifier type is supported for OCPP 1.6', async () => {
- const mockStation = createMockAuthServiceTestStation('005')
+ let mockStation16: ChargingStation
+ let mockStation20: ChargingStation
- const authService = new OCPPAuthServiceImpl(mockStation)
+ beforeEach(() => {
+ mockStation16 = createMockAuthServiceTestStation('isSupported-16')
+ mockStation20 = createMockAuthServiceTestStation('isSupported-20', OCPPVersion.VERSION_20)
+ })
+
+ await it('should check if identifier type is supported for OCPP 1.6', async () => {
+ const authService = new OCPPAuthServiceImpl(mockStation16)
await authService.initialize()
const idTagIdentifier: UnifiedIdentifier = {
})
await it('should check if identifier type is supported for OCPP 2.0', async () => {
- const mockStation = createMockAuthServiceTestStation('006', OCPPVersion.VERSION_20)
-
- const authService = new OCPPAuthServiceImpl(mockStation)
+ const authService = new OCPPAuthServiceImpl(mockStation20)
await authService.initialize()
const centralIdentifier: UnifiedIdentifier = {
})
await describe('testConnectivity', async () => {
- await it('should test remote connectivity', async () => {
- const mockStation = createMockAuthServiceTestStation('007')
+ let mockStation: ChargingStation
+
+ beforeEach(() => {
+ mockStation = createMockAuthServiceTestStation('connectivity')
+ })
+ await it('should test remote connectivity', async () => {
const authService = new OCPPAuthServiceImpl(mockStation)
const isConnected = await authService.testConnectivity()
})
await describe('clearCache', async () => {
- await it('should clear authorization cache', async () => {
- const mockStation = createMockAuthServiceTestStation('008')
+ let mockStation: ChargingStation
+
+ beforeEach(() => {
+ mockStation = createMockAuthServiceTestStation('clearCache')
+ })
+ await it('should clear authorization cache', async () => {
const authService = new OCPPAuthServiceImpl(mockStation)
await expect(authService.clearCache()).resolves.toBeUndefined()
})
await describe('invalidateCache', async () => {
- await it('should invalidate cache for specific identifier', async () => {
- const mockStation = createMockAuthServiceTestStation('009')
+ let mockStation: ChargingStation
+
+ beforeEach(() => {
+ mockStation = createMockAuthServiceTestStation('invalidateCache')
+ })
+ await it('should invalidate cache for specific identifier', async () => {
const authService = new OCPPAuthServiceImpl(mockStation)
const identifier: UnifiedIdentifier = {
})
await describe('getStats', async () => {
- await it('should return authentication statistics', async () => {
- const mockStation = createMockAuthServiceTestStation('010')
+ let mockStation: ChargingStation
+
+ beforeEach(() => {
+ mockStation = createMockAuthServiceTestStation('getStats')
+ })
+ await it('should return authentication statistics', async () => {
const authService = new OCPPAuthServiceImpl(mockStation)
const stats = await authService.getStats()
})
await describe('authorize', async () => {
- await it('should authorize identifier using strategy chain', async () => {
- const mockStation = createMockAuthServiceTestStation('011')
+ let mockStation: ChargingStation
+ beforeEach(() => {
+ mockStation = createMockAuthServiceTestStation('authorize')
+ })
+
+ await it('should authorize identifier using strategy chain', async () => {
const authService = new OCPPAuthServiceImpl(mockStation)
const identifier: UnifiedIdentifier = {
})
await it('should return INVALID status when all strategies fail', async () => {
- const mockStation = createMockAuthServiceTestStation('012')
-
const authService = new OCPPAuthServiceImpl(mockStation)
const identifier: UnifiedIdentifier = {
})
await describe('isLocallyAuthorized', async () => {
- await it('should check local authorization', async () => {
- const mockStation = createMockAuthServiceTestStation('013')
+ let mockStation: ChargingStation
+
+ beforeEach(() => {
+ mockStation = createMockAuthServiceTestStation('localAuth')
+ })
+ await it('should check local authorization', async () => {
const authService = new OCPPAuthServiceImpl(mockStation)
const identifier: UnifiedIdentifier = {
})
await describe('OCPP version specific behavior', async () => {
- await it('should handle OCPP 1.6 specific identifiers', async () => {
- const mockStation = createMockAuthServiceTestStation('014')
+ let mockStation16: ChargingStation
+ let mockStation20: ChargingStation
- const authService = new OCPPAuthServiceImpl(mockStation)
+ beforeEach(() => {
+ mockStation16 = createMockAuthServiceTestStation('version-16')
+ mockStation20 = createMockAuthServiceTestStation('version-20', OCPPVersion.VERSION_20)
+ })
+
+ await it('should handle OCPP 1.6 specific identifiers', async () => {
+ const authService = new OCPPAuthServiceImpl(mockStation16)
const identifier: UnifiedIdentifier = {
ocppVersion: OCPPVersion.VERSION_16,
})
await it('should handle OCPP 2.0 specific identifiers', async () => {
- const mockStation = createMockAuthServiceTestStation('015', OCPPVersion.VERSION_20)
-
- const authService = new OCPPAuthServiceImpl(mockStation)
+ const authService = new OCPPAuthServiceImpl(mockStation20)
const identifier: UnifiedIdentifier = {
ocppVersion: OCPPVersion.VERSION_20,
})
await describe('error handling', async () => {
- await it('should handle invalid identifier gracefully', async () => {
- const mockStation = createMockAuthServiceTestStation('016')
+ let mockStation: ChargingStation
+ beforeEach(() => {
+ mockStation = createMockAuthServiceTestStation('errorHandling')
+ })
+
+ await it('should handle invalid identifier gracefully', async () => {
const authService = new OCPPAuthServiceImpl(mockStation)
const identifier: UnifiedIdentifier = {
})
await describe('authentication contexts', async () => {
- await it('should handle TRANSACTION_START context', async () => {
- const mockStation = createMockAuthServiceTestStation('017')
+ let mockStation16: ChargingStation
+ let mockStation20: ChargingStation
- const authService = new OCPPAuthServiceImpl(mockStation)
+ beforeEach(() => {
+ mockStation16 = createMockAuthServiceTestStation('context-16')
+ mockStation20 = createMockAuthServiceTestStation('context-20', OCPPVersion.VERSION_20)
+ })
+
+ await it('should handle TRANSACTION_START context', async () => {
+ const authService = new OCPPAuthServiceImpl(mockStation16)
const identifier: UnifiedIdentifier = {
ocppVersion: OCPPVersion.VERSION_16,
})
await it('should handle TRANSACTION_STOP context', async () => {
- const mockStation = createMockAuthServiceTestStation('018')
-
- const authService = new OCPPAuthServiceImpl(mockStation)
+ const authService = new OCPPAuthServiceImpl(mockStation16)
const identifier: UnifiedIdentifier = {
ocppVersion: OCPPVersion.VERSION_16,
})
await it('should handle REMOTE_START context', async () => {
- const mockStation = createMockAuthServiceTestStation('019', OCPPVersion.VERSION_20)
-
- const authService = new OCPPAuthServiceImpl(mockStation)
+ const authService = new OCPPAuthServiceImpl(mockStation20)
const identifier: UnifiedIdentifier = {
ocppVersion: OCPPVersion.VERSION_20,