type Reservation,
} from '../../src/types/index.js'
import { logger } from '../../src/utils/Logger.js'
-import { createMockChargingStation, createMockChargingStationTemplate } from './ChargingStationTestUtils.js'
import { standardCleanup } from '../helpers/TestLifecycleHelpers.js'
+import { createMockChargingStation, createMockChargingStationTemplate } from './ChargingStationTestUtils.js'
await describe('Helpers test suite', async () => {
const baseName = 'CS-TEST'
webSocket: mockWebSocket,
}
+ const typedStation: ChargingStation = station as unknown as ChargingStation
+
return {
mocks,
- station: station as unknown as ChargingStation,
+ station: typedStation,
}
}
+/**
+ * Create a mock charging station template for testing
+ * @param baseName - Base name for the template
+ * @returns ChargingStationTemplate with minimal required properties for testing
+ */
+export function createMockChargingStationTemplate (
+ baseName: string = TEST_CHARGING_STATION_BASE_NAME
+): ChargingStationTemplate {
+ return {
+ baseName,
+ } as ChargingStationTemplate
+}
+
/**
* Reset a ChargingStation to its initial state
*
status.transactionSetInterval = undefined
}
}
-
-/**
- * Create a mock charging station template for testing
- * @param baseName - Base name for the template
- * @returns ChargingStationTemplate with minimal required properties for testing
- */
-export function createMockChargingStationTemplate (
- baseName: string = TEST_CHARGING_STATION_BASE_NAME
-): ChargingStationTemplate {
- return {
- baseName,
- } as ChargingStationTemplate
-}
OCPPVersion,
} from '../../../../src/types/index.js'
import { Constants } from '../../../../src/utils/index.js'
-import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import { TEST_CHARGING_STATION_BASE_NAME } from '../../ChargingStationTestConstants.js'
+import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
const VALID_PEM_CERTIFICATE = `-----BEGIN CERTIFICATE-----
MIIBkTCB+wIJAKHBfpvPA0GXMA0GCSqGSIb3DQEBCwUAMBExDzANBgNVBAMMBnRl
validateCertificateFormat: Mock<(cert: string) => boolean>
}
-/**
- * Test-specific ChargingStation interface with certificate management
- * Extends ChargingStation with properties needed for certificate tests
- */
-interface TestableChargingStationWithCertificate extends ChargingStation {
- certificateManager?: MockCertificateManager
- closeWSConnection?: Mock<() => void>
-}
-
const createMockCertificateManager = (
options: {
storeCertificateError?: Error
import { expect } from '@std/expect'
import { afterEach, beforeEach, describe, it, mock } from 'node:test'
+import type { ChargingStation } from '../../../../src/charging-station/index.js'
+
import { createTestableIncomingRequestService } from '../../../../src/charging-station/ocpp/2.0/__testable__/index.js'
import { OCPP20IncomingRequestService } from '../../../../src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.js'
import { OCPPAuthServiceFactory } from '../../../../src/charging-station/ocpp/auth/services/OCPPAuthServiceFactory.js'
import { GenericStatus, OCPPVersion } from '../../../../src/types/index.js'
import { Constants } from '../../../../src/utils/index.js'
-import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import { TEST_CHARGING_STATION_BASE_NAME } from '../../ChargingStationTestConstants.js'
+import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
await describe('C11 - Clear Authorization Data in Authorization Cache', async () => {
afterEach(() => {
await it('should NOT call idTagsCache.deleteIdTags() on ClearCache request', async () => {
// Verify that IdTagsCache is not touched
let deleteIdTagsCalled = false
- const originalDeleteIdTags = station.idTagsCache.deleteIdTags.bind(
- station.idTagsCache
- )
+ const originalDeleteIdTags = station.idTagsCache.deleteIdTags.bind(station.idTagsCache)
Object.assign(station.idTagsCache, {
deleteIdTags: () => {
import { expect } from '@std/expect'
import { afterEach, beforeEach, describe, it, mock } from 'node:test'
+import type { ChargingStation } from '../../../../src/charging-station/index.js'
import type { ChargingStationWithCertificateManager } from '../../../../src/charging-station/ocpp/2.0/OCPP20CertificateManager.js'
import { createTestableIncomingRequestService } from '../../../../src/charging-station/ocpp/2.0/__testable__/index.js'
ReasonCodeEnumType,
} from '../../../../src/types/index.js'
import { Constants } from '../../../../src/utils/index.js'
-import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import { TEST_CHARGING_STATION_BASE_NAME } from '../../ChargingStationTestConstants.js'
+import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import { createStationWithCertificateManager } from './OCPP20TestUtils.js'
const VALID_CERTIFICATE_HASH_DATA = {
import { expect } from '@std/expect'
import { afterEach, beforeEach, describe, it } from 'node:test'
+import type { ChargingStation } from '../../../../src/charging-station/index.js'
+
import {
addConfigurationKey,
setConfigurationKeyValue,
import { StandardParametersKey } from '../../../../src/types/ocpp/Configuration.js'
import { Constants } from '../../../../src/utils/index.js'
import { standardCleanup } from '../../../../tests/helpers/TestLifecycleHelpers.js'
-import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import {
TEST_CHARGE_POINT_MODEL,
TEST_CHARGE_POINT_SERIAL_NUMBER,
TEST_CHARGING_STATION_BASE_NAME,
TEST_FIRMWARE_VERSION,
} from '../../ChargingStationTestConstants.js'
+import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
await describe('B07 - Get Base Report', async () => {
let station: ChargingStation
})
await it('should include registry variables with Actual attribute only for unsupported types', () => {
- const reportData = testableService.buildReportData(
- station,
- ReportBaseEnumType.FullInventory
- )
+ const reportData = testableService.buildReportData(station, ReportBaseEnumType.FullInventory)
const heartbeatEntry = reportData.find(
(item: ReportDataType) =>
item.variable.name === (OCPP20OptionalVariableName.HeartbeatInterval as string) &&
// FR: B08.FR.07
await it('should build correct report data for FullInventory with station info', () => {
- const reportData = testableService.buildReportData(
- station,
- ReportBaseEnumType.FullInventory
- )
+ const reportData = testableService.buildReportData(station, ReportBaseEnumType.FullInventory)
expect(Array.isArray(reportData)).toBe(true)
expect(reportData.length).toBeGreaterThan(0)
// FR: B08.FR.08
await it('should build correct report data for SummaryInventory', () => {
- const reportData = testableService.buildReportData(
- station,
- ReportBaseEnumType.SummaryInventory
- )
+ const reportData = testableService.buildReportData(station, ReportBaseEnumType.SummaryInventory)
expect(Array.isArray(reportData)).toBe(true)
expect(reportData.length).toBeGreaterThan(0)
// Use members exceeding 10 chars total; exclude removed RTC/Manual.
const longValue = 'Heartbeat,NTP,GPS,RealTimeClock,MobileNetwork,RadioTimeTransmitter'
// Set Actual (SequenceList). Should accept full value internally.
- const setResult: OCPP20SetVariableResultType[] = variableManager.setVariables(
- station,
- [
- {
- attributeType: AttributeEnumType.Actual,
- attributeValue: longValue,
- component: { name: OCPP20ComponentName.ClockCtrlr },
- variable: { name: OCPP20RequiredVariableName.TimeSource },
- },
- ]
- )
+ const setResult: OCPP20SetVariableResultType[] = variableManager.setVariables(station, [
+ {
+ attributeType: AttributeEnumType.Actual,
+ attributeValue: longValue,
+ component: { name: OCPP20ComponentName.ClockCtrlr },
+ variable: { name: OCPP20RequiredVariableName.TimeSource },
+ },
+ ])
expect(setResult[0].attributeStatus).toBe('Accepted')
// Build report; value should be truncated to length 10
- const reportData = testableService.buildReportData(
- station,
- ReportBaseEnumType.FullInventory
- )
+ const reportData = testableService.buildReportData(station, ReportBaseEnumType.FullInventory)
const timeSourceEntry = reportData.find(
(item: ReportDataType) =>
item.variable.name === (OCPP20RequiredVariableName.TimeSource as string) &&
import { expect } from '@std/expect'
import { afterEach, beforeEach, describe, it, mock } from 'node:test'
+import type { ChargingStation } from '../../../../src/charging-station/index.js'
import type { ChargingStationWithCertificateManager } from '../../../../src/charging-station/ocpp/2.0/OCPP20CertificateManager.js'
import { createTestableIncomingRequestService } from '../../../../src/charging-station/ocpp/2.0/__testable__/index.js'
OCPPVersion,
} from '../../../../src/types/index.js'
import { Constants } from '../../../../src/utils/index.js'
-import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import { TEST_CHARGING_STATION_BASE_NAME } from '../../ChargingStationTestConstants.js'
+import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import { createStationWithCertificateManager } from './OCPP20TestUtils.js'
const createMockCertificateHashData = (serialNumber = '123456789'): CertificateHashDataType => ({
await describe('Certificate Manager Missing', async () => {
await it('should return NotFound when certificate manager is not available', async () => {
- const stationWithoutCertManager = createChargingStation({
+ const { station: stationWithoutCertManager } = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 3,
evseConfiguration: { evsesCount: 3 },
import {
TEST_CHARGING_STATION_BASE_NAME,
TEST_CONNECTOR_ID_VALID_INSTANCE,
- } from '../../ChargingStationTestConstants.js'
+} from '../../ChargingStationTestConstants.js'
import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import {
resetLimits,
OCPPVersion,
} from '../../../../src/types/index.js'
import { Constants } from '../../../../src/utils/index.js'
-import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import { TEST_CHARGING_STATION_BASE_NAME } from '../../ChargingStationTestConstants.js'
+import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import { createStationWithCertificateManager } from './OCPP20TestUtils.js'
const VALID_PEM_CERTIFICATE = `-----BEGIN CERTIFICATE-----
mock.restoreAll()
})
- let station: ChargingStation
let mockChargingStation: ChargingStation
let stationWithCertManager: ChargingStationWithCertificateManager
let incomingRequestService: OCPP20IncomingRequestService
},
websocketPingInterval: Constants.DEFAULT_WEBSOCKET_PING_INTERVAL,
})
- station = initialStation
+ mockChargingStation = initialStation
mockChargingStation = initialStation
// Use factory function to create station with certificate manager
} from '../../../../src/types/ocpp/2.0/Transaction.js'
import { Constants } from '../../../../src/utils/index.js'
import { standardCleanup } from '../../../../tests/helpers/TestLifecycleHelpers.js'
-import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import { TEST_CHARGING_STATION_BASE_NAME } from '../../ChargingStationTestConstants.js'
+import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import { createMockAuthService } from '../auth/helpers/MockFactories.js'
import {
resetConnectorTransactionState,
} from '../../../../src/types/ocpp/2.0/Transaction.js'
import { Constants } from '../../../../src/utils/index.js'
import { standardCleanup } from '../../../../tests/helpers/TestLifecycleHelpers.js'
-import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import { TEST_CHARGING_STATION_BASE_NAME } from '../../ChargingStationTestConstants.js'
+import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import { createMockAuthService } from '../auth/helpers/MockFactories.js'
import {
resetConnectorTransactionState,
await it('should handle TransactionEvent request failure gracefully', async () => {
sentTransactionEvents = []
- const failingChargingStation = createChargingStation({
+ const { station: failingChargingStation } = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME + '-FAIL',
connectorsCount: 1,
evseConfiguration: { evsesCount: 1 },
ResetStatusEnumType,
} from '../../../../src/types/index.js'
import { Constants } from '../../../../src/utils/index.js'
-import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import { standardCleanup } from '../../../helpers/TestLifecycleHelpers.js'
import { TEST_CHARGING_STATION_BASE_NAME } from '../../ChargingStationTestConstants.js'
+import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
await describe('B11 & B12 - Reset', async () => {
let mockChargingStation: ChargingStation
getNumberOfRunningTransactions: () => number
reset: () => Promise<void>
}
- let mockStation: ReturnType<typeof createChargingStation> & {
- getNumberOfRunningTransactions: () => number
- reset: () => Promise<void>
- }
let incomingRequestService: OCPP20IncomingRequestService
let testableService: ReturnType<typeof createTestableIncomingRequestService>
}
const createTestStation = (): TestStation => {
- const station = createChargingStation({
+ const { station } = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 3,
evseConfiguration: { evsesCount: 3 },
import { afterEach, beforeEach, describe, it } from 'node:test'
import type { ChargingStation } from '../../../../src/charging-station/index.js'
+
import { createTestableIncomingRequestService } from '../../../../src/charging-station/ocpp/2.0/__testable__/index.js'
import { OCPP20IncomingRequestService } from '../../../../src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.js'
import { OCPP20VariableManager } from '../../../../src/charging-station/ocpp/2.0/OCPP20VariableManager.js'
} from '../../../../src/types/index.js'
import { Constants } from '../../../../src/utils/index.js'
import { standardCleanup } from '../../../../tests/helpers/TestLifecycleHelpers.js'
-import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import {
TEST_CHARGING_STATION_BASE_NAME,
TEST_CONNECTOR_ID_VALID_INSTANCE,
} from '../../ChargingStationTestConstants.js'
+import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import {
resetLimits,
resetValueSizeLimits,
import { expect } from '@std/expect'
import { afterEach, beforeEach, describe, it, mock } from 'node:test'
+import type { ChargingStation } from '../../../../src/charging-station/index.js'
+
import { OCPP20RequestService } from '../../../../src/charging-station/ocpp/2.0/OCPP20RequestService.js'
import { OCPP20ResponseService } from '../../../../src/charging-station/ocpp/2.0/OCPP20ResponseService.js'
import {
OCPP20RequestCommand,
OCPPVersion,
} from '../../../../src/types/index.js'
-import type { ChargingStation } from '../../../../src/charging-station/index.js'
import { type ChargingStationType } from '../../../../src/types/ocpp/2.0/Common.js'
import { Constants } from '../../../../src/utils/index.js'
-import { createMockChargingStation } from '../../../ChargingStationTestUtils.js'
import {
TEST_CHARGE_POINT_MODEL,
TEST_CHARGE_POINT_SERIAL_NUMBER,
TEST_CHARGING_STATION_BASE_NAME,
TEST_FIRMWARE_VERSION,
} from '../../ChargingStationTestConstants.js'
+import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import {
createTestableOCPP20RequestService,
type TestableOCPP20RequestService,
}
const payload = testableRequestService.buildRequestPayload(
- station,
+ station,
OCPP20RequestCommand.BOOT_NOTIFICATION,
requestParams
) as OCPP20BootNotificationRequest
import { expect } from '@std/expect'
import { afterEach, beforeEach, describe, it, mock } from 'node:test'
+import type { ChargingStation } from '../../../../src/charging-station/index.js'
+
import { OCPP20RequestService } from '../../../../src/charging-station/ocpp/2.0/OCPP20RequestService.js'
import { OCPP20ResponseService } from '../../../../src/charging-station/ocpp/2.0/OCPP20ResponseService.js'
import {
OCPPVersion,
} from '../../../../src/types/index.js'
import { Constants, has } from '../../../../src/utils/index.js'
-import { createMockChargingStation } from '../../../ChargingStationTestUtils.js'
-import type { ChargingStation } from '../../../../src/charging-station/index.js'
import {
TEST_CHARGE_POINT_MODEL,
TEST_CHARGE_POINT_SERIAL_NUMBER,
TEST_CHARGING_STATION_BASE_NAME,
TEST_FIRMWARE_VERSION,
} from '../../ChargingStationTestConstants.js'
+import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import {
createTestableOCPP20RequestService,
type TestableOCPP20RequestService,
// FR: G02.FR.05
await it('should handle HeartBeat request with different charging station configurations', () => {
- const alternativeChargingStation = createChargingStation({
+ const { station: alternativeChargingStation } = createMockChargingStation({
baseName: 'CS-ALTERNATIVE-002',
connectorsCount: 3,
evseConfiguration: { evsesCount: 3 },
})
await describe('M03 - GetCertificateStatus Request', async () => {
- let station: TestChargingStation
+ let station: ReturnType<typeof createMockChargingStation>['station']
beforeEach(() => {
- station = createChargingStation({
+ const result = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 3,
evseConfiguration: { evsesCount: 3 },
},
websocketPingInterval: Constants.DEFAULT_WEBSOCKET_PING_INTERVAL,
})
+ station = result.station
})
afterEach(() => {
})
await describe('Request Command Names', async () => {
- let station: TestChargingStation
+ let station: ReturnType<typeof createMockChargingStation>['station']
beforeEach(() => {
- station = createChargingStation({
+ const result = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 1,
evseConfiguration: { evsesCount: 1 },
},
websocketPingInterval: Constants.DEFAULT_WEBSOCKET_PING_INTERVAL,
})
+ station = result.station
})
afterEach(() => {
import { expect } from '@std/expect'
import { afterEach, beforeEach, describe, it, mock } from 'node:test'
+import type { ChargingStation } from '../../../../src/charging-station/index.js'
+
import {
createTestableRequestService,
type TestableOCPP20RequestService,
type ReportDataType,
} from '../../../../src/types/index.js'
import { Constants } from '../../../../src/utils/index.js'
-import { createMockChargingStation } from '../../../ChargingStationTestUtils.js'
-import type { ChargingStation } from '../../../../src/charging-station/index.js'
import {
TEST_CHARGE_POINT_MODEL,
TEST_CHARGE_POINT_SERIAL_NUMBER,
TEST_CHARGING_STATION_BASE_NAME,
TEST_FIRMWARE_VERSION,
} from '../../ChargingStationTestConstants.js'
+import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
await describe('B07/B08 - NotifyReport', async () => {
let testableService: TestableOCPP20RequestService
import { expect } from '@std/expect'
import { afterEach, beforeEach, describe, it, mock } from 'node:test'
+import type { ChargingStation } from '../../../../src/charging-station/index.js'
+
import { createTestableRequestService } from '../../../../src/charging-station/ocpp/2.0/__testable__/index.js'
import {
CertificateSigningUseEnumType,
OCPPVersion,
} from '../../../../src/types/index.js'
import { Constants } from '../../../../src/utils/index.js'
-import { createMockChargingStation } from '../../../ChargingStationTestUtils.js'
-import type { ChargingStation } from '../../../../src/charging-station/index.js'
import { TEST_CHARGING_STATION_BASE_NAME } from '../../ChargingStationTestConstants.js'
+import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
const MOCK_ORGANIZATION_NAME = 'Test Organization Inc.'
},
})
- await service.requestSignCertificate(
- station,
- CertificateSigningUseEnumType.V2GCertificate
- )
+ await service.requestSignCertificate(station, CertificateSigningUseEnumType.V2GCertificate)
const sentPayload = sendMessageMock.mock.calls[0].arguments[2] as OCPP20SignCertificateRequest
await describe('Error Handling', async () => {
await it('should generate CSR without certificate manager dependency', async () => {
- const stationWithoutCertManager = createChargingStation({
+ const { station: stationWithoutCertManager } = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 1,
evseConfiguration: { evsesCount: 1 },
import { expect } from '@std/expect'
import { afterEach, beforeEach, describe, it, mock } from 'node:test'
+import type { ChargingStation } from '../../../../src/charging-station/index.js'
+
import { OCPP20RequestService } from '../../../../src/charging-station/ocpp/2.0/OCPP20RequestService.js'
import { OCPP20ResponseService } from '../../../../src/charging-station/ocpp/2.0/OCPP20ResponseService.js'
import {
OCPPVersion,
} from '../../../../src/types/index.js'
import { Constants } from '../../../../src/utils/index.js'
-import { createMockChargingStation } from '../../../ChargingStationTestUtils.js'
-import type { ChargingStation } from '../../../../src/charging-station/index.js'
import {
TEST_FIRMWARE_VERSION,
TEST_STATUS_CHARGE_POINT_MODEL,
TEST_STATUS_CHARGE_POINT_VENDOR,
TEST_STATUS_CHARGING_STATION_BASE_NAME,
} from '../../ChargingStationTestConstants.js'
+import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import {
createTestableOCPP20RequestService,
type TestableOCPP20RequestService,
import { millisecondsToSeconds } from 'date-fns'
import { afterEach, beforeEach, describe, it } from 'node:test'
+import type { ChargingStation } from '../../../../src/charging-station/ChargingStation.js'
+
import {
deleteConfigurationKey,
getConfigurationKey,
} from '../../../../src/charging-station/ConfigurationKeyUtils.js'
-import type { ChargingStation } from '../../../../src/charging-station/ChargingStation.js'
import { createTestableVariableManager } from '../../../../src/charging-station/ocpp/2.0/__testable__/index.js'
import { OCPP20VariableManager } from '../../../../src/charging-station/ocpp/2.0/OCPP20VariableManager.js'
import { VARIABLE_REGISTRY } from '../../../../src/charging-station/ocpp/2.0/OCPP20VariableRegistry.js'
import { AuthComponentFactory } from '../../../../../src/charging-station/ocpp/auth/factories/AuthComponentFactory.js'
import { OCPPVersion } from '../../../../../src/types/ocpp/OCPPVersion.js'
-import { createMockChargingStation } from '../../../ChargingStationTestUtils.js'
import { standardCleanup } from '../../../../helpers/TestLifecycleHelpers.js'
+import { createMockChargingStation } from '../../../ChargingStationTestUtils.js'
await describe('AuthComponentFactory', async () => {
afterEach(() => {