import { type ConnectorStatus, CurrentType, MeterValueMeasurand } from '../../types/index.js'
-import { isEmpty } from '../../utils/index.js'
+import { Constants, isEmpty } from '../../utils/index.js'
export interface TransactionIntervalState {
consumed: number
: Number.parseFloat(sampledValue.value)
if (!Number.isFinite(value)) continue
const unit = sampledValue.unitOfMeasure?.unit ?? sampledValue.unit
- const unitMultiplier = unit === 'kWh' ? 1000 : unit === 'MWh' ? 1_000_000 : 1
+ const unitMultiplier =
+ unit === 'kWh' ? Constants.UNIT_DIVIDER_KILO : unit === 'MWh' ? 1_000_000 : 1
const decimalMultiplier = 10 ** (sampledValue.unitOfMeasure?.multiplier ?? 0)
const phaseMultiplier = /^L[123](?:-N)?$/.test(sampledValue.phase ?? '') ? numberOfPhases : 1
const locationMultiplier =
this.pendingTriggeredMeterValues.delete(target.connectorStatus)
}
stationState?.triggeredMeterValueTargets?.delete(target)
- if (stationState?.triggeredMeterValueTargets?.size === 0) {
+ if (stationState != null && isEmpty(stationState.triggeredMeterValueTargets)) {
delete stationState.triggeredMeterValueTargets
}
}
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, beforeEach, describe, it, mock } from 'node:test'
-import { setTimeout as sleep } from 'node:timers/promises'
import { Bootstrap, STATE_FILE_VERSION } from '../../src/charging-station/index.js'
-import { logger } from '../../src/utils/index.js'
+import { logger, sleep } from '../../src/utils/index.js'
import { resetSingleton, standardCleanup } from '../helpers/TestLifecycleHelpers.js'
interface Barrier {
import type { ChargingStation } from '../../src/charging-station/ChargingStation.js'
import { OCPPProtocol } from '../../src/types/index.js'
-import { buildAddedMessage } from '../../src/utils/MessageChannelUtils.js'
+import { buildAddedMessage } from '../../src/utils/index.js'
import { flushMicrotasks, standardCleanup } from '../helpers/TestLifecycleHelpers.js'
import {
cleanupStationTemplates,
import type { ChargingStation } from '../../src/charging-station/ChargingStation.js'
-import { buildAddedMessage } from '../../src/utils/MessageChannelUtils.js'
+import { buildAddedMessage } from '../../src/utils/index.js'
import { flushMicrotasks, standardCleanup } from '../helpers/TestLifecycleHelpers.js'
import {
cleanupStationTemplates,
import { existsSync, readdirSync, readFileSync } from 'node:fs'
import { join } from 'node:path'
import { afterEach, describe, it } from 'node:test'
-import { setTimeout as sleep } from 'node:timers/promises'
import type { ChargingStation } from '../../src/charging-station/ChargingStation.js'
import type { ChargingStationOptions } from '../../src/types/index.js'
import { SharedLRUCache } from '../../src/charging-station/SharedLRUCache.js'
+import { sleep } from '../../src/utils/index.js'
import { standardCleanup } from '../helpers/TestLifecycleHelpers.js'
import {
cleanupStationTemplates,
* live in `OCPPSpecRequirements.md`.
*/
+import { Constants } from '../../src/utils/index.js'
+
/**
* Test Station Identifiers
* Base identifiers used for creating test charging station instances
export const TEST_AUTHORIZATION_TIMEOUT_MS = 30000
export const TEST_METER_VALUES_INTERVAL_MS = 30_000
export const TEST_ONE_HOUR_SECONDS = 3600
-export const TEST_ONE_HOUR_MS = TEST_ONE_HOUR_SECONDS * 1000
+export const TEST_ONE_HOUR_MS = Constants.MS_PER_HOUR
/**
* Charging Station Information
import { CURRENT_SCHEMA_VERSION } from '../../src/charging-station/index.js'
import { TemplateValidationError, validateTemplate } from '../../src/charging-station/index.js'
import { BaseError } from '../../src/exception/index.js'
-import { logger } from '../../src/utils/index.js'
+import { clone, logger } from '../../src/utils/index.js'
import { mockLoggerWarnDebug, standardCleanup } from '../helpers/TestLifecycleHelpers.js'
import { TEST_SUPERVISION_URL } from '../utils/TestNetworkConstants.js'
import { TEST_CHARGING_STATION_BASE_NAME } from './ChargingStationTestConstants.js'
Connectors: { 0: {}, 1: {} },
supervisionUrl: TEST_SUPERVISION_URL,
})
- const before = structuredClone(parsed)
+ const before = clone(parsed)
validateTemplate(parsed, 'immutable.json')
OCPP20TriggerReasonEnumType,
OCPP20UnitEnumType,
} from '../../src/types/index.js'
-import { Constants } from '../../src/utils/index.js'
+import { clone, Constants } from '../../src/utils/index.js'
import { standardCleanup } from '../helpers/TestLifecycleHelpers.js'
const validateTransactionEvent = createAjv().compile(transactionEventRequestSchema)
transactionEventQueue: existingEvents,
transactionId,
} as unknown as ConnectorStatus
- const queueSnapshot = structuredClone(existingEvents)
+ const queueSnapshot = clone(existingEvents)
const candidate = toQueuedEvent({
customData: { payload: 'x'.repeat(400_000), vendorId: 'test' },
eventType: OCPP20TransactionEventEnumType.Updated,
recordTransactionIntervalConsumption,
restoreTransactionIntervalState,
truncateTransactionIntervalValue,
-} from '../../src/charging-station/meter-values/TransactionIntervalUtils.js'
+} from '../../src/charging-station/meter-values/index.js'
import { standardCleanup } from '../helpers/TestLifecycleHelpers.js'
await describe('TransactionIntervalUtils', async () => {
*/
import assert from 'node:assert/strict'
-import { randomUUID } from 'node:crypto'
import { afterEach, describe, it, mock } from 'node:test'
import { ChargingStationWorkerBroadcastChannel } from '../../../src/charging-station/broadcast-channel/ChargingStationWorkerBroadcastChannel.js'
StandardParametersKey,
VendorParametersKey,
} from '../../../src/types/index.js'
-import { Constants } from '../../../src/utils/index.js'
+import { Constants, generateUUID } from '../../../src/utils/index.js'
import {
flushMicrotasks,
setupConnectorWithTransaction,
testable.requestHandler({
data: [
- randomUUID(),
+ generateUUID(),
BroadcastChannelProcedureName.GET_15118_EV_CERTIFICATE,
{ hashIds: [station.stationInfo?.hashId] },
],
testable.requestHandler({
data: [
- randomUUID(),
+ generateUUID(),
BroadcastChannelProcedureName.LOG_STATUS_NOTIFICATION,
{ hashIds: [station.stationInfo?.hashId] },
],
testable.requestHandler({
data: [
- randomUUID(),
+ generateUUID(),
BroadcastChannelProcedureName.NOTIFY_CUSTOMER_INFORMATION,
{ hashIds: [station.stationInfo?.hashId] },
],
testable.requestHandler({
data: [
- randomUUID(),
+ generateUUID(),
BroadcastChannelProcedureName.NOTIFY_REPORT,
{ hashIds: [station.stationInfo?.hashId] },
],
testable.requestHandler({
data: [
- randomUUID(),
+ generateUUID(),
BroadcastChannelProcedureName.SECURITY_EVENT_NOTIFICATION,
{ hashIds: [station.stationInfo?.hashId] },
],
testable.requestHandler({
data: [
- randomUUID(),
+ generateUUID(),
BroadcastChannelProcedureName.METER_VALUES,
{ connectorId: 1, hashIds: [station.stationInfo?.hashId] },
],
testable.requestHandler({
data: [
- randomUUID(),
+ generateUUID(),
BroadcastChannelProcedureName.METER_VALUES,
{ evseId: 1, hashIds: [station.stationInfo?.hashId] },
],
testable.requestHandler({
data: [
- randomUUID(),
+ generateUUID(),
BroadcastChannelProcedureName.METER_VALUES,
{
connectorId: 1,
import assert from 'node:assert/strict'
import { afterEach, describe, it } from 'node:test'
-import type { BuildVersionedSampledValue } from '../../../src/charging-station/meter-values/CoherentMeterValueBuilder.js'
import type {
+ BuildVersionedSampledValue,
CoherentSession,
EvProfile,
ICoherentContext,
-} from '../../../src/charging-station/meter-values/types.js'
+} from '../../../src/charging-station/meter-values/index.js'
import type {
ChargingStationInfo,
ConnectorStatus,
SampledValueTemplate,
} from '../../../src/types/index.js'
-import {
- buildCoherentMeterValue,
- buildCoherentMeterValueSnapshot,
-} from '../../../src/charging-station/meter-values/CoherentMeterValueBuilder.js'
import {
computeCoherentSample,
disposeCoherentSessionRuntime,
} from '../../../src/charging-station/meter-values/CoherentSampleComputer.js'
import {
+ buildCoherentMeterValue,
+ buildCoherentMeterValueSnapshot,
createCoherentSession,
resolveRootSeed,
-} from '../../../src/charging-station/meter-values/CoherentSession.js'
+} from '../../../src/charging-station/meter-values/index.js'
import { hashLabel } from '../../../src/charging-station/meter-values/PRNG.js'
import { buildOCPP20SampledValue } from '../../../src/charging-station/ocpp/2.0/OCPP20RequestBuilders.js'
import {
import assert from 'node:assert/strict'
import { afterEach, describe, it } from 'node:test'
-import type { EvProfile } from '../../../src/charging-station/meter-values/types.js'
+import type { EvProfile } from '../../../src/charging-station/meter-values/index.js'
import {
interpolateChargingCurve,
import type {
LocalAuthListManager,
OCPPAuthService,
-} from '../../../../src/charging-station/ocpp/auth/interfaces/OCPPAuthService.js'
+} from '../../../../src/charging-station/ocpp/auth/index.js'
import type { OCPP16SendLocalListRequest } from '../../../../src/types/index.js'
-import { InMemoryLocalAuthListManager } from '../../../../src/charging-station/ocpp/auth/cache/InMemoryLocalAuthListManager.js'
-import { OCPPAuthServiceFactory } from '../../../../src/charging-station/ocpp/auth/services/OCPPAuthServiceFactory.js'
+import {
+ InMemoryLocalAuthListManager,
+ OCPPAuthServiceFactory,
+} from '../../../../src/charging-station/ocpp/auth/index.js'
import {
OCPP16AuthorizationStatus,
OCPP16StandardParametersKey,
RequestParams,
} from '../../../../src/types/index.js'
-import { TransactionMeterValueDeliveryBarrier } from '../../../../src/charging-station/meter-values/TransactionMeterValueDeliveryBarrier.js'
+import { TransactionMeterValueDeliveryBarrier } from '../../../../src/charging-station/meter-values/index.js'
import { createTestableIncomingRequestService } from '../../../../src/charging-station/ocpp/1.6/__testable__/index.js'
import { OCPP16IncomingRequestService } from '../../../../src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.js'
import { OCPP16ServiceUtils } from '../../../../src/charging-station/ocpp/1.6/OCPP16ServiceUtils.js'
OCPPVersion,
type RequestParams,
} from '../../../../src/types/index.js'
+import { clone } from '../../../../src/utils/index.js'
import {
flushMicrotasks,
setupConnectorWithTransaction,
timestamp: new Date('2026-09-08T12:34:56.000Z'),
},
]
- const expectedTransactionData = structuredClone(transactionData)
+ const expectedTransactionData = clone(transactionData)
const stop = OCPP16ServiceUtils.stopTransactionOnConnector(station, 1, undefined, {
transactionData,
connectorId = 1,
reservationId = 1,
idTag = TEST_ID_TAG,
- expiryDate = new Date(Date.now() + 3600000)
+ expiryDate = new Date(Date.now() + Constants.MS_PER_HOUR)
) => ({
connectorId,
expiryDate,
import { afterEach, beforeEach, describe, it } from 'node:test'
import type { ChargingStation } from '../../../../src/charging-station/index.js'
-import type { LocalAuthListManager } from '../../../../src/charging-station/ocpp/auth/interfaces/OCPPAuthService.js'
+import type { LocalAuthListManager } from '../../../../src/charging-station/ocpp/auth/index.js'
import { buildConfigKey } from '../../../../src/charging-station/index.js'
import { createTestableIncomingRequestService } from '../../../../src/charging-station/ocpp/2.0/__testable__/index.js'
import { ChargingStation } from '../../../../src/charging-station/ChargingStation.js'
import { addConfigurationKey, buildConfigKey } from '../../../../src/charging-station/index.js'
-import { TransactionMeterValueDeliveryBarrier } from '../../../../src/charging-station/meter-values/TransactionMeterValueDeliveryBarrier.js'
+import { TransactionMeterValueDeliveryBarrier } from '../../../../src/charging-station/meter-values/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 { OCPP20ServiceUtils } from '../../../../src/charging-station/ocpp/2.0/OCPP20ServiceUtils.js'
import { afterEach, beforeEach, describe, it } from 'node:test'
import type { ChargingStation } from '../../../../src/charging-station/index.js'
-import type { AuthCache } from '../../../../src/charging-station/ocpp/auth/interfaces/OCPPAuthService.js'
+import type { AuthCache } from '../../../../src/charging-station/ocpp/auth/index.js'
import {
AuthResultStatus,
OCPP20TransactionEventEnumType,
OCPPVersion,
} from '../../../../src/types/index.js'
-import { Constants } from '../../../../src/utils/index.js'
+import { clone, Constants } from '../../../../src/utils/index.js'
import {
flushMicrotasks,
setupConnectorWithTransaction,
OCPP20TransactionEventEnumType.Started
)
staleRequest.seqNo = 0
- const replacementRequest = structuredClone(staleRequest)
+ const replacementRequest = clone(staleRequest)
connectorStatus.transactionEventQueue = [
{ request: replacementRequest, seqNo: 0, timestamp: replacementRequest.timestamp },
]
import assert from 'node:assert/strict'
import { afterEach, beforeEach, describe, it, mock } from 'node:test'
-import type { CoherentSession } from '../../../../src/charging-station/meter-values/types.js'
+import type { CoherentSession } from '../../../../src/charging-station/meter-values/index.js'
import type {
ChargingStationInfo,
ConnectorStatus,
getConfigurationKey,
} from '../../../../src/charging-station/index.js'
import { computeCoherentSample } from '../../../../src/charging-station/meter-values/CoherentSampleComputer.js'
-import { recordTransactionIntervalConsumption } from '../../../../src/charging-station/meter-values/TransactionIntervalUtils.js'
-import { TransactionMeterValueDeliveryBarrier } from '../../../../src/charging-station/meter-values/TransactionMeterValueDeliveryBarrier.js'
+import {
+ recordTransactionIntervalConsumption,
+ TransactionMeterValueDeliveryBarrier,
+} from '../../../../src/charging-station/meter-values/index.js'
import {
createTestableIncomingRequestService,
type TestableOCPP20IncomingRequestService,
SigningMethodEnumType,
Voltage,
} from '../../../../src/types/index.js'
-import { Constants } from '../../../../src/utils/index.js'
+import { clone, Constants } from '../../../../src/utils/index.js'
import {
setupConnectorWithTransaction,
standardCleanup,
unit: 'Wh',
},
] as unknown as EvseStatus['MeterValues']
- stationEvse.MeterValues = structuredClone(sharedMeterValues)
+ stationEvse.MeterValues = clone(sharedMeterValues)
evseStatus.MeterValues = sharedMeterValues
upsertConfigurationKey(mockStation, ALIGNED_DATA_INTERVAL_KEY, '60')
upsertConfigurationKey(mockStation, ALIGNED_ENABLED_KEY, 'true')
import { afterEach, beforeEach, describe, it } from 'node:test'
import type { ChargingStation } from '../../../../src/charging-station/index.js'
-import type { AuthCache } from '../../../../src/charging-station/ocpp/auth/interfaces/OCPPAuthService.js'
+import type { AuthCache } from '../../../../src/charging-station/ocpp/auth/index.js'
import { OCPP20ServiceUtils } from '../../../../src/charging-station/ocpp/2.0/OCPP20ServiceUtils.js'
import {
import assert from 'node:assert/strict'
import { afterEach, beforeEach, describe, it, mock } from 'node:test'
-import type { CoherentSession } from '../../../../src/charging-station/meter-values/types.js'
+import type { CoherentSession } from '../../../../src/charging-station/meter-values/index.js'
import type { ConnectorStatus, EmptyObject, EvseStatus } from '../../../../src/types/index.js'
import { ChargingStation } from '../../../../src/charging-station/ChargingStation.js'
preparePersistedTransactionEventQueue,
} from '../../../../src/charging-station/HelpersConnectorStatus.js'
import { addConfigurationKey, buildConfigKey } from '../../../../src/charging-station/index.js'
-import { recordTransactionIntervalConsumption } from '../../../../src/charging-station/meter-values/TransactionIntervalUtils.js'
-import { TransactionMeterValueDeliveryBarrier } from '../../../../src/charging-station/meter-values/TransactionMeterValueDeliveryBarrier.js'
+import {
+ recordTransactionIntervalConsumption,
+ TransactionMeterValueDeliveryBarrier,
+} from '../../../../src/charging-station/meter-values/index.js'
import { createTestableResponseService } from '../../../../src/charging-station/ocpp/2.0/__testable__/index.js'
import { buildOCPP20SampledValue } from '../../../../src/charging-station/ocpp/2.0/OCPP20RequestBuilders.js'
import { OCPP20ResponseService } from '../../../../src/charging-station/ocpp/2.0/OCPP20ResponseService.js'
SigningMethodEnumType,
Voltage,
} from '../../../../src/types/index.js'
-import { Constants, generateUUID } from '../../../../src/utils/index.js'
+import { clone, Constants, generateUUID } from '../../../../src/utils/index.js'
import {
flushMicrotasks,
setupConnectorWithTransaction,
requestParams.onTransportError?.(replayFailure, false)
throw replayFailure
}
- transportedRequests.push(structuredClone(request))
+ transportedRequests.push(clone(request))
requestParams.onMessageSent?.()
requestParams.onResponseReceived?.()
return {}
connectorStatus.transactionStarting = true
connectorStatus.transactionRestored = true
const queuedEvent = connectorStatus.transactionEventQueue[0]
- const originalPayload = structuredClone(queuedEvent.request)
+ const originalPayload = clone(queuedEvent.request)
const saveQueueSpy = mock.method(station, 'saveTransactionEventQueues')
online = true
64
)
const originalQueue = [queuedUpdated]
- const originalEvent = structuredClone(queuedUpdated)
+ const originalEvent = clone(queuedUpdated)
connectorStatus.transactionEventQueue = originalQueue
mock.method(mockTracking.station, 'persistTransactionEventQueues', () => {
persistenceStarted.resolve(undefined)
})
const savedQueues: unknown[][] = []
mock.method(mockTracking.station, 'saveTransactionEventQueues', () => {
- savedQueues.push(structuredClone(connectorStatus.transactionEventQueue ?? []))
+ savedQueues.push(clone(connectorStatus.transactionEventQueue ?? []))
})
const stopped = OCPP20ServiceUtils.requestStopTransaction(
64
)
const originalQueue = [queuedUpdated]
- const originalEvent = structuredClone(queuedUpdated)
+ const originalEvent = clone(queuedUpdated)
connectorStatus.transactionEventQueue = originalQueue
let persistenceCalls = 0
mock.method(mockTracking.station, 'persistTransactionEventQueues', () => {
timestamp: new Date(10_000),
},
]
- const originalEndedMeterValues = structuredClone(connectorStatus.transactionEndedMeterValues)
+ const originalEndedMeterValues = clone(connectorStatus.transactionEndedMeterValues)
OCPP20ServiceUtils.startEndedMeterValues(mockTracking.station, connectorId, 60_000, 1)
await assert.rejects(
import type { ChargingStation } from '../../../../src/charging-station/index.js'
import { InMemoryAuthCache } from '../../../../src/charging-station/ocpp/auth/cache/InMemoryAuthCache.js'
-import { OCPPAuthServiceImpl } from '../../../../src/charging-station/ocpp/auth/services/OCPPAuthServiceImpl.js'
-import { LocalAuthStrategy } from '../../../../src/charging-station/ocpp/auth/strategies/LocalAuthStrategy.js'
import {
AuthContext,
AuthenticationMethod,
AuthResultStatus,
IdentifierType,
-} from '../../../../src/charging-station/ocpp/auth/types/AuthTypes.js'
+} from '../../../../src/charging-station/ocpp/auth/index.js'
+import { OCPPAuthServiceImpl } from '../../../../src/charging-station/ocpp/auth/services/OCPPAuthServiceImpl.js'
+import { LocalAuthStrategy } from '../../../../src/charging-station/ocpp/auth/strategies/LocalAuthStrategy.js'
import { OCPPVersion } from '../../../../src/types/index.js'
import { standardCleanup } from '../../../helpers/TestLifecycleHelpers.js'
import { createMockChargingStation } from '../../helpers/StationHelpers.js'
AuthenticationMethod,
AuthResultStatus,
IdentifierType,
-} from '../../../../../src/charging-station/ocpp/auth/types/AuthTypes.js'
+} from '../../../../../src/charging-station/ocpp/auth/index.js'
import { OCPP16AuthorizationStatus, OCPPVersion } from '../../../../../src/types/index.js'
+import { Constants } from '../../../../../src/utils/index.js'
import { standardCleanup } from '../../../../helpers/TestLifecycleHelpers.js'
import { TEST_ID_TAG_VALID } from '../../../ChargingStationTestConstants.js'
import { createMockAuthorizationResult, createMockIdentifier } from '../helpers/MockFactories.js'
new Promise<OCPP16AuthorizeResponse>(resolve => {
resolve({
idTagInfo: {
- expiryDate: new Date(Date.now() + 86400000),
+ expiryDate: new Date(Date.now() + Constants.MS_PER_DAY),
parentIdTag: undefined,
status: OCPP16AuthorizationStatus.ACCEPTED,
},
AuthenticationMethod,
AuthResultStatus,
IdentifierType,
-} from '../../../../../src/charging-station/ocpp/auth/types/AuthTypes.js'
+} from '../../../../../src/charging-station/ocpp/auth/index.js'
import {
OCPP20AuthorizationStatusEnumType,
OCPP20IdTokenEnumType,
import assert from 'node:assert/strict'
import { afterEach, beforeEach, describe, it } from 'node:test'
-import type { AuthorizationResult } from '../../../../../src/charging-station/ocpp/auth/types/AuthTypes.js'
+import type { AuthorizationResult } from '../../../../../src/charging-station/ocpp/auth/index.js'
import { InMemoryAuthCache } from '../../../../../src/charging-station/ocpp/auth/cache/InMemoryAuthCache.js'
import {
AuthenticationMethod,
AuthResultStatus,
-} from '../../../../../src/charging-station/ocpp/auth/types/AuthTypes.js'
+} from '../../../../../src/charging-station/ocpp/auth/index.js'
import { standardCleanup, withMockTimers } from '../../../../helpers/TestLifecycleHelpers.js'
import { createMockAuthorizationResult } from '../helpers/MockFactories.js'
import assert from 'node:assert/strict'
import { afterEach, beforeEach, describe, it } from 'node:test'
-import type { DifferentialAuthEntry } from '../../../../../src/charging-station/ocpp/auth/interfaces/OCPPAuthService.js'
-import type { LocalAuthEntry } from '../../../../../src/charging-station/ocpp/auth/interfaces/OCPPAuthService.js'
+import type {
+ DifferentialAuthEntry,
+ LocalAuthEntry,
+} from '../../../../../src/charging-station/ocpp/auth/index.js'
-import { InMemoryLocalAuthListManager } from '../../../../../src/charging-station/ocpp/auth/cache/InMemoryLocalAuthListManager.js'
+import { InMemoryLocalAuthListManager } from '../../../../../src/charging-station/ocpp/auth/index.js'
import { standardCleanup } from '../../../../helpers/TestLifecycleHelpers.js'
const createEntry = (
AuthResultStatus,
IdentifierType,
} from '../../../../../src/charging-station/ocpp/auth/types/AuthTypes.js'
+import { Constants } from '../../../../../src/utils/index.js'
import { standardCleanup } from '../../../../helpers/TestLifecycleHelpers.js'
import {
createMockAuthCache,
await it('should authenticate using local auth list', () => {
mockLocalAuthListManager.getEntry = () => ({
- expiryDate: new Date(Date.now() + 86400000),
+ expiryDate: new Date(Date.now() + Constants.MS_PER_DAY),
identifier: 'LOCAL_TAG',
metadata: { source: 'local' },
status: 'accepted',
import type { AddressInfo } from 'node:net'
+import { format } from 'date-fns'
import assert from 'node:assert/strict'
import { request as httpRequest, type Server } from 'node:http'
import { join } from 'node:path'
await it('should return log content with default date (current local date)', async () => {
// Arrange
const now = new Date()
- const todayDate = `${now.getFullYear().toString()}-${(now.getMonth() + 1).toString().padStart(2, '0')}-${now.getDate().toString().padStart(2, '0')}`
+ const todayDate = format(now, 'yyyy-MM-dd')
writeTempFile(
logTmpDir,
`combined-${todayDate}.log`,
DEPRECATED_KEY_REMAPPINGS,
} from '../../src/utils/index.js'
import { ConfigurationValidationError, validateConfiguration } from '../../src/utils/index.js'
-import { logger } from '../../src/utils/index.js'
+import { clone, logger } from '../../src/utils/index.js'
import { standardCleanup } from '../helpers/TestLifecycleHelpers.js'
import {
buildLegacyConfiguration,
await it('should not mutate the caller-supplied parsed object', t => {
t.mock.method(console, 'warn', () => undefined)
const parsed = buildLegacyConfiguration()
- const before = structuredClone(parsed)
+ const before = clone(parsed)
validateConfiguration(parsed, 'immutable.json')
import assert from 'node:assert'
import { describe, it } from 'node:test'
-import { OCPP16AvailabilityType, OCPP16ChargePointStatus, ResponseStatus } from 'ui-common'
+import {
+ OCPP16AvailabilityType,
+ OCPP16ChargePointStatus,
+ ResponseStatus,
+ WebSocketReadyState,
+} from 'ui-common'
import { tryRenderPayload } from '../src/output/renderers.js'
import { captureStream } from './helpers.js'
ocppVersion: '2.0.1',
templateName: 'test.station-template',
},
- wsState: 1,
+ wsState: WebSocketReadyState.OPEN,
},
],
status: ResponseStatus.SUCCESS,
): RequestPayload {
if (isOCPP20x(ocppVersion)) {
return {
- idToken: { idToken: idTag, type: OCPP20IdTokenEnumType.ISO14443 },
+ idToken: buildIdToken(idTag),
}
}
assertOCPP16OrUndefined(ocppVersion)
connectorId,
eventType: OCPP20TransactionEventEnumType.STARTED,
...(options?.evseId != null && { evseId: options.evseId }),
- ...(options?.idTag != null && {
- idToken: { idToken: options.idTag, type: OCPP20IdTokenEnumType.ISO14443 },
- }),
+ ...(options?.idTag != null && { idToken: buildIdToken(options.idTag) }),
},
procedureName: ProcedureName.TRANSACTION_EVENT,
}
/** @file Shared mock factories for WebSocket-based tests */
-import type { WebSocketLike } from '../src/client/types.js'
+import { type WebSocketLike, WebSocketReadyState } from '../src/client/types.js'
export interface MockWebSocketLike extends WebSocketLike {
sentMessages: string[]
let onmessageFn: ((event: { data: string }) => void) | null = null
let onopenFn: (() => void) | null = null
const sentMessages: string[] = []
- let readyState: 0 | 1 | 2 | 3 = 1
+ let readyState: WebSocketReadyState = WebSocketReadyState.OPEN
return {
close (code?: number, reason?: string) {
- readyState = 3
+ readyState = WebSocketReadyState.CLOSED
oncloseFn?.({ code: code ?? 1000, reason: reason ?? '' })
},
get onclose () {
},
sentMessages,
triggerClose (code?: number, reason?: string) {
- readyState = 3
+ readyState = WebSocketReadyState.CLOSED
oncloseFn?.({ code: code ?? 1000, reason: reason ?? '' })
},
triggerError (message) {
* These are not Vue composables (no reactive state) — they are pure utility functions
* consumed exclusively by skin components via the shared layer.
*/
-import type { ChargingStationData, ConnectorEntry, Status } from 'ui-common'
+import {
+ type ChargingStationData,
+ type ConnectorEntry,
+ type Status,
+ WebSocketReadyState,
+} from 'ui-common'
/**
* Status variant type for UI display.
return CONNECTOR_STATUS_VARIANT[status.toLowerCase()] ?? 'idle'
}
-const WS_STATE_CLOSED = 3
-const WS_STATE_CLOSING = 2
-const WS_STATE_CONNECTING = 0
-const WS_STATE_OPEN = 1
-
/**
* Maps a WebSocket ready state to a display variant.
* @param wsState - The WebSocket readyState value
*/
export function getWebSocketStateVariant (wsState?: number): StatusVariant {
switch (wsState) {
- case WS_STATE_CLOSED:
+ case WebSocketReadyState.CLOSED:
return 'err'
- case WS_STATE_CLOSING:
+ case WebSocketReadyState.CLOSING:
return 'warn'
- case WS_STATE_CONNECTING:
+ case WebSocketReadyState.CONNECTING:
return 'warn'
- case WS_STATE_OPEN:
+ case WebSocketReadyState.OPEN:
return 'ok'
default:
return 'idle'
* @file Shared test utilities for Vue.js web UI unit tests
* @description MockWebSocket, withSetup composable helper, mock factories.
*/
-import { ResponseStatus } from 'ui-common'
+import { ResponseStatus, WebSocketReadyState } from 'ui-common'
import { vi } from 'vitest'
import { type App, createApp } from 'vue'
// ── MockWebSocket ─────────────────────────────────────────────────────────────
export class MockWebSocket {
- static readonly CLOSED = 3
- static readonly CLOSING = 2
- static readonly CONNECTING = 0
+ static readonly CLOSED = WebSocketReadyState.CLOSED
+ static readonly CLOSING = WebSocketReadyState.CLOSING
static lastInstance: MockWebSocket | null = null
- static readonly OPEN = 1
+ static readonly OPEN = WebSocketReadyState.OPEN
addEventListener: ReturnType<typeof vi.fn>
close: ReturnType<typeof vi.fn>
- readonly CLOSED = 3
- readonly CLOSING = 2
- readonly CONNECTING = 0
+ readonly CLOSED = WebSocketReadyState.CLOSED
+ readonly CLOSING = WebSocketReadyState.CLOSING
onclose: ((event: CloseEvent) => void) | null = null
onerror: ((event: Event) => void) | null = null
onmessage: ((event: MessageEvent) => void) | null = null
onopen: (() => void) | null = null
- readonly OPEN = 1
- readyState: number = MockWebSocket.CONNECTING
+ readonly OPEN = WebSocketReadyState.OPEN
+ readyState: number = WebSocketReadyState.CONNECTING
removeEventListener: ReturnType<typeof vi.fn>
send: ReturnType<typeof vi.fn>
sentMessages: string[] = []