// For validation edge cases, we need to manually create invalid states
// since the factory is designed to create valid configurations
const stationNoInfo = createChargingStation({ baseName })
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
- delete (stationNoInfo as any).stationInfo
+ stationNoInfo.stationInfo = undefined
expect(() => {
validateStationInfo(stationNoInfo)
}).toThrow(new BaseError('Missing charging station information'))
* @file Tests for OCPP20ServiceUtils TransactionEvent Offline
* @description Unit tests for OCPP 2.0 offline TransactionEvent queueing (E02)
*/
-/* eslint-disable @typescript-eslint/no-unsafe-member-access */
-/* eslint-disable @typescript-eslint/no-unsafe-assignment */
-/* eslint-disable @typescript-eslint/no-unsafe-argument */
-/* eslint-disable @typescript-eslint/no-unsafe-call */
-/* eslint-disable @typescript-eslint/no-explicit-any */
import { expect } from '@std/expect'
import { afterEach, beforeEach, describe, it, mock } from 'node:test'
+import type { ChargingStation } from '../../../../src/charging-station/ChargingStation.js'
import type { EmptyObject } from '../../../../src/types/index.js'
import { OCPP20ServiceUtils } from '../../../../src/charging-station/ocpp/2.0/OCPP20ServiceUtils.js'
OCPPVersion,
} from '../../../../src/types/index.js'
import { Constants, generateUUID } from '../../../../src/utils/index.js'
+import { standardCleanup } from '../../../../tests/helpers/TestLifecycleHelpers.js'
import { createChargingStation } from '../../../ChargingStationFactory.js'
import { TEST_CHARGING_STATION_BASE_NAME } from '../../ChargingStationTestConstants.js'
import { resetLimits } from './OCPP20TestUtils.js'
await describe('E02 - OCPP 2.0.1 Offline TransactionEvent Queueing', async () => {
- let mockChargingStation: any
+ let mockChargingStation: ChargingStation
let requestHandlerMock: ReturnType<typeof mock.fn>
- let sentRequests: any[]
+ interface SentRequest {
+ command: string
+ payload: Record<string, unknown>
+ }
+ let sentRequests: SentRequest[]
let isOnline: boolean
beforeEach(() => {
sentRequests = []
isOnline = true
- requestHandlerMock = mock.fn(async (_station: any, command: string, payload: any) => {
- sentRequests.push({ command, payload })
- return Promise.resolve({} as EmptyObject)
- })
+ requestHandlerMock = mock.fn(
+ async (_station: ChargingStation, command: string, payload: Record<string, unknown>) => {
+ sentRequests.push({ command, payload })
+ return Promise.resolve({} as EmptyObject)
+ }
+ )
mockChargingStation = createChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connector.transactionEventQueue = undefined
}
}
+ standardCleanup()
})
await describe('Queue formation when offline', async () => {
* @file Tests for OCPP20ServiceUtils TransactionEvent Periodic
* @description Unit tests for OCPP 2.0 periodic TransactionEvent at TxUpdatedInterval (E02)
*/
-/* eslint-disable @typescript-eslint/no-unsafe-member-access */
-/* eslint-disable @typescript-eslint/no-unsafe-assignment */
-/* eslint-disable @typescript-eslint/no-unsafe-argument */
-/* eslint-disable @typescript-eslint/no-unsafe-call */
-/* eslint-disable @typescript-eslint/no-explicit-any */
-/* eslint-disable @typescript-eslint/require-await */
-/* eslint-disable @typescript-eslint/no-unnecessary-condition */
import { expect } from '@std/expect'
import { afterEach, beforeEach, describe, it, mock } from 'node:test'
+import type { ChargingStation } from '../../../../src/charging-station/ChargingStation.js'
import type { EmptyObject } from '../../../../src/types/index.js'
import { OCPP20ServiceUtils } from '../../../../src/charging-station/ocpp/2.0/OCPP20ServiceUtils.js'
OCPPVersion,
} from '../../../../src/types/index.js'
import { Constants, generateUUID } from '../../../../src/utils/index.js'
+import { standardCleanup } from '../../../../tests/helpers/TestLifecycleHelpers.js'
import { createChargingStation } from '../../../ChargingStationFactory.js'
import { TEST_CHARGING_STATION_BASE_NAME } from '../../ChargingStationTestConstants.js'
import { resetLimits } from './OCPP20TestUtils.js'
await describe('E02 - OCPP 2.0.1 Periodic TransactionEvent at TxUpdatedInterval', async () => {
- let mockChargingStation: any
+ let mockChargingStation: ChargingStation
let requestHandlerMock: ReturnType<typeof mock.fn>
- let sentRequests: any[]
+ interface SentRequest {
+ command: string
+ payload: Record<string, unknown>
+ }
+ let sentRequests: SentRequest[]
beforeEach(() => {
sentRequests = []
- requestHandlerMock = mock.fn(async (_station: any, command: string, payload: any) => {
- sentRequests.push({ command, payload })
- return Promise.resolve({} as EmptyObject)
- })
+ requestHandlerMock = mock.fn(
+ async (_station: ChargingStation, command: string, payload: Record<string, unknown>) => {
+ sentRequests.push({ command, payload })
+ return Promise.resolve({} as EmptyObject)
+ }
+ )
mockChargingStation = createChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
const connector = mockChargingStation.getConnectorStatus(connectorId)
if (connector?.transactionTxUpdatedSetInterval != null) {
clearInterval(connector.transactionTxUpdatedSetInterval)
- delete connector.transactionTxUpdatedSetInterval
+ connector.transactionTxUpdatedSetInterval = undefined
}
}
+ standardCleanup()
})
await describe('startTxUpdatedInterval', async () => {
})
// Call startTxUpdatedInterval on OCPP 1.6 station
- ocpp16Station.startTxUpdatedInterval?.(1, 60000)
+ ocpp16Station.startTxUpdatedInterval(1, 60000)
// Verify no timer was started (method should return early)
const connector = ocpp16Station.getConnectorStatus(1)
)
})
- await it('should increment seqNo for each periodic event', async () => {
+ await it('should increment seqNo for each periodic event', () => {
const connectorId = 1
const transactionId = generateUUID()
})
await describe('Timer lifecycle integration', async () => {
- await it('should continue seqNo sequence across multiple periodic events', async () => {
+ await it('should continue seqNo sequence across multiple periodic events', () => {
const connectorId = 1
const transactionId = generateUUID()
expect(endEvent.seqNo).toBe(4)
})
- await it('should handle multiple connectors with independent timers', async () => {
+ await it('should handle multiple connectors with independent timers', () => {
const transactionId1 = generateUUID()
const transactionId2 = generateUUID()
transactionId
)
throw new Error('Should have thrown network error')
- } catch (error: any) {
- expect(error.message).toContain('Network timeout')
+ } catch (error) {
+ expect((error as Error).message).toContain('Network timeout')
}
})
})
* @file Tests for OCPP20ServiceUtils TransactionEvent
* @description Unit tests for OCPP 2.0 TransactionEvent building and trigger reasons (E01-E04)
*/
-/* eslint-disable @typescript-eslint/no-unsafe-member-access */
-/* eslint-disable @typescript-eslint/no-unsafe-assignment */
-
-/* eslint-disable @typescript-eslint/no-explicit-any */
import { expect } from '@std/expect'
-import { afterEach, describe, it } from 'node:test'
+import { afterEach, beforeEach, describe, it } from 'node:test'
import { OCPP20ServiceUtils } from '../../../../src/charging-station/ocpp/2.0/OCPP20ServiceUtils.js'
import {
import { createMockOCPP20TransactionTestStation, resetLimits } from './OCPP20TestUtils.js'
await describe('E01-E04 - OCPP 2.0.1 TransactionEvent Implementation', async () => {
- const mockChargingStation = createMockOCPP20TransactionTestStation()
+ let mockChargingStation: ReturnType<typeof createMockOCPP20TransactionTestStation>
- // Reset limits before tests
- resetLimits(mockChargingStation)
+ beforeEach(() => {
+ mockChargingStation = createMockOCPP20TransactionTestStation()
+ resetLimits(mockChargingStation)
+ })
// Reset singleton state and timers after each test to ensure test isolation
afterEach(() => {
invalidTransactionId
)
throw new Error('Should have thrown error for invalid identifier string')
- } catch (error: any) {
- expect(error.message).toContain('Invalid transaction ID format')
+ } catch (error) {
+ expect((error as Error).message).toContain('Invalid transaction ID format')
expect(error.message).toContain('≤36 characters')
}
})
transactionId
)
throw new Error('Should have thrown error')
- } catch (error: any) {
- expect(error.message).toContain('Network error')
+ } catch (error) {
+ expect((error as Error).message).toContain('Network error')
}
})
})
]
for (const field of requiredFields) {
expect(transactionEvent).toHaveProperty(field)
- expect((transactionEvent as any)[field]).toBeDefined()
+ expect(transactionEvent[field as keyof typeof transactionEvent]).toBeDefined()
}
// Validate field types match schema requirements
await it('should fallback to Trigger for unknown context source', () => {
const context: OCPP20TransactionContext = {
- source: 'unknown_source' as any, // Invalid source to test fallback
+ source: 'unknown_source' as OCPP20TransactionContext['source'], // Invalid source to test fallback
}
const triggerReason = OCPP20ServiceUtils.selectTriggerReason(
transactionId
)
throw new Error('Should have thrown error')
- } catch (error: any) {
- expect(error.message).toContain('Context test error')
+ } catch (error) {
+ expect((error as Error).message).toContain('Context test error')
}
})
})