waitForCondition,
} from './helpers/StationHelpers.js'
+export { createChargingStation, createChargingStationTemplate } from '../ChargingStationFactory.js'
+
export { MockIdTagsCache, MockSharedLRUCache } from './mocks/MockCaches.js'
// Re-export all mock classes
export { MockWebSocket, WebSocketReadyState } from './mocks/MockWebSocket.js'
setConfigurationKeyValue,
} from '../../src/charging-station/ConfigurationKeyUtils.js'
import { logger } from '../../src/utils/Logger.js'
-import { createChargingStation } from '../ChargingStationFactory.js'
+import { createChargingStation } from './ChargingStationTestUtils.js'
const TEST_KEY_1 = 'TestKey1'
const MIXED_CASE_KEY = 'MiXeDkEy'
type Reservation,
} from '../../src/types/index.js'
import { logger } from '../../src/utils/Logger.js'
-import { createChargingStation, createChargingStationTemplate } from '../ChargingStationFactory.js'
+import { createChargingStation, createChargingStationTemplate } from './ChargingStationTestUtils.js'
import { standardCleanup } from '../helpers/TestLifecycleHelpers.js'
await describe('Helpers test suite', async () => {
OCPPVersion,
} from '../../../../src/types/index.js'
import { Constants } from '../../../../src/utils/index.js'
-import { createChargingStation } from '../../../ChargingStationFactory.js'
+import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import { TEST_CHARGING_STATION_BASE_NAME } from '../../ChargingStationTestConstants.js'
const VALID_PEM_CERTIFICATE = `-----BEGIN CERTIFICATE-----
})
await describe('I04 - CertificateSigned', async () => {
- let mockChargingStation: TestableChargingStationWithCertificate
+ let station: ChargingStation
let incomingRequestService: OCPP20IncomingRequestService
let testableService: ReturnType<typeof createTestableIncomingRequestService>
beforeEach(() => {
- mockChargingStation = createChargingStation({
+ const { station: mockStation } = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 3,
evseConfiguration: { evsesCount: 3 },
ocppVersion: OCPPVersion.VERSION_201,
},
websocketPingInterval: Constants.DEFAULT_WEBSOCKET_PING_INTERVAL,
- }) as TestableChargingStationWithCertificate
- mockChargingStation.certificateManager = createMockCertificateManager()
- mockChargingStation.closeWSConnection = mock.fn()
+ })
+ station = mockStation
+ station.certificateManager = createMockCertificateManager()
+ station.closeWSConnection = mock.fn()
incomingRequestService = new OCPP20IncomingRequestService()
testableService = createTestableIncomingRequestService(incomingRequestService)
})
})
await describe('Valid Certificate Chain Installation', async () => {
await it('should accept valid certificate chain', async () => {
- mockChargingStation.certificateManager = createMockCertificateManager({
+ station.certificateManager = createMockCertificateManager({
storeCertificateResult: true,
})
}
const response: OCPP20CertificateSignedResponse =
- await testableService.handleRequestCertificateSigned(mockChargingStation, request)
+ await testableService.handleRequestCertificateSigned(station, request)
expect(response).toBeDefined()
expect(typeof response).toBe('object')
})
await it('should accept single certificate (no chain)', async () => {
- mockChargingStation.certificateManager = createMockCertificateManager({
+ station.certificateManager = createMockCertificateManager({
storeCertificateResult: true,
})
}
const response: OCPP20CertificateSignedResponse =
- await testableService.handleRequestCertificateSigned(mockChargingStation, request)
+ await testableService.handleRequestCertificateSigned(station, request)
expect(response).toBeDefined()
expect(response.status).toBe(GenericStatus.Accepted)
}
const response: OCPP20CertificateSignedResponse =
- await testableService.handleRequestCertificateSigned(mockChargingStation, request)
+ await testableService.handleRequestCertificateSigned(station, request)
expect(response).toBeDefined()
expect(response.status).toBe(GenericStatus.Rejected)
const mockCertManager = createMockCertificateManager({
storeCertificateResult: true,
})
- mockChargingStation.certificateManager = mockCertManager
+ station.certificateManager = mockCertManager
const mockCloseWSConnection = mock.fn()
- mockChargingStation.closeWSConnection = mockCloseWSConnection
+ station.closeWSConnection = mockCloseWSConnection
const request: OCPP20CertificateSignedRequest = {
certificateChain: VALID_PEM_CERTIFICATE,
}
const response: OCPP20CertificateSignedResponse =
- await testableService.handleRequestCertificateSigned(mockChargingStation, request)
+ await testableService.handleRequestCertificateSigned(station, request)
expect(response.status).toBe(GenericStatus.Accepted)
// Verify closeWSConnection was called to trigger reconnect
const mockCertManager = createMockCertificateManager({
storeCertificateResult: true,
})
- mockChargingStation.certificateManager = mockCertManager
+ station.certificateManager = mockCertManager
const mockCloseWSConnection = mock.fn()
- mockChargingStation.closeWSConnection = mockCloseWSConnection
+ station.closeWSConnection = mockCloseWSConnection
const request: OCPP20CertificateSignedRequest = {
certificateChain: VALID_PEM_CERTIFICATE,
}
const response: OCPP20CertificateSignedResponse =
- await testableService.handleRequestCertificateSigned(mockChargingStation, request)
+ await testableService.handleRequestCertificateSigned(station, request)
expect(response.status).toBe(GenericStatus.Accepted)
// Verify storeCertificate was called
await describe('Certificate Manager Missing', async () => {
await it('should return Rejected status with InternalError when certificate manager is missing', async () => {
// Create a separate mock charging station without certificateManager
- const stationWithoutCertManager = createChargingStation({
+ const { station: stationWithoutCertManager } = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 1,
evseConfiguration: { evsesCount: 1 },
ocppVersion: OCPPVersion.VERSION_201,
},
websocketPingInterval: Constants.DEFAULT_WEBSOCKET_PING_INTERVAL,
- }) as TestableChargingStationWithCertificate
+ })
// Ensure certificateManager is undefined (not present)
delete stationWithoutCertManager.certificateManager
await describe('Storage Failure Handling', async () => {
await it('should return Rejected status when storage fails', async () => {
- mockChargingStation.certificateManager = createMockCertificateManager({
+ station.certificateManager = createMockCertificateManager({
storeCertificateResult: false,
})
}
const response: OCPP20CertificateSignedResponse =
- await testableService.handleRequestCertificateSigned(mockChargingStation, request)
+ await testableService.handleRequestCertificateSigned(station, request)
expect(response).toBeDefined()
expect(response.status).toBe(GenericStatus.Rejected)
})
await it('should return Rejected status when storage throws error', async () => {
- mockChargingStation.certificateManager = createMockCertificateManager({
+ station.certificateManager = createMockCertificateManager({
storeCertificateError: new Error('Storage full'),
})
}
const response: OCPP20CertificateSignedResponse =
- await testableService.handleRequestCertificateSigned(mockChargingStation, request)
+ await testableService.handleRequestCertificateSigned(station, request)
expect(response).toBeDefined()
expect(response.status).toBe(GenericStatus.Rejected)
await describe('Response Structure Validation', async () => {
await it('should return response matching CertificateSignedResponse schema', async () => {
- mockChargingStation.certificateManager = createMockCertificateManager({
+ station.certificateManager = createMockCertificateManager({
storeCertificateResult: true,
})
}
const response: OCPP20CertificateSignedResponse =
- await testableService.handleRequestCertificateSigned(mockChargingStation, request)
+ await testableService.handleRequestCertificateSigned(station, request)
expect(response).toBeDefined()
expect(typeof response).toBe('object')
}
const response: OCPP20CertificateSignedResponse =
- await testableService.handleRequestCertificateSigned(mockChargingStation, request)
+ await testableService.handleRequestCertificateSigned(station, request)
expect(response.status).toBe(GenericStatus.Rejected)
expect(response.statusInfo).toBeDefined()
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 { createChargingStation } from '../../../ChargingStationFactory.js'
+import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import { TEST_CHARGING_STATION_BASE_NAME } from '../../ChargingStationTestConstants.js'
await describe('C11 - Clear Authorization Data in Authorization Cache', async () => {
mock.restoreAll()
})
- let mockChargingStation: ReturnType<typeof createChargingStation>
+ let station: ChargingStation
let incomingRequestService: OCPP20IncomingRequestService
let testableService: ReturnType<typeof createTestableIncomingRequestService>
beforeEach(() => {
- mockChargingStation = createChargingStation({
+ const { station: mockStation } = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 3,
evseConfiguration: { evsesCount: 3 },
},
websocketPingInterval: Constants.DEFAULT_WEBSOCKET_PING_INTERVAL,
})
+ station = mockStation
incomingRequestService = new OCPP20IncomingRequestService()
testableService = createTestableIncomingRequestService(incomingRequestService)
})
// FR: C11.FR.01 - CS SHALL attempt to clear its Authorization Cache
await it('should handle ClearCache request successfully', async () => {
- const response = await testableService.handleRequestClearCache(mockChargingStation)
+ const response = await testableService.handleRequestClearCache(station)
expect(response).toBeDefined()
expect(typeof response).toBe('object')
// FR: C11.FR.02 - Return correct status based on cache clearing result
await it('should return correct status based on cache clearing result', async () => {
- const response = await testableService.handleRequestClearCache(mockChargingStation)
+ const response = await testableService.handleRequestClearCache(station)
expect(response).toBeDefined()
expect(response.status).toBeDefined()
})
try {
- const response = await testableService.handleRequestClearCache(mockChargingStation)
+ const response = await testableService.handleRequestClearCache(station)
expect(clearCacheCalled).toBe(true)
expect(response.status).toBe(GenericStatus.Accepted)
await it('should NOT call idTagsCache.deleteIdTags() on ClearCache request', async () => {
// Verify that IdTagsCache is not touched
let deleteIdTagsCalled = false
- const originalDeleteIdTags = mockChargingStation.idTagsCache.deleteIdTags.bind(
- mockChargingStation.idTagsCache
+ const originalDeleteIdTags = station.idTagsCache.deleteIdTags.bind(
+ station.idTagsCache
)
- Object.assign(mockChargingStation.idTagsCache, {
+ Object.assign(station.idTagsCache, {
deleteIdTags: () => {
deleteIdTagsCalled = true
},
})
try {
- await testableService.handleRequestClearCache(mockChargingStation)
+ await testableService.handleRequestClearCache(station)
expect(deleteIdTagsCalled).toBe(false)
} finally {
// Restore original method
- Object.assign(mockChargingStation.idTagsCache, { deleteIdTags: originalDeleteIdTags })
+ Object.assign(station.idTagsCache, { deleteIdTags: originalDeleteIdTags })
}
})
})
})
try {
- const response = await testableService.handleRequestClearCache(mockChargingStation)
+ const response = await testableService.handleRequestClearCache(station)
expect(response.status).toBe(GenericStatus.Rejected)
} finally {
})
try {
- const response = await testableService.handleRequestClearCache(mockChargingStation)
+ const response = await testableService.handleRequestClearCache(station)
expect(response.status).toBe(GenericStatus.Accepted)
} finally {
})
try {
- const response = await testableService.handleRequestClearCache(mockChargingStation)
+ const response = await testableService.handleRequestClearCache(station)
expect(response.status).toBe(GenericStatus.Rejected)
} finally {
})
try {
- await testableService.handleRequestClearCache(mockChargingStation)
+ await testableService.handleRequestClearCache(station)
// clearCache should NOT be called when cache is disabled
expect(clearCacheAttempted).toBe(false)
})
try {
- const response = await testableService.handleRequestClearCache(mockChargingStation)
+ const response = await testableService.handleRequestClearCache(station)
// Per C11.FR.05: SHALL return Rejected if CS does not support Authorization Cache
expect(response.status).toBe(GenericStatus.Rejected)
ReasonCodeEnumType,
} from '../../../../src/types/index.js'
import { Constants } from '../../../../src/utils/index.js'
-import { createChargingStation } from '../../../ChargingStationFactory.js'
+import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import { TEST_CHARGING_STATION_BASE_NAME } from '../../ChargingStationTestConstants.js'
import { createStationWithCertificateManager } from './OCPP20TestUtils.js'
mock.restoreAll()
})
- let mockChargingStation: ReturnType<typeof createChargingStation>
+ let station: ChargingStation
let stationWithCertManager: ChargingStationWithCertificateManager
let incomingRequestService: OCPP20IncomingRequestService
let testableService: ReturnType<typeof createTestableIncomingRequestService>
beforeEach(() => {
- mockChargingStation = createChargingStation({
+ const { station: mockStation } = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 3,
evseConfiguration: { evsesCount: 3 },
},
websocketPingInterval: Constants.DEFAULT_WEBSOCKET_PING_INTERVAL,
})
+ station = mockStation
stationWithCertManager = createStationWithCertificateManager(
- mockChargingStation,
+ station,
createMockCertificateManager()
)
}
const response: OCPP20DeleteCertificateResponse =
- await testableService.handleRequestDeleteCertificate(mockChargingStation, request)
+ await testableService.handleRequestDeleteCertificate(station, request)
expect(response).toBeDefined()
expect(typeof response).toBe('object')
}
const response: OCPP20DeleteCertificateResponse =
- await testableService.handleRequestDeleteCertificate(mockChargingStation, request)
+ await testableService.handleRequestDeleteCertificate(station, request)
expect(response).toBeDefined()
expect(response.status).toBe(DeleteCertificateStatusEnumType.Accepted)
}
const response: OCPP20DeleteCertificateResponse =
- await testableService.handleRequestDeleteCertificate(mockChargingStation, request)
+ await testableService.handleRequestDeleteCertificate(station, request)
expect(response).toBeDefined()
expect(response.status).toBe(DeleteCertificateStatusEnumType.Accepted)
}
const response: OCPP20DeleteCertificateResponse =
- await testableService.handleRequestDeleteCertificate(mockChargingStation, request)
+ await testableService.handleRequestDeleteCertificate(station, request)
expect(response).toBeDefined()
expect(response.status).toBe(DeleteCertificateStatusEnumType.NotFound)
}
const response: OCPP20DeleteCertificateResponse =
- await testableService.handleRequestDeleteCertificate(mockChargingStation, request)
+ await testableService.handleRequestDeleteCertificate(station, request)
expect(response).toBeDefined()
expect(response.status).toBe(DeleteCertificateStatusEnumType.Failed)
})
await it('should return Failed with InternalError when certificateManager is missing', async () => {
- const stationWithoutCertManager = createChargingStation({
+ const { station: stationWithoutCertManager } = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 3,
evseConfiguration: { evsesCount: 3 },
}
const response: OCPP20DeleteCertificateResponse =
- await testableService.handleRequestDeleteCertificate(mockChargingStation, request)
+ await testableService.handleRequestDeleteCertificate(station, request)
expect(response).toBeDefined()
expect(typeof response).toBe('object')
}
const response: OCPP20DeleteCertificateResponse =
- await testableService.handleRequestDeleteCertificate(mockChargingStation, request)
+ await testableService.handleRequestDeleteCertificate(station, request)
expect(response.status).toBe(DeleteCertificateStatusEnumType.Failed)
expect(response.statusInfo).toBeDefined()
import { StandardParametersKey } from '../../../../src/types/ocpp/Configuration.js'
import { Constants } from '../../../../src/utils/index.js'
import { standardCleanup } from '../../../../tests/helpers/TestLifecycleHelpers.js'
-import { createChargingStation } from '../../../ChargingStationFactory.js'
+import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import {
TEST_CHARGE_POINT_MODEL,
TEST_CHARGE_POINT_SERIAL_NUMBER,
} from '../../ChargingStationTestConstants.js'
await describe('B07 - Get Base Report', async () => {
- let mockChargingStation: ReturnType<typeof createChargingStation>
+ let station: ChargingStation
let incomingRequestService: OCPP20IncomingRequestService
let testableService: ReturnType<typeof createTestableIncomingRequestService>
beforeEach(() => {
- mockChargingStation = createChargingStation({
+ const { station: mockStation } = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 3,
evseConfiguration: { evsesCount: 3 },
},
websocketPingInterval: Constants.DEFAULT_WEBSOCKET_PING_INTERVAL,
})
+ station = mockStation
incomingRequestService = new OCPP20IncomingRequestService()
requestId: 1,
}
- const response = testableService.handleRequestGetBaseReport(mockChargingStation, request)
+ const response = testableService.handleRequestGetBaseReport(station, request)
expect(response).toBeDefined()
expect(response.status).toBe(GenericDeviceModelStatusEnumType.Accepted)
requestId: 2,
}
- const response = testableService.handleRequestGetBaseReport(mockChargingStation, request)
+ const response = testableService.handleRequestGetBaseReport(station, request)
expect(response).toBeDefined()
expect(response.status).toBe(GenericDeviceModelStatusEnumType.Accepted)
await it('should include registry variables with Actual attribute only for unsupported types', () => {
const reportData = testableService.buildReportData(
- mockChargingStation,
+ station,
ReportBaseEnumType.FullInventory
)
const heartbeatEntry = reportData.find(
requestId: 3,
}
- const response = testableService.handleRequestGetBaseReport(mockChargingStation, request)
+ const response = testableService.handleRequestGetBaseReport(station, request)
expect(response).toBeDefined()
expect(response.status).toBe(GenericDeviceModelStatusEnumType.Accepted)
requestId: 4,
}
- const response = testableService.handleRequestGetBaseReport(mockChargingStation, request)
+ const response = testableService.handleRequestGetBaseReport(station, request)
expect(response).toBeDefined()
expect(response.status).toBe(GenericDeviceModelStatusEnumType.NotSupported)
requestId: 5,
}
- const response = testableService.handleRequestGetBaseReport(mockChargingStation, request)
+ const response = testableService.handleRequestGetBaseReport(station, request)
expect(response).toBeDefined()
expect(response.status).toBe(GenericDeviceModelStatusEnumType.Accepted)
// Test the buildReportData method indirectly by calling handleRequestGetBaseReport
// and checking if it returns Accepted status (which means data was built successfully)
- const response = testableService.handleRequestGetBaseReport(mockChargingStation, request)
+ const response = testableService.handleRequestGetBaseReport(station, request)
expect(response).toBeDefined()
expect(response.status).toBe(GenericDeviceModelStatusEnumType.Accepted)
// We can also test the buildReportData method directly if needed
const reportData = testableService.buildReportData(
- mockChargingStation,
+ station,
ReportBaseEnumType.ConfigurationInventory
)
// FR: B08.FR.07
await it('should build correct report data for FullInventory with station info', () => {
const reportData = testableService.buildReportData(
- mockChargingStation,
+ station,
ReportBaseEnumType.FullInventory
)
// FR: B08.FR.08
await it('should build correct report data for SummaryInventory', () => {
const reportData = testableService.buildReportData(
- mockChargingStation,
+ station,
ReportBaseEnumType.SummaryInventory
)
// Ensure ReportingValueSize is at a small value (default is Constants.OCPP_VALUE_ABSOLUTE_MAX_LENGTH). We will override configuration key if absent.
const reportingSizeKey = StandardParametersKey.ReportingValueSize
// Add or lower configuration key to 10 to force truncation
- addConfigurationKey(mockChargingStation, reportingSizeKey, '10', undefined, {
+ addConfigurationKey(station, reportingSizeKey, '10', undefined, {
overwrite: true,
})
- setConfigurationKeyValue(mockChargingStation, reportingSizeKey, '10')
+ setConfigurationKeyValue(station, reportingSizeKey, '10')
// Choose TimeSource (SequenceList) and construct an artificially long ordered list value > 10 chars
const variableManager = OCPP20VariableManager.getInstance()
const longValue = 'Heartbeat,NTP,GPS,RealTimeClock,MobileNetwork,RadioTimeTransmitter'
// Set Actual (SequenceList). Should accept full value internally.
const setResult: OCPP20SetVariableResultType[] = variableManager.setVariables(
- mockChargingStation,
+ station,
[
{
attributeType: AttributeEnumType.Actual,
// Build report; value should be truncated to length 10
const reportData = testableService.buildReportData(
- mockChargingStation,
+ station,
ReportBaseEnumType.FullInventory
)
const timeSourceEntry = reportData.find(
// FR: B08.FR.09
await it('should handle GetBaseReport with EVSE structure', () => {
- // The createChargingStation should create a station with EVSEs
- const stationWithEvses = createChargingStation({
+ // Create a station with EVSEs
+ const { station: stationWithEvses } = createMockChargingStation({
baseName: 'CS-EVSE-001',
connectorsCount: 3,
evseConfiguration: { evsesCount: 3 },
// FR: B08.FR.10
await it('should validate unsupported reportBase correctly', () => {
const reportData = testableService.buildReportData(
- mockChargingStation,
+ station,
'InvalidReportBase' as unknown as ReportBaseEnumType
)
OCPPVersion,
} from '../../../../src/types/index.js'
import { Constants } from '../../../../src/utils/index.js'
-import { createChargingStation } from '../../../ChargingStationFactory.js'
+import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import { TEST_CHARGING_STATION_BASE_NAME } from '../../ChargingStationTestConstants.js'
import { createStationWithCertificateManager } from './OCPP20TestUtils.js'
})
await describe('I04 - GetInstalledCertificateIds', async () => {
- let mockChargingStation: ReturnType<typeof createChargingStation>
+ let station: ChargingStation
let stationWithCertManager: ChargingStationWithCertificateManager
let incomingRequestService: OCPP20IncomingRequestService
let testableService: ReturnType<typeof createTestableIncomingRequestService>
beforeEach(() => {
- mockChargingStation = createChargingStation({
+ const { station: mockStation } = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 3,
evseConfiguration: { evsesCount: 3 },
},
websocketPingInterval: Constants.DEFAULT_WEBSOCKET_PING_INTERVAL,
})
+ station = mockStation
stationWithCertManager = createStationWithCertificateManager(
- mockChargingStation,
+ station,
createMockCertificateManager()
)
const request: OCPP20GetInstalledCertificateIdsRequest = {}
const response: OCPP20GetInstalledCertificateIdsResponse =
- await testableService.handleRequestGetInstalledCertificateIds(mockChargingStation, request)
+ await testableService.handleRequestGetInstalledCertificateIds(station, request)
expect(response).toBeDefined()
expect(response.status).toBe(GetInstalledCertificateStatusEnumType.Accepted)
}
const response: OCPP20GetInstalledCertificateIdsResponse =
- await testableService.handleRequestGetInstalledCertificateIds(mockChargingStation, request)
+ await testableService.handleRequestGetInstalledCertificateIds(station, request)
expect(response).toBeDefined()
expect(response.status).toBe(GetInstalledCertificateStatusEnumType.Accepted)
}
const response: OCPP20GetInstalledCertificateIdsResponse =
- await testableService.handleRequestGetInstalledCertificateIds(mockChargingStation, request)
+ await testableService.handleRequestGetInstalledCertificateIds(station, request)
expect(response).toBeDefined()
expect(response.status).toBe(GetInstalledCertificateStatusEnumType.Accepted)
const request: OCPP20GetInstalledCertificateIdsRequest = {}
const response: OCPP20GetInstalledCertificateIdsResponse =
- await testableService.handleRequestGetInstalledCertificateIds(mockChargingStation, request)
+ await testableService.handleRequestGetInstalledCertificateIds(station, request)
expect(response).toBeDefined()
// Per OCPP 2.0.1 spec: NotFound is returned when no certificates match the request
}
const response: OCPP20GetInstalledCertificateIdsResponse =
- await testableService.handleRequestGetInstalledCertificateIds(mockChargingStation, request)
+ await testableService.handleRequestGetInstalledCertificateIds(station, request)
expect(response).toBeDefined()
expect(response.status).toBe(GetInstalledCertificateStatusEnumType.NotFound)
const request: OCPP20GetInstalledCertificateIdsRequest = {}
const response: OCPP20GetInstalledCertificateIdsResponse =
- await testableService.handleRequestGetInstalledCertificateIds(mockChargingStation, request)
+ await testableService.handleRequestGetInstalledCertificateIds(station, request)
expect(response).toBeDefined()
expect(typeof response).toBe('object')
const request: OCPP20GetInstalledCertificateIdsRequest = {}
const response: OCPP20GetInstalledCertificateIdsResponse =
- await testableService.handleRequestGetInstalledCertificateIds(mockChargingStation, request)
+ await testableService.handleRequestGetInstalledCertificateIds(station, request)
expect(response.status).toBe(GetInstalledCertificateStatusEnumType.Accepted)
expect(response.certificateHashDataChain).toBeDefined()
} from '../../../../src/types/index.js'
import { Constants } from '../../../../src/utils/index.js'
import { standardCleanup } from '../../../../tests/helpers/TestLifecycleHelpers.js'
-import { createChargingStation } from '../../../ChargingStationFactory.js'
import {
TEST_CHARGING_STATION_BASE_NAME,
TEST_CONNECTOR_ID_VALID_INSTANCE,
-} from '../../ChargingStationTestConstants.js'
+ } from '../../ChargingStationTestConstants.js'
+import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import {
resetLimits,
resetReportingValueSize,
} from './OCPP20TestUtils.js'
await describe('B06 - Get Variables', async () => {
- let mockChargingStation: ReturnType<typeof createChargingStation>
+ let station: ReturnType<typeof createMockChargingStation>
let incomingRequestService: OCPP20IncomingRequestService
beforeEach(() => {
- mockChargingStation = createChargingStation({
+ const { station: newStation } = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 3,
evseConfiguration: { evsesCount: 3 },
},
websocketPingInterval: Constants.DEFAULT_WEBSOCKET_PING_INTERVAL,
})
+ station = newStation
incomingRequestService = new OCPP20IncomingRequestService()
})
],
}
- const response = incomingRequestService.handleRequestGetVariables(mockChargingStation, request)
+ const response = incomingRequestService.handleRequestGetVariables(station, request)
expect(response).toBeDefined()
expect(response.getVariableResult).toBeDefined()
],
}
- const response = incomingRequestService.handleRequestGetVariables(mockChargingStation, request)
+ const response = incomingRequestService.handleRequestGetVariables(station, request)
expect(response).toBeDefined()
expect(response.getVariableResult).toBeDefined()
],
}
- const response = incomingRequestService.handleRequestGetVariables(mockChargingStation, request)
+ const response = incomingRequestService.handleRequestGetVariables(station, request)
expect(response).toBeDefined()
expect(response.getVariableResult).toBeDefined()
// FR: B06.FR.04
await it('should reject AuthorizeRemoteStart under Connector component', () => {
- resetLimits(mockChargingStation)
- resetReportingValueSize(mockChargingStation)
+ resetLimits(station)
+ resetReportingValueSize(station)
const request: OCPP20GetVariablesRequest = {
getVariableData: [
{
},
],
}
- const response = incomingRequestService.handleRequestGetVariables(mockChargingStation, request)
+ const response = incomingRequestService.handleRequestGetVariables(station, request)
expect(response.getVariableResult).toHaveLength(1)
const result = response.getVariableResult[0]
expect(result.attributeStatus).toBe(GetVariableStatusEnumType.UnknownComponent)
},
],
}
- const response = incomingRequestService.handleRequestGetVariables(mockChargingStation, request)
+ const response = incomingRequestService.handleRequestGetVariables(station, request)
expect(response.getVariableResult).toHaveLength(1)
const result = response.getVariableResult[0]
expect(result.attributeStatus).toBe(GetVariableStatusEnumType.NotSupportedAttributeType)
await it('should truncate variable value based on ReportingValueSize', () => {
// Set size below actual value length to force truncation
- setReportingValueSize(mockChargingStation, 2)
+ setReportingValueSize(station, 2)
const request: OCPP20GetVariablesRequest = {
getVariableData: [
{
},
],
}
- const response = incomingRequestService.handleRequestGetVariables(mockChargingStation, request)
+ const response = incomingRequestService.handleRequestGetVariables(station, request)
const result = response.getVariableResult[0]
expect(result.attributeStatus).toBe(GetVariableStatusEnumType.Accepted)
expect(result.attributeValue?.length).toBe(2)
- resetReportingValueSize(mockChargingStation)
+ resetReportingValueSize(station)
})
await it('should allow ReportingValueSize retrieval from DeviceDataCtrlr', () => {
},
],
}
- const response = incomingRequestService.handleRequestGetVariables(mockChargingStation, request)
+ const response = incomingRequestService.handleRequestGetVariables(station, request)
const result = response.getVariableResult[0]
expect(result.attributeStatus).toBe(GetVariableStatusEnumType.Accepted)
expect(result.attributeValue).toBeDefined()
})
await it('should enforce ItemsPerMessage limit', () => {
- setStrictLimits(mockChargingStation, 1, 10000)
+ setStrictLimits(station, 1, 10000)
const request: OCPP20GetVariablesRequest = {
getVariableData: [
{
},
],
}
- const response = incomingRequestService.handleRequestGetVariables(mockChargingStation, request)
+ const response = incomingRequestService.handleRequestGetVariables(station, request)
expect(response.getVariableResult.length).toBe(2)
for (const r of response.getVariableResult) {
expect(r.attributeStatus).toBe(GetVariableStatusEnumType.Rejected)
expect(r.attributeStatusInfo?.reasonCode).toBeDefined()
}
- resetLimits(mockChargingStation)
+ resetLimits(station)
})
await it('should enforce BytesPerMessage limit (pre-calculation)', () => {
- setStrictLimits(mockChargingStation, 100, 10)
+ setStrictLimits(station, 100, 10)
const request: OCPP20GetVariablesRequest = {
getVariableData: [
{
},
],
}
- const response = incomingRequestService.handleRequestGetVariables(mockChargingStation, request)
+ const response = incomingRequestService.handleRequestGetVariables(station, request)
expect(response.getVariableResult.length).toBe(2)
response.getVariableResult.forEach(r => {
expect(r.attributeStatus).toBe(GetVariableStatusEnumType.Rejected)
expect(r.attributeStatusInfo?.reasonCode).toBe(ReasonCodeEnumType.TooLargeElement)
})
- resetLimits(mockChargingStation)
+ resetLimits(station)
})
await it('should enforce BytesPerMessage limit (post-calculation)', () => {
}
const preEstimate = Buffer.byteLength(JSON.stringify(request.getVariableData), 'utf8')
const limit = preEstimate + 5 // allow pre-check pass, fail post-check
- setStrictLimits(mockChargingStation, 100, limit)
- const response = incomingRequestService.handleRequestGetVariables(mockChargingStation, request)
+ setStrictLimits(station, 100, limit)
+ const response = incomingRequestService.handleRequestGetVariables(station, request)
const actualSize = Buffer.byteLength(JSON.stringify(response.getVariableResult), 'utf8')
expect(actualSize).toBeGreaterThan(limit)
expect(response.getVariableResult).toHaveLength(request.getVariableData.length)
expect(r.attributeStatus).toBe(GetVariableStatusEnumType.Rejected)
expect(r.attributeStatusInfo?.reasonCode).toBe(ReasonCodeEnumType.TooLargeElement)
})
- resetLimits(mockChargingStation)
+ resetLimits(station)
})
// Added tests for relocated components
},
],
}
- const response = incomingRequestService.handleRequestGetVariables(mockChargingStation, request)
+ const response = incomingRequestService.handleRequestGetVariables(station, request)
expect(response.getVariableResult).toHaveLength(1)
const result = response.getVariableResult[0]
expect(result.attributeStatus).toBe(GetVariableStatusEnumType.Accepted)
},
],
}
- const response = incomingRequestService.handleRequestGetVariables(mockChargingStation, request)
+ const response = incomingRequestService.handleRequestGetVariables(station, request)
expect(response.getVariableResult).toHaveLength(1)
const result = response.getVariableResult[0]
expect(result.attributeStatus).toBe(GetVariableStatusEnumType.Accepted)
},
],
}
- const response = incomingRequestService.handleRequestGetVariables(mockChargingStation, request)
+ const response = incomingRequestService.handleRequestGetVariables(station, request)
expect(response.getVariableResult).toHaveLength(1)
const result = response.getVariableResult[0]
expect(result.attributeStatus).toBe(GetVariableStatusEnumType.Accepted)
},
],
}
- const response = incomingRequestService.handleRequestGetVariables(mockChargingStation, request)
+ const response = incomingRequestService.handleRequestGetVariables(station, request)
expect(response.getVariableResult).toHaveLength(3)
const fileTransfer = response.getVariableResult[0]
expect(fileTransfer.attributeStatus).toBe(GetVariableStatusEnumType.Accepted)
},
],
}
- const response = incomingRequestService.handleRequestGetVariables(mockChargingStation, request)
+ const response = incomingRequestService.handleRequestGetVariables(station, request)
expect(response.getVariableResult).toHaveLength(3)
const txStarted = response.getVariableResult[0]
expect(txStarted.attributeStatus).toBe(GetVariableStatusEnumType.Accepted)
},
],
}
- const response = incomingRequestService.handleRequestGetVariables(mockChargingStation, request)
+ const response = incomingRequestService.handleRequestGetVariables(station, request)
expect(response.getVariableResult).toHaveLength(1)
const result = response.getVariableResult[0]
expect(result.attributeStatus).toBe(GetVariableStatusEnumType.NotSupportedAttributeType)
},
],
}
- const response = incomingRequestService.handleRequestGetVariables(mockChargingStation, request)
+ const response = incomingRequestService.handleRequestGetVariables(station, request)
expect(response.getVariableResult).toHaveLength(1)
const result = response.getVariableResult[0]
expect(result.attributeStatus).toBe(GetVariableStatusEnumType.UnknownVariable)
},
],
}
- const response = incomingRequestService.handleRequestGetVariables(mockChargingStation, request)
+ const response = incomingRequestService.handleRequestGetVariables(station, request)
expect(response.getVariableResult).toHaveLength(1)
const result = response.getVariableResult[0]
expect(result.attributeStatus).toBe(GetVariableStatusEnumType.Rejected)
},
],
}
- const response = incomingRequestService.handleRequestGetVariables(mockChargingStation, request)
+ const response = incomingRequestService.handleRequestGetVariables(station, request)
expect(response.getVariableResult).toHaveLength(2)
const minSet = response.getVariableResult[0]
const maxSet = response.getVariableResult[1]
},
],
}
- const response = incomingRequestService.handleRequestGetVariables(mockChargingStation, request)
+ const response = incomingRequestService.handleRequestGetVariables(station, request)
expect(response.getVariableResult).toHaveLength(1)
const result = response.getVariableResult[0]
expect(result.attributeStatus).toBe(GetVariableStatusEnumType.NotSupportedAttributeType)
},
],
}
- const response = incomingRequestService.handleRequestGetVariables(mockChargingStation, request)
+ const response = incomingRequestService.handleRequestGetVariables(station, request)
expect(response.getVariableResult).toHaveLength(1)
const result = response.getVariableResult[0]
expect(result.attributeStatus).toBe(GetVariableStatusEnumType.NotSupportedAttributeType)
await it('should apply ValueSize then ReportingValueSize sequential truncation', () => {
// First apply a smaller ValueSize (5) then a smaller ReportingValueSize (3)
- setValueSize(mockChargingStation, 5)
- setReportingValueSize(mockChargingStation, 3)
+ setValueSize(station, 5)
+ setReportingValueSize(station, 3)
const request: OCPP20GetVariablesRequest = {
getVariableData: [
{
},
],
}
- const response = incomingRequestService.handleRequestGetVariables(mockChargingStation, request)
+ const response = incomingRequestService.handleRequestGetVariables(station, request)
const result = response.getVariableResult[0]
expect(result.attributeStatus).toBe(GetVariableStatusEnumType.Accepted)
expect(result.attributeValue).toBeDefined()
expect(result.attributeValue?.length).toBeLessThanOrEqual(3)
- resetReportingValueSize(mockChargingStation)
+ resetReportingValueSize(station)
})
})
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 { createChargingStation } from '../../../ChargingStationFactory.js'
+import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import { TEST_CHARGING_STATION_BASE_NAME } from '../../ChargingStationTestConstants.js'
import { createStationWithCertificateManager } from './OCPP20TestUtils.js'
mock.restoreAll()
})
- let mockChargingStation: ReturnType<typeof createChargingStation>
+ let station: ChargingStation
+ let mockChargingStation: ChargingStation
let stationWithCertManager: ChargingStationWithCertificateManager
let incomingRequestService: OCPP20IncomingRequestService
let testableService: ReturnType<typeof createTestableIncomingRequestService>
beforeEach(() => {
- mockChargingStation = createChargingStation({
+ const { station: initialStation } = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 3,
evseConfiguration: { evsesCount: 3 },
},
websocketPingInterval: Constants.DEFAULT_WEBSOCKET_PING_INTERVAL,
})
+ station = initialStation
+ mockChargingStation = initialStation
// Use factory function to create station with certificate manager
stationWithCertManager = createStationWithCertificateManager(
import { expect } from '@std/expect'
import { afterEach, beforeEach, describe, it } from 'node:test'
+import type { ChargingStation } from '../../../../src/charging-station/index.js'
import type { OCPP20RequestStartTransactionRequest } from '../../../../src/types/index.js'
import type {
OCPP20ChargingProfileType,
} from '../../../../src/types/ocpp/2.0/Transaction.js'
import { Constants } from '../../../../src/utils/index.js'
import { standardCleanup } from '../../../../tests/helpers/TestLifecycleHelpers.js'
-import { createChargingStation } from '../../../ChargingStationFactory.js'
+import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import { TEST_CHARGING_STATION_BASE_NAME } from '../../ChargingStationTestConstants.js'
import { createMockAuthService } from '../auth/helpers/MockFactories.js'
import {
} from './OCPP20TestUtils.js'
await describe('F01 & F02 - Remote Start Transaction', async () => {
- let mockChargingStation: ReturnType<typeof createChargingStation>
+ let mockChargingStation: ChargingStation
let incomingRequestService: OCPP20IncomingRequestService
let testableService: ReturnType<typeof createTestableIncomingRequestService>
beforeEach(() => {
- mockChargingStation = createChargingStation({
+ const { station } = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 3,
evseConfiguration: { evsesCount: 3 },
},
websocketPingInterval: Constants.DEFAULT_WEBSOCKET_PING_INTERVAL,
})
+ mockChargingStation = station
incomingRequestService = new OCPP20IncomingRequestService()
testableService = createTestableIncomingRequestService(incomingRequestService)
const stationId = mockChargingStation.stationInfo?.chargingStationId ?? 'unknown'
// FR: F01.FR.17, F02.FR.05 - Verify remoteStartId and idToken are stored for later TransactionEvent
await it('should store remoteStartId and idToken in connector status for TransactionEvent', async () => {
- const spyChargingStation = createChargingStation({
+ const { station: spyChargingStation } = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 3,
evseConfiguration: { evsesCount: 3 },
import { expect } from '@std/expect'
import { afterEach, beforeEach, describe, it } from 'node:test'
+import type { ChargingStation } from '../../../../src/charging-station/index.js'
import type {
OCPP20RequestStartTransactionRequest,
OCPP20RequestStopTransactionRequest,
} from '../../../../src/types/ocpp/2.0/Transaction.js'
import { Constants } from '../../../../src/utils/index.js'
import { standardCleanup } from '../../../../tests/helpers/TestLifecycleHelpers.js'
-import { createChargingStation } from '../../../ChargingStationFactory.js'
+import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import { TEST_CHARGING_STATION_BASE_NAME } from '../../ChargingStationTestConstants.js'
import { createMockAuthService } from '../auth/helpers/MockFactories.js'
import {
await describe('F03 - Remote Stop Transaction', async () => {
let sentTransactionEvents: OCPP20TransactionEventRequest[] = []
- let mockChargingStation: ReturnType<typeof createChargingStation>
+ let mockChargingStation: ChargingStation
let incomingRequestService: OCPP20IncomingRequestService
let testableService: ReturnType<typeof createTestableIncomingRequestService>
beforeEach(() => {
sentTransactionEvents = []
- mockChargingStation = createChargingStation({
+ const { station } = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 3,
evseConfiguration: { evsesCount: 3 },
},
websocketPingInterval: Constants.DEFAULT_WEBSOCKET_PING_INTERVAL,
})
+ mockChargingStation = station
incomingRequestService = new OCPP20IncomingRequestService()
testableService = createTestableIncomingRequestService(incomingRequestService)
const stationId = mockChargingStation.stationInfo?.chargingStationId ?? 'unknown'
ResetStatusEnumType,
} from '../../../../src/types/index.js'
import { Constants } from '../../../../src/utils/index.js'
-import { createChargingStation } from '../../../ChargingStationFactory.js'
+import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import { standardCleanup } from '../../../helpers/TestLifecycleHelpers.js'
import { TEST_CHARGING_STATION_BASE_NAME } from '../../ChargingStationTestConstants.js'
await describe('B11 & B12 - Reset', async () => {
- let mockChargingStation: ReturnType<typeof createChargingStation>
+ let mockChargingStation: ChargingStation
+ let mockStation: ChargingStation & {
+ getNumberOfRunningTransactions: () => number
+ reset: () => Promise<void>
+ }
let mockStation: ReturnType<typeof createChargingStation> & {
getNumberOfRunningTransactions: () => number
reset: () => Promise<void>
beforeEach(() => {
mock.timers.enable({ apis: ['setInterval', 'setTimeout', 'setImmediate'] })
- mockChargingStation = createChargingStation({
+ const { station } = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 3,
evseConfiguration: { evsesCount: 3 },
},
websocketPingInterval: Constants.DEFAULT_WEBSOCKET_PING_INTERVAL,
})
+ mockChargingStation = station
// Add missing method to mock using interface extension pattern
interface MockChargingStation extends ChargingStation {
import { millisecondsToSeconds } from 'date-fns'
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 { createChargingStation } from '../../../ChargingStationFactory.js'
+import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import {
TEST_CHARGING_STATION_BASE_NAME,
TEST_CONNECTOR_ID_VALID_INSTANCE,
} from './OCPP20TestUtils.js'
await describe('B05 - Set Variables', async () => {
- let mockChargingStation: ReturnType<typeof createChargingStation>
+ let mockChargingStation: ChargingStation
let incomingRequestService: OCPP20IncomingRequestService
let testableService: ReturnType<typeof createTestableIncomingRequestService>
beforeEach(() => {
- mockChargingStation = createChargingStation({
+ const { station } = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 3,
evseConfiguration: { evsesCount: 3 },
},
websocketPingInterval: Constants.DEFAULT_WEBSOCKET_PING_INTERVAL,
})
+ mockChargingStation = station
incomingRequestService = new OCPP20IncomingRequestService()
testableService = createTestableIncomingRequestService(incomingRequestService)
})
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 { createChargingStation, type TestChargingStation } from '../../../ChargingStationFactory.js'
+import { createMockChargingStation } from '../../../ChargingStationTestUtils.js'
import {
TEST_CHARGE_POINT_MODEL,
TEST_CHARGE_POINT_SERIAL_NUMBER,
let mockResponseService: OCPP20ResponseService
let requestService: OCPP20RequestService
let testableRequestService: TestableOCPP20RequestService
- let mockChargingStation: TestChargingStation
+ let station: ChargingStation
beforeEach(() => {
mockResponseService = new OCPP20ResponseService()
requestService = new OCPP20RequestService(mockResponseService)
testableRequestService = createTestableOCPP20RequestService(requestService)
- mockChargingStation = createChargingStation({
+ const { station: createdStation } = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 3,
evseConfiguration: { evsesCount: 3 },
},
websocketPingInterval: Constants.DEFAULT_WEBSOCKET_PING_INTERVAL,
})
+ station = createdStation
})
afterEach(() => {
}
const payload = testableRequestService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.BOOT_NOTIFICATION,
requestParams
) as OCPP20BootNotificationRequest
}
const payload = testableRequestService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.BOOT_NOTIFICATION,
requestParams
) as OCPP20BootNotificationRequest
}
const payload = testableRequestService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.BOOT_NOTIFICATION,
requestParams
) as OCPP20BootNotificationRequest
}
const payload = testableRequestService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.BOOT_NOTIFICATION,
requestParams
) as OCPP20BootNotificationRequest
}
const payload = testableRequestService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.BOOT_NOTIFICATION,
requestParams
) as OCPP20BootNotificationRequest
OCPPVersion,
} from '../../../../src/types/index.js'
import { Constants, has } from '../../../../src/utils/index.js'
-import { createChargingStation, type TestChargingStation } from '../../../ChargingStationFactory.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,
let mockResponseService: OCPP20ResponseService
let requestService: OCPP20RequestService
let testableRequestService: TestableOCPP20RequestService
- let mockChargingStation: TestChargingStation
+ let station: ChargingStation
beforeEach(() => {
mockResponseService = new OCPP20ResponseService()
requestService = new OCPP20RequestService(mockResponseService)
testableRequestService = createTestableOCPP20RequestService(requestService)
- mockChargingStation = createChargingStation({
+ const { station: createdStation } = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 3,
evseConfiguration: { evsesCount: 3 },
},
websocketPingInterval: Constants.DEFAULT_WEBSOCKET_PING_INTERVAL,
})
+ station = createdStation
})
afterEach(() => {
const requestParams: OCPP20HeartbeatRequest = {}
const payload = testableRequestService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.HEARTBEAT,
requestParams
)
await it('should build HeartBeat request payload correctly without parameters', () => {
// Test without passing any request parameters
const payload = testableRequestService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.HEARTBEAT
)
const requestParams: OCPP20HeartbeatRequest = {}
const payload = testableRequestService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.HEARTBEAT,
requestParams
)
// Call buildRequestPayload multiple times to ensure consistency
const payload1 = testableRequestService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.HEARTBEAT,
requestParams
)
const payload2 = testableRequestService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.HEARTBEAT,
requestParams
)
const payload3 = testableRequestService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.HEARTBEAT
)
const requestParams: OCPP20HeartbeatRequest = {}
const payload = testableRequestService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.HEARTBEAT,
requestParams
)
ReasonCodeEnumType,
} from '../../../../src/types/index.js'
import { Constants } from '../../../../src/utils/index.js'
-import { createChargingStation, type TestChargingStation } from '../../../ChargingStationFactory.js'
import { TEST_CHARGING_STATION_BASE_NAME } from '../../ChargingStationTestConstants.js'
+import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
// Sample Base64 EXI request (mock - represents CertificateInstallationReq)
const MOCK_EXI_REQUEST = 'SGVsbG8gV29ybGQgRVhJIFJlcXVlc3Q='
})
await describe('M02 - Get15118EVCertificate Request', async () => {
- let mockChargingStation: TestChargingStation
+ let station: ReturnType<typeof createMockChargingStation>
beforeEach(() => {
- mockChargingStation = createChargingStation({
+ const { station: newStation } = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 3,
evseConfiguration: { evsesCount: 3 },
},
websocketPingInterval: Constants.DEFAULT_WEBSOCKET_PING_INTERVAL,
})
+ station = newStation
})
afterEach(() => {
})
await service.requestGet15118EVCertificate(
- mockChargingStation,
+ station,
MOCK_ISO15118_SCHEMA_VERSION,
CertificateActionEnumType.Install,
MOCK_EXI_REQUEST
})
await service.requestGet15118EVCertificate(
- mockChargingStation,
+ station,
MOCK_ISO15118_SCHEMA_VERSION,
CertificateActionEnumType.Update,
MOCK_EXI_REQUEST
})
const response = await service.requestGet15118EVCertificate(
- mockChargingStation,
+ station,
MOCK_ISO15118_SCHEMA_VERSION,
CertificateActionEnumType.Install,
MOCK_EXI_REQUEST
})
const response = await service.requestGet15118EVCertificate(
- mockChargingStation,
+ station,
MOCK_ISO15118_SCHEMA_VERSION,
CertificateActionEnumType.Install,
MOCK_EXI_REQUEST
})
await service.requestGet15118EVCertificate(
- mockChargingStation,
+ station,
MOCK_ISO15118_SCHEMA_VERSION,
CertificateActionEnumType.Install,
MOCK_EXI_REQUEST
})
await service.requestGet15118EVCertificate(
- mockChargingStation,
+ station,
MOCK_ISO15118_SCHEMA_VERSION,
CertificateActionEnumType.Install,
complexBase64EXI
})
await describe('M03 - GetCertificateStatus Request', async () => {
- let mockChargingStation: TestChargingStation
+ let station: TestChargingStation
beforeEach(() => {
- mockChargingStation = createChargingStation({
+ station = createChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 3,
evseConfiguration: { evsesCount: 3 },
const ocspRequestData = createMockOCSPRequestData()
- await service.requestGetCertificateStatus(mockChargingStation, ocspRequestData)
+ await service.requestGetCertificateStatus(station, ocspRequestData)
expect(sendMessageMock.mock.calls.length).toBe(1)
})
const response = await service.requestGetCertificateStatus(
- mockChargingStation,
+ station,
createMockOCSPRequestData()
)
})
const response = await service.requestGetCertificateStatus(
- mockChargingStation,
+ station,
createMockOCSPRequestData()
)
})
const response = await service.requestGetCertificateStatus(
- mockChargingStation,
+ station,
createMockOCSPRequestData()
)
})
await describe('Request Command Names', async () => {
- let mockChargingStation: TestChargingStation
+ let station: TestChargingStation
beforeEach(() => {
- mockChargingStation = createChargingStation({
+ station = createChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 1,
evseConfiguration: { evsesCount: 1 },
})
await service.requestGet15118EVCertificate(
- mockChargingStation,
+ station,
MOCK_ISO15118_SCHEMA_VERSION,
CertificateActionEnumType.Install,
MOCK_EXI_REQUEST
},
})
- await service.requestGetCertificateStatus(mockChargingStation, createMockOCSPRequestData())
+ await service.requestGetCertificateStatus(station, createMockOCSPRequestData())
const commandName = sendMessageMock.mock.calls[0].arguments[3]
expect(commandName).toBe(OCPP20RequestCommand.GET_CERTIFICATE_STATUS)
type ReportDataType,
} from '../../../../src/types/index.js'
import { Constants } from '../../../../src/utils/index.js'
-import { createChargingStation, type TestChargingStation } from '../../../ChargingStationFactory.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,
await describe('B07/B08 - NotifyReport', async () => {
let testableService: TestableOCPP20RequestService
- let mockChargingStation: TestChargingStation
+ let station: ChargingStation
beforeEach(() => {
const { service } = createTestableRequestService()
testableService = service
- mockChargingStation = createChargingStation({
+ const { station: createdStation } = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 3,
evseConfiguration: { evsesCount: 3 },
},
websocketPingInterval: Constants.DEFAULT_WEBSOCKET_PING_INTERVAL,
})
+ station = createdStation
})
afterEach(() => {
// Access the private buildRequestPayload method via type assertion
const payload = testableService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.NOTIFY_REPORT,
requestParams
) as OCPP20NotifyReportRequest
}
const payload = testableService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.NOTIFY_REPORT,
requestParams
) as OCPP20NotifyReportRequest
}
const payload = testableService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.NOTIFY_REPORT,
requestParams
) as OCPP20NotifyReportRequest
}
const payload = testableService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.NOTIFY_REPORT,
requestParams
) as OCPP20NotifyReportRequest
}
const payload = testableService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.NOTIFY_REPORT,
requestParams
) as OCPP20NotifyReportRequest
}
const payload = testableService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.NOTIFY_REPORT,
requestParams
) as OCPP20NotifyReportRequest
}
const payload = testableService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.NOTIFY_REPORT,
requestParams
) as OCPP20NotifyReportRequest
}
const payload = testableService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.NOTIFY_REPORT,
requestParams
) as OCPP20NotifyReportRequest
}
const payload = testableService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.NOTIFY_REPORT,
requestParams
) as OCPP20NotifyReportRequest
}
const payload = testableService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.NOTIFY_REPORT,
requestParams
) as OCPP20NotifyReportRequest
OCPPVersion,
} from '../../../../src/types/index.js'
import { Constants } from '../../../../src/utils/index.js'
-import { createChargingStation, type TestChargingStation } from '../../../ChargingStationFactory.js'
+import { createMockChargingStation } from '../../../ChargingStationTestUtils.js'
+import type { ChargingStation } from '../../../../src/charging-station/index.js'
import { TEST_CHARGING_STATION_BASE_NAME } from '../../ChargingStationTestConstants.js'
const MOCK_ORGANIZATION_NAME = 'Test Organization Inc.'
await describe('I02 - SignCertificate Request', async () => {
- let mockChargingStation: TestChargingStation
+ let station: ChargingStation
beforeEach(() => {
- mockChargingStation = createChargingStation({
+ const { station: createdStation } = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 3,
evseConfiguration: { evsesCount: 3 },
},
websocketPingInterval: Constants.DEFAULT_WEBSOCKET_PING_INTERVAL,
})
+ station = createdStation
// Set up configuration with OrganizationName
- mockChargingStation.ocppConfiguration = {
+ station.ocppConfiguration = {
configurationKey: [{ key: 'SecurityCtrlr.OrganizationName', value: MOCK_ORGANIZATION_NAME }],
}
})
})
const response = await service.requestSignCertificate(
- mockChargingStation,
+ station,
CertificateSigningUseEnumType.ChargingStationCertificate
)
})
await service.requestSignCertificate(
- mockChargingStation,
+ station,
CertificateSigningUseEnumType.ChargingStationCertificate
)
})
await service.requestSignCertificate(
- mockChargingStation,
+ station,
CertificateSigningUseEnumType.ChargingStationCertificate
)
})
await service.requestSignCertificate(
- mockChargingStation,
+ station,
CertificateSigningUseEnumType.V2GCertificate
)
})
const response = await service.requestSignCertificate(
- mockChargingStation,
+ station,
CertificateSigningUseEnumType.ChargingStationCertificate
)
})
const response = await service.requestSignCertificate(
- mockChargingStation,
+ station,
CertificateSigningUseEnumType.ChargingStationCertificate
)
},
})
- await service.requestSignCertificate(mockChargingStation)
+ await service.requestSignCertificate(station)
const sentPayload = sendMessageMock.mock.calls[0].arguments[2] as OCPP20SignCertificateRequest
})
await service.requestSignCertificate(
- mockChargingStation,
+ station,
CertificateSigningUseEnumType.ChargingStationCertificate
)
})
await service.requestSignCertificate(
- mockChargingStation,
+ station,
CertificateSigningUseEnumType.ChargingStationCertificate
)
OCPPVersion,
} from '../../../../src/types/index.js'
import { Constants } from '../../../../src/utils/index.js'
-import { createChargingStation, type TestChargingStation } from '../../../ChargingStationFactory.js'
+import { createMockChargingStation } from '../../../ChargingStationTestUtils.js'
+import type { ChargingStation } from '../../../../src/charging-station/index.js'
import {
TEST_FIRMWARE_VERSION,
TEST_STATUS_CHARGE_POINT_MODEL,
let mockResponseService: OCPP20ResponseService
let requestService: OCPP20RequestService
let testableRequestService: TestableOCPP20RequestService
- let mockChargingStation: TestChargingStation
+ let station: ChargingStation
beforeEach(() => {
mockResponseService = new OCPP20ResponseService()
requestService = new OCPP20RequestService(mockResponseService)
testableRequestService = createTestableOCPP20RequestService(requestService)
- mockChargingStation = createChargingStation({
+ const { station: createdStation } = createMockChargingStation({
baseName: TEST_STATUS_CHARGING_STATION_BASE_NAME,
connectorsCount: 3,
evseConfiguration: { evsesCount: 3 },
},
websocketPingInterval: Constants.DEFAULT_WEBSOCKET_PING_INTERVAL,
})
+ station = createdStation
})
afterEach(() => {
}
const payload = testableRequestService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.STATUS_NOTIFICATION,
requestParams
) as OCPP20StatusNotificationRequest
}
const payload = testableRequestService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.STATUS_NOTIFICATION,
requestParams
) as OCPP20StatusNotificationRequest
}
const payload = testableRequestService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.STATUS_NOTIFICATION,
requestParams
) as OCPP20StatusNotificationRequest
}
const payload = testableRequestService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.STATUS_NOTIFICATION,
requestParams
) as OCPP20StatusNotificationRequest
}
const payload = testableRequestService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.STATUS_NOTIFICATION,
requestParams
) as OCPP20StatusNotificationRequest
}
const payloadConnector0 = testableRequestService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.STATUS_NOTIFICATION,
requestParamsConnector0
) as OCPP20StatusNotificationRequest
}
const payloadEvse0 = testableRequestService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.STATUS_NOTIFICATION,
requestParamsEvse0
) as OCPP20StatusNotificationRequest
}
const payload = testableRequestService.buildRequestPayload(
- mockChargingStation,
+ station,
OCPP20RequestCommand.STATUS_NOTIFICATION,
requestParams
) as OCPP20StatusNotificationRequest
} from '../../../../src/types/ocpp/2.0/Transaction.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 { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import {
type CapturedOCPPRequest,
createMockOCPP20TransactionTestStation,
await it('should handle errors gracefully', async () => {
// Create a mock charging station that throws an error
- const errorMockChargingStation = createChargingStation({
+ const { station: errorMockChargingStation } = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 1,
evseConfiguration: { evsesCount: 1 },
await it('should handle context-aware error scenarios gracefully', async () => {
// Create error mock for this test
- const errorMockChargingStation = createChargingStation({
+ const { station: errorMockChargingStation } = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 1,
evseConfiguration: { evsesCount: 1 },
return Promise.resolve({} as EmptyObject)
})
- const errorStation = createChargingStation({
+ const { station: errorStation } = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 1,
evseConfiguration: { evsesCount: 1 },
await describe('startTxUpdatedInterval', async () => {
await it('should not start timer for non-OCPP 2.0 stations', () => {
- const ocpp16Station = createChargingStation({
+ const { station: ocpp16Station } = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 1,
stationInfo: {
await describe('Error handling', async () => {
await it('should handle network errors gracefully during periodic event', async () => {
- const errorMockChargingStation = createChargingStation({
+ const { station: errorMockChargingStation } = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 1,
evseConfiguration: { evsesCount: 1 },
} from '../../../../src/types/index.js'
import { Constants } 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 { createMockChargingStation } from '../../ChargingStationTestUtils.js'
import {
resetReportingValueSize,
resetValueSizeLimits,
await describe('B05/B06 - OCPP20VariableManager test suite', async () => {
// Type declaration for mock ChargingStation
- let mockChargingStation: ReturnType<typeof createChargingStation>
+ let station: ReturnType<typeof createMockChargingStation>
// Initialize mock ChargingStation before each test
beforeEach(() => {
- mockChargingStation = createChargingStation({
+ const { station: newStation } = createMockChargingStation({
baseName: TEST_CHARGING_STATION_BASE_NAME,
connectorsCount: 3,
evseConfiguration: { evsesCount: 3 },
},
websocketPingInterval: Constants.DEFAULT_WEBSOCKET_PING_INTERVAL,
})
+ station = newStation
})
// Reset singleton state after each test to ensure test isolation
},
]
- const result = manager.getVariables(mockChargingStation, request)
+ const result = manager.getVariables(station, request)
expect(Array.isArray(result)).toBe(true)
expect(result).toHaveLength(2)
variable: { name: OCPP20RequiredVariableName.AuthorizeRemoteStart },
},
]
- const result = manager.getVariables(mockChargingStation, request)
+ const result = manager.getVariables(station, request)
expect(result).toHaveLength(1)
expect(result[0].attributeStatus).toBe(GetVariableStatusEnumType.Accepted)
expect(result[0].attributeValue).toBe('true')
})
await it('should accept setting and getting AuthorizeRemoteStart = true (AuthCtrlr)', () => {
- const setRes = manager.setVariables(mockChargingStation, [
+ const setRes = manager.setVariables(station, [
{
attributeValue: 'true',
component: { name: OCPP20ComponentName.AuthCtrlr },
},
])[0]
expect(setRes.attributeStatus).toBe(SetVariableStatusEnumType.Accepted)
- const getRes = manager.getVariables(mockChargingStation, [
+ const getRes = manager.getVariables(station, [
{
component: { name: OCPP20ComponentName.AuthCtrlr },
variable: { name: OCPP20RequiredVariableName.AuthorizeRemoteStart },
await it('should reject invalid values for AuthorizeRemoteStart (AuthCtrlr)', () => {
const invalidValues = ['', '1', 'TRUE', 'False', 'yes']
for (const val of invalidValues) {
- const res = manager.setVariables(mockChargingStation, [
+ const res = manager.setVariables(station, [
{
attributeValue: val,
component: { name: OCPP20ComponentName.AuthCtrlr },
},
]
- const result = manager.getVariables(mockChargingStation, request)
+ const result = manager.getVariables(station, request)
expect(Array.isArray(result)).toBe(true)
expect(result).toHaveLength(1)
},
]
- const result = manager.getVariables(mockChargingStation, request)
+ const result = manager.getVariables(station, request)
expect(Array.isArray(result)).toBe(true)
expect(result).toHaveLength(1)
variable: { name: OCPP20OptionalVariableName.WebSocketPingInterval },
},
]
- const result = manager.getVariables(mockChargingStation, request)
+ const result = manager.getVariables(station, request)
expect(result).toHaveLength(1)
expect(result[0].attributeStatus).toBe(GetVariableStatusEnumType.NotSupportedAttributeType)
expect(result[0].variable.name).toBe(OCPP20OptionalVariableName.WebSocketPingInterval)
},
]
- const result = manager.getVariables(mockChargingStation, request)
+ const result = manager.getVariables(station, request)
expect(Array.isArray(result)).toBe(true)
expect(result).toHaveLength(1)
},
]
- const result = manager.getVariables(mockChargingStation, request)
+ const result = manager.getVariables(station, request)
expect(Array.isArray(result)).toBe(true)
expect(result).toHaveLength(3)
// Third variable: MessageTimeout
expect(result[2].attributeStatus).toBe(GetVariableStatusEnumType.Accepted)
expect(result[2].attributeType).toBe(AttributeEnumType.Actual)
- expect(result[2].attributeValue).toBe(mockChargingStation.getConnectionTimeout().toString())
+ expect(result[2].attributeValue).toBe(station.getConnectionTimeout().toString())
expect(result[2].component.name).toBe(OCPP20ComponentName.OCPPCommCtrlr)
expect(result[2].component.instance).toBe('Default')
expect(result[2].variable.name).toBe(OCPP20RequiredVariableName.MessageTimeout)
},
]
- const result = manager.getVariables(mockChargingStation, request)
+ const result = manager.getVariables(station, request)
expect(Array.isArray(result)).toBe(true)
expect(result).toHaveLength(1)
const component: ComponentType = { name: OCPP20ComponentName.OCPPCommCtrlr }
// Access private method through any casting for testing
- const isValid = testable.isComponentValid(mockChargingStation, component)
+ const isValid = testable.isComponentValid(station, component)
expect(isValid).toBe(true)
})
await it('should reject Connector component as unsupported even when connectors exist', () => {
const component: ComponentType = { instance: '1', name: OCPP20ComponentName.Connector }
- const isValid = testable.isComponentValid(mockChargingStation, component)
+ const isValid = testable.isComponentValid(station, component)
expect(isValid).toBe(false)
})
await it('should reject invalid connector instance', () => {
const component: ComponentType = { instance: '999', name: OCPP20ComponentName.Connector }
- const isValid = testable.isComponentValid(mockChargingStation, component)
+ const isValid = testable.isComponentValid(station, component)
expect(isValid).toBe(false)
})
})
},
]
- const result = manager.setVariables(mockChargingStation, request)
+ const result = manager.setVariables(station, request)
expect(result).toHaveLength(2)
expect(result[0].attributeStatus).toBe(SetVariableStatusEnumType.Accepted)
},
]
- const result = manager.setVariables(mockChargingStation, request)
+ const result = manager.setVariables(station, request)
expect(result).toHaveLength(1)
expect(result[0].attributeStatus).toBe(SetVariableStatusEnumType.UnknownComponent)
},
]
- const result = manager.setVariables(mockChargingStation, request)
+ const result = manager.setVariables(station, request)
expect(result).toHaveLength(1)
expect(result[0].attributeStatus).toBe(SetVariableStatusEnumType.UnknownVariable)
},
]
- const result = manager.setVariables(mockChargingStation, request)
+ const result = manager.setVariables(station, request)
expect(result).toHaveLength(1)
expect(result[0].attributeStatus).toBe(SetVariableStatusEnumType.NotSupportedAttributeType)
},
]
- const result = manager.setVariables(mockChargingStation, request)
+ const result = manager.setVariables(station, request)
expect(result).toHaveLength(1)
expect(result[0].attributeStatus).toBe(SetVariableStatusEnumType.Rejected)
variable: { name: OCPP20RequiredVariableName.TxUpdatedInterval },
},
]
- const result = manager.setVariables(mockChargingStation, request)
+ const result = manager.setVariables(station, request)
expect(result[0].attributeStatus).toBe(SetVariableStatusEnumType.Accepted)
expect(result[0].attributeStatusInfo).toBeUndefined()
})
variable: { name: OCPP20RequiredVariableName.TxUpdatedInterval },
},
]
- const zeroRes = manager.setVariables(mockChargingStation, zeroReq)[0]
- const negRes = manager.setVariables(mockChargingStation, negReq)[0]
- const nonIntRes = manager.setVariables(mockChargingStation, nonIntReq)[0]
+ const zeroRes = manager.setVariables(station, zeroReq)[0]
+ const negRes = manager.setVariables(station, negReq)[0]
+ const nonIntRes = manager.setVariables(station, nonIntReq)[0]
expect(zeroRes.attributeStatus).toBe(SetVariableStatusEnumType.Rejected)
expect(zeroRes.attributeStatusInfo?.reasonCode).toBe(ReasonCodeEnumType.ValuePositiveOnly)
expect(zeroRes.attributeStatusInfo?.additionalInfo).toContain('Positive integer > 0 required')
variable: { name: OCPP20VendorVariableName.ConnectionUrl },
},
]
- const res = manager.setVariables(mockChargingStation, req)[0]
+ const res = manager.setVariables(station, req)[0]
expect(res.attributeStatus).toBe(SetVariableStatusEnumType.Accepted)
expect(res.attributeStatusInfo).toBeUndefined()
})
variable: { name: OCPP20VendorVariableName.ConnectionUrl },
},
]
- const res = manager.setVariables(mockChargingStation, req)[0]
+ const res = manager.setVariables(station, req)[0]
expect(res.attributeStatus).toBe(SetVariableStatusEnumType.Accepted)
expect(res.attributeStatusInfo).toBeUndefined()
})
variable: { name: OCPP20VendorVariableName.ConnectionUrl },
},
]
- const res = manager.setVariables(mockChargingStation, req)[0]
+ const res = manager.setVariables(station, req)[0]
expect(res.attributeStatus).toBe(SetVariableStatusEnumType.Accepted)
expect(res.attributeStatusInfo).toBeUndefined()
})
await it('should allow ConnectionUrl retrieval after set', () => {
- manager.setVariables(mockChargingStation, [
+ manager.setVariables(station, [
{
attributeValue: 'wss://example.com/ocpp',
component: { name: OCPP20ComponentName.ChargingStation },
variable: { name: OCPP20VendorVariableName.ConnectionUrl },
},
]
- const getResult = manager.getVariables(mockChargingStation, getData)[0]
+ const getResult = manager.getVariables(station, getData)[0]
expect(getResult.attributeStatus).toBe(GetVariableStatusEnumType.Accepted)
expect(getResult.attributeValue).toBe('wss://example.com/ocpp')
expect(getResult.attributeStatusInfo).toBeUndefined()
})
await it('should revert non-persistent TxUpdatedInterval after simulated restart', () => {
- manager.setVariables(mockChargingStation, [
+ manager.setVariables(station, [
{
attributeValue: '99',
component: { name: OCPP20ComponentName.SampledDataCtrlr },
variable: { name: OCPP20RequiredVariableName.TxUpdatedInterval },
},
])
- const beforeReset = manager.getVariables(mockChargingStation, [
+ const beforeReset = manager.getVariables(station, [
{
component: { name: OCPP20ComponentName.SampledDataCtrlr },
variable: { name: OCPP20RequiredVariableName.TxUpdatedInterval },
])[0]
expect(beforeReset.attributeValue).toBe('99')
manager.resetRuntimeOverrides()
- const afterReset = manager.getVariables(mockChargingStation, [
+ const afterReset = manager.getVariables(station, [
{
component: { name: OCPP20ComponentName.SampledDataCtrlr },
variable: { name: OCPP20RequiredVariableName.TxUpdatedInterval },
})
await it('should keep persistent ConnectionUrl after simulated restart', () => {
- manager.setVariables(mockChargingStation, [
+ manager.setVariables(station, [
{
attributeValue: 'https://central.example.com/ocpp',
component: { name: OCPP20ComponentName.ChargingStation },
},
])
manager.resetRuntimeOverrides()
- const getResult = manager.getVariables(mockChargingStation, [
+ const getResult = manager.getVariables(station, [
{
component: { name: OCPP20ComponentName.ChargingStation },
variable: { name: OCPP20VendorVariableName.ConnectionUrl },
variable: { name: OCPP20OptionalVariableName.WebSocketPingInterval },
},
]
- const result = manager.setVariables(mockChargingStation, request)
+ const result = manager.setVariables(station, request)
expect(result).toHaveLength(1)
expect(result[0].attributeStatus).toBe(SetVariableStatusEnumType.NotSupportedAttributeType)
expect(result[0].attributeStatusInfo?.reasonCode).toBe(ReasonCodeEnumType.UnsupportedParam)
variable: { name: OCPP20OptionalVariableName.HeartbeatInterval },
},
]
- const res = manager.setVariables(mockChargingStation, req)[0]
+ const res = manager.setVariables(station, req)[0]
expect(res.attributeStatus).toBe(SetVariableStatusEnumType.Accepted)
expect(res.attributeStatusInfo).toBeUndefined()
})
await it('should reject HeartbeatInterval zero, negative, non-integer', () => {
- const zeroRes = manager.setVariables(mockChargingStation, [
+ const zeroRes = manager.setVariables(station, [
{
attributeValue: '0',
component: { name: OCPP20ComponentName.OCPPCommCtrlr },
variable: { name: OCPP20OptionalVariableName.HeartbeatInterval },
},
])[0]
- const negRes = manager.setVariables(mockChargingStation, [
+ const negRes = manager.setVariables(station, [
{
attributeValue: '-1',
component: { name: OCPP20ComponentName.OCPPCommCtrlr },
variable: { name: OCPP20OptionalVariableName.HeartbeatInterval },
},
])[0]
- const nonIntRes = manager.setVariables(mockChargingStation, [
+ const nonIntRes = manager.setVariables(station, [
{
attributeValue: '10.5',
component: { name: OCPP20ComponentName.OCPPCommCtrlr },
})
await it('should accept WebSocketPingInterval zero (disable) and positive', () => {
- const zeroRes = manager.setVariables(mockChargingStation, [
+ const zeroRes = manager.setVariables(station, [
{
attributeValue: '0',
component: { name: OCPP20ComponentName.ChargingStation },
variable: { name: OCPP20OptionalVariableName.WebSocketPingInterval },
},
])[0]
- const posRes = manager.setVariables(mockChargingStation, [
+ const posRes = manager.setVariables(station, [
{
attributeValue: (Constants.DEFAULT_WEBSOCKET_PING_INTERVAL + 10).toString(),
component: { name: OCPP20ComponentName.ChargingStation },
})
await it('should reject WebSocketPingInterval negative and non-integer', () => {
- const negRes = manager.setVariables(mockChargingStation, [
+ const negRes = manager.setVariables(station, [
{
attributeValue: '-2',
component: { name: OCPP20ComponentName.ChargingStation },
variable: { name: OCPP20OptionalVariableName.WebSocketPingInterval },
},
])[0]
- const nonIntRes = manager.setVariables(mockChargingStation, [
+ const nonIntRes = manager.setVariables(station, [
{
attributeValue: '5.7',
component: { name: OCPP20ComponentName.ChargingStation },
})
await it('should validate EVConnectionTimeOut positive integer >0 and reject invalid', () => {
- const okRes = manager.setVariables(mockChargingStation, [
+ const okRes = manager.setVariables(station, [
{
attributeValue: (Constants.DEFAULT_EV_CONNECTION_TIMEOUT + 5).toString(),
component: { name: OCPP20ComponentName.TxCtrlr },
])[0]
expect(okRes.attributeStatus).toBe(SetVariableStatusEnumType.Accepted)
expect(okRes.attributeStatusInfo).toBeUndefined()
- const zeroRes = manager.setVariables(mockChargingStation, [
+ const zeroRes = manager.setVariables(station, [
{
attributeValue: '0',
component: { name: OCPP20ComponentName.TxCtrlr },
variable: { name: OCPP20RequiredVariableName.EVConnectionTimeOut },
},
])[0]
- const negRes = manager.setVariables(mockChargingStation, [
+ const negRes = manager.setVariables(station, [
{
attributeValue: '-10',
component: { name: OCPP20ComponentName.TxCtrlr },
variable: { name: OCPP20RequiredVariableName.EVConnectionTimeOut },
},
])[0]
- const nonIntRes = manager.setVariables(mockChargingStation, [
+ const nonIntRes = manager.setVariables(station, [
{
attributeValue: '15.2',
component: { name: OCPP20ComponentName.TxCtrlr },
})
await it('should validate MessageTimeout positive integer >0 and reject invalid', () => {
- const okRes = manager.setVariables(mockChargingStation, [
+ const okRes = manager.setVariables(station, [
{
- attributeValue: (mockChargingStation.getConnectionTimeout() + 5).toString(),
+ attributeValue: (station.getConnectionTimeout() + 5).toString(),
component: { instance: 'Default', name: OCPP20ComponentName.OCPPCommCtrlr },
variable: { name: OCPP20RequiredVariableName.MessageTimeout },
},
])[0]
expect(okRes.attributeStatus).toBe(SetVariableStatusEnumType.Accepted)
expect(okRes.attributeStatusInfo).toBeUndefined()
- const zeroRes = manager.setVariables(mockChargingStation, [
+ const zeroRes = manager.setVariables(station, [
{
attributeValue: '0',
component: { instance: 'Default', name: OCPP20ComponentName.OCPPCommCtrlr },
variable: { name: OCPP20RequiredVariableName.MessageTimeout },
},
])[0]
- const negRes = manager.setVariables(mockChargingStation, [
+ const negRes = manager.setVariables(station, [
{
attributeValue: '-25',
component: { instance: 'Default', name: OCPP20ComponentName.OCPPCommCtrlr },
variable: { name: OCPP20RequiredVariableName.MessageTimeout },
},
])[0]
- const nonIntRes = manager.setVariables(mockChargingStation, [
+ const nonIntRes = manager.setVariables(station, [
{
attributeValue: '30.9',
component: { instance: 'Default', name: OCPP20ComponentName.OCPPCommCtrlr },
await it('should avoid duplicate persistence operations when value unchanged', () => {
const keyBefore = getConfigurationKey(
- mockChargingStation,
+ station,
OCPP20OptionalVariableName.HeartbeatInterval as unknown as VariableType['name']
)
expect(keyBefore).toBeDefined()
const originalValue = keyBefore?.value
- const first = manager.setVariables(mockChargingStation, [
+ const first = manager.setVariables(station, [
{
attributeValue: originalValue ?? '30',
component: { name: OCPP20ComponentName.OCPPCommCtrlr },
},
])[0]
expect(first.attributeStatus).toBe(SetVariableStatusEnumType.Accepted)
- const changed = manager.setVariables(mockChargingStation, [
+ const changed = manager.setVariables(station, [
{
attributeValue: (parseInt(originalValue ?? '30', 10) + 5).toString(),
component: { name: OCPP20ComponentName.OCPPCommCtrlr },
])[0]
expect(changed.attributeStatus).toBe(SetVariableStatusEnumType.Accepted)
const keyAfterChange = getConfigurationKey(
- mockChargingStation,
+ station,
OCPP20OptionalVariableName.HeartbeatInterval as unknown as VariableType['name']
)
expect(keyAfterChange?.value).not.toBe(originalValue)
- const reverted = manager.setVariables(mockChargingStation, [
+ const reverted = manager.setVariables(station, [
{
attributeValue: originalValue ?? '30',
component: { name: OCPP20ComponentName.OCPPCommCtrlr },
])[0]
expect(reverted.attributeStatus).toBe(SetVariableStatusEnumType.Accepted)
const keyAfterRevert = getConfigurationKey(
- mockChargingStation,
+ station,
OCPP20OptionalVariableName.HeartbeatInterval as unknown as VariableType['name']
)
expect(keyAfterRevert?.value).toBe(originalValue)
await it('should add missing configuration key with default during self-check', () => {
deleteConfigurationKey(
- mockChargingStation,
+ station,
OCPP20RequiredVariableName.EVConnectionTimeOut as unknown as VariableType['name'],
{ save: false }
)
const before = getConfigurationKey(
- mockChargingStation,
+ station,
OCPP20RequiredVariableName.EVConnectionTimeOut as unknown as VariableType['name']
)
expect(before).toBeUndefined()
- const res = manager.getVariables(mockChargingStation, [
+ const res = manager.getVariables(station, [
{
component: { name: OCPP20ComponentName.TxCtrlr },
variable: { name: OCPP20RequiredVariableName.EVConnectionTimeOut },
expect(res.attributeStatusInfo).toBeUndefined()
expect(res.attributeValue).toBe(Constants.DEFAULT_EV_CONNECTION_TIMEOUT.toString())
const after = getConfigurationKey(
- mockChargingStation,
+ station,
OCPP20RequiredVariableName.EVConnectionTimeOut as unknown as VariableType['name']
)
expect(after).toBeDefined()
})
await it('should clear runtime overrides via resetRuntimeOverrides()', () => {
- manager.setVariables(mockChargingStation, [
+ manager.setVariables(station, [
{
attributeValue: '123',
component: { name: OCPP20ComponentName.SampledDataCtrlr },
variable: { name: OCPP20RequiredVariableName.TxUpdatedInterval },
},
])
- const beforeReset = manager.getVariables(mockChargingStation, [
+ const beforeReset = manager.getVariables(station, [
{
component: { name: OCPP20ComponentName.SampledDataCtrlr },
variable: { name: OCPP20RequiredVariableName.TxUpdatedInterval },
])[0]
expect(beforeReset.attributeValue).toBe('123')
manager.resetRuntimeOverrides()
- const afterReset = manager.getVariables(mockChargingStation, [
+ const afterReset = manager.getVariables(station, [
{
component: { name: OCPP20ComponentName.SampledDataCtrlr },
variable: { name: OCPP20RequiredVariableName.TxUpdatedInterval },
})
await it('should reject HeartbeatInterval with leading whitespace', () => {
- const res = manager.setVariables(mockChargingStation, [
+ const res = manager.setVariables(station, [
{
attributeValue: ' 60',
component: { name: OCPP20ComponentName.OCPPCommCtrlr },
})
await it('should reject HeartbeatInterval with trailing whitespace', () => {
- const res = manager.setVariables(mockChargingStation, [
+ const res = manager.setVariables(station, [
{
attributeValue: '60 ',
component: { name: OCPP20ComponentName.OCPPCommCtrlr },
})
await it('should reject HeartbeatInterval with plus sign prefix', () => {
- const res = manager.setVariables(mockChargingStation, [
+ const res = manager.setVariables(station, [
{
attributeValue: '+10',
component: { name: OCPP20ComponentName.OCPPCommCtrlr },
})
await it('should accept HeartbeatInterval with leading zeros', () => {
- const res = manager.setVariables(mockChargingStation, [
+ const res = manager.setVariables(station, [
{
attributeValue: '007',
component: { name: OCPP20ComponentName.OCPPCommCtrlr },
})
await it('should reject HeartbeatInterval blank string', () => {
- const res = manager.setVariables(mockChargingStation, [
+ const res = manager.setVariables(station, [
{
attributeValue: '',
component: { name: OCPP20ComponentName.OCPPCommCtrlr },
})
await it('should reject HeartbeatInterval with internal space', () => {
- const res = manager.setVariables(mockChargingStation, [
+ const res = manager.setVariables(station, [
{
attributeValue: '6 0',
component: { name: OCPP20ComponentName.OCPPCommCtrlr },
})
await it('should reject ConnectionUrl missing scheme', () => {
- const res = manager.setVariables(mockChargingStation, [
+ const res = manager.setVariables(station, [
{
attributeValue: 'example.com/ocpp',
component: { name: OCPP20ComponentName.ChargingStation },
await it('should reject ConnectionUrl exceeding max length', () => {
const longUrl = 'wss://example.com/' + 'a'.repeat(600)
- const res = manager.setVariables(mockChargingStation, [
+ const res = manager.setVariables(station, [
{
attributeValue: longUrl,
component: { name: OCPP20ComponentName.ChargingStation },
})
await it('should reject HeartbeatInterval exceeding max length', () => {
- const res = manager.setVariables(mockChargingStation, [
+ const res = manager.setVariables(station, [
{
attributeValue: '1'.repeat(11),
component: { name: OCPP20ComponentName.OCPPCommCtrlr },
// Effective value size limit tests combining ConfigurationValueSize and ValueSize
await it('should enforce ConfigurationValueSize when ValueSize unset', () => {
- resetValueSizeLimits(mockChargingStation)
- setConfigurationValueSize(mockChargingStation, 50)
+ resetValueSizeLimits(station)
+ setConfigurationValueSize(station, 50)
// remove ValueSize to simulate unset
deleteConfigurationKey(
- mockChargingStation,
+ station,
OCPP20RequiredVariableName.ValueSize as unknown as VariableType['name'],
{ save: false }
)
- const okRes = manager.setVariables(mockChargingStation, [
+ const okRes = manager.setVariables(station, [
{
attributeValue: buildWsExampleUrl(50, 'x'),
component: { name: OCPP20ComponentName.ChargingStation },
},
])[0]
expect(okRes.attributeStatus).toBe(SetVariableStatusEnumType.Accepted)
- const tooLongRes = manager.setVariables(mockChargingStation, [
+ const tooLongRes = manager.setVariables(station, [
{
attributeValue: buildWsExampleUrl(51, 'x'),
component: { name: OCPP20ComponentName.ChargingStation },
})
await it('should enforce ValueSize when ConfigurationValueSize unset', () => {
- resetValueSizeLimits(mockChargingStation)
- setValueSize(mockChargingStation, 40)
+ resetValueSizeLimits(station)
+ setValueSize(station, 40)
deleteConfigurationKey(
- mockChargingStation,
+ station,
OCPP20RequiredVariableName.ConfigurationValueSize as unknown as VariableType['name'],
{ save: false }
)
- const okRes = manager.setVariables(mockChargingStation, [
+ const okRes = manager.setVariables(station, [
{
attributeValue: buildWsExampleUrl(40, 'y'),
component: { name: OCPP20ComponentName.ChargingStation },
},
])[0]
expect(okRes.attributeStatus).toBe(SetVariableStatusEnumType.Accepted)
- const tooLongRes = manager.setVariables(mockChargingStation, [
+ const tooLongRes = manager.setVariables(station, [
{
attributeValue: buildWsExampleUrl(41, 'y'),
component: { name: OCPP20ComponentName.ChargingStation },
})
await it('should use smaller of ConfigurationValueSize and ValueSize (ValueSize smaller)', () => {
- resetValueSizeLimits(mockChargingStation)
- setConfigurationValueSize(mockChargingStation, 60)
- setValueSize(mockChargingStation, 55)
- const okRes = manager.setVariables(mockChargingStation, [
+ resetValueSizeLimits(station)
+ setConfigurationValueSize(station, 60)
+ setValueSize(station, 55)
+ const okRes = manager.setVariables(station, [
{
attributeValue: buildWsExampleUrl(55, 'z'),
component: { name: OCPP20ComponentName.ChargingStation },
},
])[0]
expect(okRes.attributeStatus).toBe(SetVariableStatusEnumType.Accepted)
- const tooLongRes = manager.setVariables(mockChargingStation, [
+ const tooLongRes = manager.setVariables(station, [
{
attributeValue: buildWsExampleUrl(56, 'z'),
component: { name: OCPP20ComponentName.ChargingStation },
})
await it('should use smaller of ConfigurationValueSize and ValueSize (ConfigurationValueSize smaller)', () => {
- resetValueSizeLimits(mockChargingStation)
- setConfigurationValueSize(mockChargingStation, 30)
- setValueSize(mockChargingStation, 100)
- const okRes = manager.setVariables(mockChargingStation, [
+ resetValueSizeLimits(station)
+ setConfigurationValueSize(station, 30)
+ setValueSize(station, 100)
+ const okRes = manager.setVariables(station, [
{
attributeValue: buildWsExampleUrl(30, 'w'),
component: { name: OCPP20ComponentName.ChargingStation },
},
])[0]
expect(okRes.attributeStatus).toBe(SetVariableStatusEnumType.Accepted)
- const tooLongRes = manager.setVariables(mockChargingStation, [
+ const tooLongRes = manager.setVariables(station, [
{
attributeValue: buildWsExampleUrl(31, 'w'),
component: { name: OCPP20ComponentName.ChargingStation },
})
await it('should fallback to default limit when both invalid/non-positive', () => {
- resetValueSizeLimits(mockChargingStation)
+ resetValueSizeLimits(station)
// set invalid values
- setConfigurationValueSize(mockChargingStation, 0)
- setValueSize(mockChargingStation, -5)
- const okRes = manager.setVariables(mockChargingStation, [
+ setConfigurationValueSize(station, 0)
+ setValueSize(station, -5)
+ const okRes = manager.setVariables(station, [
{
attributeValue: buildWsExampleUrl(300, 'v'), // below default absolute max length
component: { name: OCPP20ComponentName.ChargingStation },
variable: { name: OCPP20RequiredVariableName.TxUpdatedMeasurands },
},
]
- const results = manager.setVariables(mockChargingStation, updateAttempts)
+ const results = manager.setVariables(station, updateAttempts)
// First (FileTransferProtocols) should be rejected (ReadOnly); others accepted
expect(results[0].attributeStatus).toBe(SetVariableStatusEnumType.Rejected)
expect(results[0].attributeStatusInfo?.reasonCode).toBe(ReasonCodeEnumType.ReadOnly)
})
await it('should retrieve FileTransferProtocols default including FTPS (ReadOnly)', () => {
- const getRes = manager.getVariables(mockChargingStation, [
+ const getRes = manager.getVariables(station, [
{
component: { name: OCPP20ComponentName.OCPPCommCtrlr },
variable: { name: OCPP20RequiredVariableName.FileTransferProtocols },
await it('should keep FileTransferProtocols value unchanged after rejected update attempt', () => {
// First ensure the configuration key exists by calling getVariables (triggers self-check)
- // Each test gets a fresh mockChargingStation, so we must initialize the configuration key
- const initGet = manager.getVariables(mockChargingStation, [
+ // Each test gets a fresh station, so we must initialize the configuration key
+ const initGet = manager.getVariables(station, [
{
component: { name: OCPP20ComponentName.OCPPCommCtrlr },
variable: { name: OCPP20RequiredVariableName.FileTransferProtocols },
expect(initGet.attributeValue).toBe('HTTPS,FTPS,SFTP')
const beforeCfg = getConfigurationKey(
- mockChargingStation,
+ station,
OCPP20RequiredVariableName.FileTransferProtocols as unknown as VariableType['name']
)
expect(beforeCfg?.value).toBe('HTTPS,FTPS,SFTP')
- const rejected = manager.setVariables(mockChargingStation, [
+ const rejected = manager.setVariables(station, [
{
attributeValue: 'HTTP,HTTPS',
component: { name: OCPP20ComponentName.OCPPCommCtrlr },
])[0]
expect(rejected.attributeStatus).toBe(SetVariableStatusEnumType.Rejected)
expect(rejected.attributeStatusInfo?.reasonCode).toBe(ReasonCodeEnumType.ReadOnly)
- const afterGet = manager.getVariables(mockChargingStation, [
+ const afterGet = manager.getVariables(station, [
{
component: { name: OCPP20ComponentName.OCPPCommCtrlr },
variable: { name: OCPP20RequiredVariableName.FileTransferProtocols },
expect(afterGet.attributeStatus).toBe(GetVariableStatusEnumType.Accepted)
expect(afterGet.attributeValue).toBe('HTTPS,FTPS,SFTP')
const afterCfg = getConfigurationKey(
- mockChargingStation,
+ station,
OCPP20RequiredVariableName.FileTransferProtocols as unknown as VariableType['name']
)
expect(afterCfg?.value).toBe(beforeCfg?.value)
})
await it('should reject removed TimeSource members RTC and Manual', () => {
- const res = manager.setVariables(mockChargingStation, [
+ const res = manager.setVariables(station, [
{
attributeValue: 'NTP,GPS,RTC,Manual', // RTC & Manual no longer valid
component: { name: OCPP20ComponentName.ClockCtrlr },
})
await it('should accept extended TimeSource including RealTimeClock and MobileNetwork', () => {
- const res = manager.setVariables(mockChargingStation, [
+ const res = manager.setVariables(station, [
{
attributeValue: 'MobileNetwork,Heartbeat,NTP,GPS,RealTimeClock',
component: { name: OCPP20ComponentName.ClockCtrlr },
const invalidPatterns = ['', ',HTTP', 'HTTP,', 'HTTP,,FTP', 'HTTP,HTTP']
for (const lv of listVariables) {
for (const pattern of invalidPatterns) {
- const res = manager.setVariables(mockChargingStation, [
+ const res = manager.setVariables(station, [
{
attributeValue: pattern,
component: { name: lv.component },
await it('should reject DataSigned in TxStopPoint list value', () => {
const manager = OCPP20VariableManager.getInstance()
- const res = manager.setVariables(mockChargingStation, [
+ const res = manager.setVariables(station, [
{
attributeValue: 'Authorized,EVConnected,DataSigned', // DataSigned invalid for stop point enumeration
component: { name: OCPP20ComponentName.TxCtrlr },
const manager = OCPP20VariableManager.getInstance()
await it('should truncate retrieved value using ValueSize only when ReportingValueSize absent', () => {
- resetValueSizeLimits(mockChargingStation)
+ resetValueSizeLimits(station)
// Ensure ReportingValueSize unset
deleteConfigurationKey(
- mockChargingStation,
+ station,
OCPP20RequiredVariableName.ReportingValueSize as unknown as VariableType['name'],
{ save: false }
)
// Temporarily set large ValueSize to allow storing long value
- setValueSize(mockChargingStation, 200)
+ setValueSize(station, 200)
const longUrl = buildWsExampleUrl(180, 'a')
- const setRes = manager.setVariables(mockChargingStation, [
+ const setRes = manager.setVariables(station, [
{
attributeValue: longUrl,
component: { name: OCPP20ComponentName.ChargingStation },
])[0]
expect(setRes.attributeStatus).toBe(SetVariableStatusEnumType.Accepted)
// Now reduce ValueSize to 50 to force truncation at get-time
- setValueSize(mockChargingStation, 50)
- const getRes = manager.getVariables(mockChargingStation, [
+ setValueSize(station, 50)
+ const getRes = manager.getVariables(station, [
{
component: { name: OCPP20ComponentName.ChargingStation },
variable: { name: OCPP20VendorVariableName.ConnectionUrl },
expect(getRes.attributeValue?.length).toBe(50)
// First 50 chars should match original long value prefix
expect(longUrl.startsWith(getRes.attributeValue ?? '')).toBe(true)
- resetValueSizeLimits(mockChargingStation)
+ resetValueSizeLimits(station)
})
await it('should apply ValueSize then ReportingValueSize sequential truncation', () => {
- resetValueSizeLimits(mockChargingStation)
+ resetValueSizeLimits(station)
// Store long value with large limits
- setValueSize(mockChargingStation, 300)
- setReportingValueSize(mockChargingStation, 250) // will be applied second
+ setValueSize(station, 300)
+ setReportingValueSize(station, 250) // will be applied second
const longUrl = buildWsExampleUrl(260, 'b')
- const setRes = manager.setVariables(mockChargingStation, [
+ const setRes = manager.setVariables(station, [
{
attributeValue: longUrl,
component: { name: OCPP20ComponentName.ChargingStation },
])[0]
expect(setRes.attributeStatus).toBe(SetVariableStatusEnumType.Accepted)
// Reduce ValueSize below ReportingValueSize to 200 so first truncation occurs at 200, then second at 150
- setValueSize(mockChargingStation, 200)
- setReportingValueSize(mockChargingStation, 150)
- const getRes = manager.getVariables(mockChargingStation, [
+ setValueSize(station, 200)
+ setReportingValueSize(station, 150)
+ const getRes = manager.getVariables(station, [
{
component: { name: OCPP20ComponentName.ChargingStation },
variable: { name: OCPP20VendorVariableName.ConnectionUrl },
expect(getRes.attributeStatus).toBe(GetVariableStatusEnumType.Accepted)
expect(getRes.attributeValue?.length).toBe(150)
expect(longUrl.startsWith(getRes.attributeValue ?? '')).toBe(true)
- resetValueSizeLimits(mockChargingStation)
- resetReportingValueSize(mockChargingStation)
+ resetValueSizeLimits(station)
+ resetReportingValueSize(station)
})
await it('should enforce absolute max character cap after truncation chain', () => {
- resetValueSizeLimits(mockChargingStation)
- resetReportingValueSize(mockChargingStation)
+ resetValueSizeLimits(station)
+ resetReportingValueSize(station)
// Directly upsert configuration key with > absolute max length value bypassing set-time limit (which rejects > absolute max length)
const overLongValue = buildWsExampleUrl(3000, 'c')
upsertConfigurationKey(
- mockChargingStation,
+ station,
OCPP20VendorVariableName.ConnectionUrl as unknown as VariableType['name'],
overLongValue
)
// Set generous ValueSize (1500) and ReportingValueSize (1400) so only absolute cap applies (since both < Constants.OCPP_VALUE_ABSOLUTE_MAX_LENGTH)
- setValueSize(mockChargingStation, 1500)
- setReportingValueSize(mockChargingStation, 1400)
- const getRes = manager.getVariables(mockChargingStation, [
+ setValueSize(station, 1500)
+ setReportingValueSize(station, 1400)
+ const getRes = manager.getVariables(station, [
{
component: { name: OCPP20ComponentName.ChargingStation },
variable: { name: OCPP20VendorVariableName.ConnectionUrl },
expect(getRes.attributeStatus).toBe(GetVariableStatusEnumType.Accepted)
expect(getRes.attributeValue?.length).toBe(1400)
expect(overLongValue.startsWith(getRes.attributeValue ?? '')).toBe(true)
- resetValueSizeLimits(mockChargingStation)
- resetReportingValueSize(mockChargingStation)
+ resetValueSizeLimits(station)
+ resetReportingValueSize(station)
})
await it('should not exceed variable maxLength even if ValueSize and ReportingValueSize set above it', () => {
- resetValueSizeLimits(mockChargingStation)
- resetReportingValueSize(mockChargingStation)
+ resetValueSizeLimits(station)
+ resetReportingValueSize(station)
// Store exactly variable maxLength value via setVariables (allowed per registry/spec)
const connectionUrlMaxLength =
VARIABLE_REGISTRY[
`${OCPP20ComponentName.ChargingStation}::${OCPP20VendorVariableName.ConnectionUrl}`
].maxLength ?? 512
const maxLenValue = buildWsExampleUrl(connectionUrlMaxLength, 'd')
- const setRes = manager.setVariables(mockChargingStation, [
+ const setRes = manager.setVariables(station, [
{
attributeValue: maxLenValue,
component: { name: OCPP20ComponentName.ChargingStation },
])[0]
expect(setRes.attributeStatus).toBe(SetVariableStatusEnumType.Accepted)
// Set larger limits that would allow a bigger value if not for variable-level maxLength
- setValueSize(mockChargingStation, 3000)
- setReportingValueSize(mockChargingStation, 2800)
- const getRes = manager.getVariables(mockChargingStation, [
+ setValueSize(station, 3000)
+ setReportingValueSize(station, 2800)
+ const getRes = manager.getVariables(station, [
{
component: { name: OCPP20ComponentName.ChargingStation },
variable: { name: OCPP20VendorVariableName.ConnectionUrl },
expect(getRes.attributeStatus).toBe(GetVariableStatusEnumType.Accepted)
expect(getRes.attributeValue?.length).toBe(connectionUrlMaxLength)
expect(getRes.attributeValue).toBe(maxLenValue)
- resetValueSizeLimits(mockChargingStation)
- resetReportingValueSize(mockChargingStation)
+ resetValueSizeLimits(station)
+ resetReportingValueSize(station)
})
})
await it('should auto-create persistent OrganizationName configuration key during self-check', () => {
deleteConfigurationKey(
- mockChargingStation,
+ station,
OCPP20RequiredVariableName.OrganizationName as unknown as VariableType['name'],
{ save: false }
)
const before = getConfigurationKey(
- mockChargingStation,
+ station,
OCPP20RequiredVariableName.OrganizationName as unknown as VariableType['name']
)
expect(before).toBeUndefined()
- const res = manager.getVariables(mockChargingStation, [
+ const res = manager.getVariables(station, [
{
component: { name: OCPP20ComponentName.SecurityCtrlr },
variable: { name: OCPP20RequiredVariableName.OrganizationName },
expect(res.attributeStatus).toBe(GetVariableStatusEnumType.Accepted)
expect(res.attributeValue).toBe('Example Charging Services Ltd')
const after = getConfigurationKey(
- mockChargingStation,
+ station,
OCPP20RequiredVariableName.OrganizationName as unknown as VariableType['name']
)
expect(after).toBeDefined()
})
await it('should accept setting OrganizationName and require reboot per OCPP 2.0.1 specification', () => {
- const setRes = manager.setVariables(mockChargingStation, [
+ const setRes = manager.setVariables(station, [
{
attributeValue: 'NewOrgName',
component: { name: OCPP20ComponentName.SecurityCtrlr },
])[0]
// OCPP 2.0.1 compliant behavior: OrganizationName changes require reboot
expect(setRes.attributeStatus).toBe(SetVariableStatusEnumType.RebootRequired)
- const getRes = manager.getVariables(mockChargingStation, [
+ const getRes = manager.getVariables(station, [
{
component: { name: OCPP20ComponentName.SecurityCtrlr },
variable: { name: OCPP20RequiredVariableName.OrganizationName },
await it('should preserve OrganizationName value after resetRuntimeOverrides()', () => {
// First set OrganizationName to ensure it's persisted (test must be self-contained)
- manager.setVariables(mockChargingStation, [
+ manager.setVariables(station, [
{
attributeValue: 'PersistenceTestOrgName',
component: { name: OCPP20ComponentName.SecurityCtrlr },
])
// Now reset runtime overrides
manager.resetRuntimeOverrides()
- const res = manager.getVariables(mockChargingStation, [
+ const res = manager.getVariables(station, [
{
component: { name: OCPP20ComponentName.SecurityCtrlr },
variable: { name: OCPP20RequiredVariableName.OrganizationName },
await it('should create configuration key for instance-scoped MessageAttemptInterval and persist Actual value (Actual-only, no MinSet/MaxSet)', () => {
// Ensure no configuration key exists before operations
const cfgBefore = getConfigurationKey(
- mockChargingStation,
+ station,
OCPP20RequiredVariableName.MessageAttemptInterval as unknown as VariableType['name']
)
expect(cfgBefore).toBeUndefined()
- const initialGet = manager.getVariables(mockChargingStation, [
+ const initialGet = manager.getVariables(station, [
{
component: { instance: 'TransactionEvent', name: OCPP20ComponentName.OCPPCommCtrlr },
variable: { name: OCPP20RequiredVariableName.MessageAttemptInterval },
expect(initialGet.attributeValue).toBe('5')
// Negative: MinSet not supported
- const minSetRes = manager.setVariables(mockChargingStation, [
+ const minSetRes = manager.setVariables(station, [
{
attributeType: AttributeEnumType.MinSet,
attributeValue: '6',
},
])[0]
expect(minSetRes.attributeStatus).toBe(SetVariableStatusEnumType.NotSupportedAttributeType)
- const getMin = manager.getVariables(mockChargingStation, [
+ const getMin = manager.getVariables(station, [
{
attributeType: AttributeEnumType.MinSet,
component: { instance: 'TransactionEvent', name: OCPP20ComponentName.OCPPCommCtrlr },
expect(getMin.attributeStatus).toBe(GetVariableStatusEnumType.NotSupportedAttributeType)
// Negative: MaxSet not supported
- const maxSetRes = manager.setVariables(mockChargingStation, [
+ const maxSetRes = manager.setVariables(station, [
{
attributeType: AttributeEnumType.MaxSet,
attributeValue: '10',
},
])[0]
expect(maxSetRes.attributeStatus).toBe(SetVariableStatusEnumType.NotSupportedAttributeType)
- const getMax = manager.getVariables(mockChargingStation, [
+ const getMax = manager.getVariables(station, [
{
attributeType: AttributeEnumType.MaxSet,
component: { instance: 'TransactionEvent', name: OCPP20ComponentName.OCPPCommCtrlr },
expect(getMax.attributeStatus).toBe(GetVariableStatusEnumType.NotSupportedAttributeType)
// Attempt Actual value below registry min (min=1) -> reject
- const belowMinRes = manager.setVariables(mockChargingStation, [
+ const belowMinRes = manager.setVariables(station, [
{
attributeValue: '0',
component: { instance: 'TransactionEvent', name: OCPP20ComponentName.OCPPCommCtrlr },
expect(belowMinRes.attributeStatusInfo?.reasonCode).toBe(ReasonCodeEnumType.ValuePositiveOnly)
// Attempt Actual value above registry max (max=3600) -> reject
- const aboveMaxRes = manager.setVariables(mockChargingStation, [
+ const aboveMaxRes = manager.setVariables(station, [
{
attributeValue: '3601',
component: { instance: 'TransactionEvent', name: OCPP20ComponentName.OCPPCommCtrlr },
expect(aboveMaxRes.attributeStatusInfo?.reasonCode).toBe(ReasonCodeEnumType.ValueTooHigh)
// Accept Actual value within metadata bounds
- const withinRes = manager.setVariables(mockChargingStation, [
+ const withinRes = manager.setVariables(station, [
{
attributeValue: '7',
component: { instance: 'TransactionEvent', name: OCPP20ComponentName.OCPPCommCtrlr },
expect(withinRes.attributeStatus).toBe(SetVariableStatusEnumType.Accepted)
// Retrieval now returns persisted value '7'
- const afterSetGet = manager.getVariables(mockChargingStation, [
+ const afterSetGet = manager.getVariables(station, [
{
component: { instance: 'TransactionEvent', name: OCPP20ComponentName.OCPPCommCtrlr },
variable: { name: OCPP20RequiredVariableName.MessageAttemptInterval },
expect(afterSetGet.attributeValue).toBe('7')
const cfgAfter = getConfigurationKey(
- mockChargingStation,
+ station,
OCPP20RequiredVariableName.MessageAttemptInterval as unknown as VariableType['name']
)
expect(cfgAfter).toBeDefined()
IdentifierType,
} from '../../../../src/charging-station/ocpp/auth/types/AuthTypes.js'
import { OCPPVersion } from '../../../../src/types/ocpp/OCPPVersion.js'
-import { createChargingStation } from '../../../ChargingStationFactory.js'
+import { createChargingStation } from '../../ChargingStationTestUtils.js'
import {
createMockAuthRequest,
createMockOCPP16Identifier,
import { AuthComponentFactory } from '../../../../../src/charging-station/ocpp/auth/factories/AuthComponentFactory.js'
import { OCPPVersion } from '../../../../../src/types/ocpp/OCPPVersion.js'
-import { createChargingStation } from '../../../../ChargingStationFactory.js'
+import { createMockChargingStation } from '../../../../ChargingStationTestUtils.js'
import { standardCleanup } from '../../../../helpers/TestLifecycleHelpers.js'
await describe('AuthComponentFactory', async () => {
await describe('createAdapters', async () => {
await it('should create OCPP 1.6 adapter', async () => {
- const chargingStation = createChargingStation({
+ const { station: chargingStation } = createMockChargingStation({
stationInfo: { ocppVersion: OCPPVersion.VERSION_16 },
})
const result = await AuthComponentFactory.createAdapters(chargingStation)
})
await it('should create OCPP 2.0 adapter', async () => {
- const chargingStation = createChargingStation({
+ const { station: chargingStation } = createMockChargingStation({
stationInfo: { ocppVersion: OCPPVersion.VERSION_20 },
})
const result = await AuthComponentFactory.createAdapters(chargingStation)
})
await it('should create OCPP 2.0.1 adapter', async () => {
- const chargingStation = createChargingStation({
+ const { station: chargingStation } = createMockChargingStation({
stationInfo: { ocppVersion: OCPPVersion.VERSION_201 },
})
const result = await AuthComponentFactory.createAdapters(chargingStation)
})
await it('should throw error for unsupported version', async () => {
- const chargingStation = createChargingStation({
+ const { station: chargingStation } = createMockChargingStation({
stationInfo: { ocppVersion: 'VERSION_15' as OCPPVersion },
})
})
await it('should throw error when no OCPP version', async () => {
- const chargingStation = createChargingStation()
+ const { station: chargingStation } = createMockChargingStation()
chargingStation.stationInfo = undefined
await expect(AuthComponentFactory.createAdapters(chargingStation)).rejects.toThrow(
await describe('createLocalAuthListManager', async () => {
await it('should return undefined (delegated to service)', () => {
- const chargingStation = createChargingStation()
+ const { station: chargingStation } = createMockChargingStation()
const config: AuthConfiguration = {
allowOfflineTxForUnknownId: false,
authorizationCacheEnabled: false,
await describe('createRemoteStrategy', async () => {
await it('should return undefined when remote auth disabled', async () => {
- const chargingStation = createChargingStation({
+ const { station: chargingStation } = createMockChargingStation({
stationInfo: { ocppVersion: OCPPVersion.VERSION_16 },
})
const adapters = await AuthComponentFactory.createAdapters(chargingStation)
})
await it('should create remote strategy when enabled', async () => {
- const chargingStation = createChargingStation({
+ const { station: chargingStation } = createMockChargingStation({
stationInfo: { ocppVersion: OCPPVersion.VERSION_16 },
})
const adapters = await AuthComponentFactory.createAdapters(chargingStation)
await describe('createCertificateStrategy', async () => {
await it('should create certificate strategy', async () => {
- const chargingStation = createChargingStation({
+ const { station: chargingStation } = createMockChargingStation({
stationInfo: { ocppVersion: OCPPVersion.VERSION_16 },
})
const adapters = await AuthComponentFactory.createAdapters(chargingStation)
await describe('createStrategies', async () => {
await it('should create only certificate strategy by default', async () => {
- const chargingStation = createChargingStation({
+ const { station: chargingStation } = createMockChargingStation({
stationInfo: { ocppVersion: OCPPVersion.VERSION_16 },
})
const adapters = await AuthComponentFactory.createAdapters(chargingStation)
})
await it('should create and sort all strategies when enabled', async () => {
- const chargingStation = createChargingStation({
+ const { station: chargingStation } = createMockChargingStation({
stationInfo: { ocppVersion: OCPPVersion.VERSION_16 },
})
const adapters = await AuthComponentFactory.createAdapters(chargingStation)
handleSendMessageError,
} from '../../src/utils/ErrorUtils.js'
import { logger } from '../../src/utils/Logger.js'
-import { createChargingStation } from '../ChargingStationFactory.js'
+import { createChargingStation } from '../charging-station/ChargingStationTestUtils.js'
import { standardCleanup } from '../helpers/TestLifecycleHelpers.js'
await describe('ErrorUtils test suite', async () => {