1 /* eslint-disable @typescript-eslint/no-unsafe-member-access */
2 import { describe
, it
} from
'node:test'
4 import { expect
} from
'expect'
6 import type { ChargingStation
} from
'../../src/charging-station/index.js'
10 IncomingRequestCommand
,
13 } from
'../../src/types/index.js'
16 handleIncomingRequestError
,
17 handleSendMessageError
18 } from
'../../src/utils/ErrorUtils.js'
19 import { logger
} from
'../../src/utils/Logger.js'
21 await describe('ErrorUtils test suite', async () => {
22 // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
23 const chargingStation
= {
24 logPrefix
: () => 'CS-TEST |'
27 await it('Verify handleFileException()', t
=> {
28 t
.mock
.method(console
, 'warn')
29 t
.mock
.method(console
, 'error')
30 t
.mock
.method(logger
, 'warn')
31 t
.mock
.method(logger
, 'error')
32 const error
= new Error()
35 handleFileException('path/to/module.js', FileType
.Authorization
, error
, 'log prefix |', {})
38 handleFileException('path/to/module.js', FileType
.Authorization
, error
, 'log prefix |', {
42 expect(logger
.warn
.mock
.calls
.length
).toBe(1)
43 expect(logger
.error
.mock
.calls
.length
).toBe(1)
45 handleFileException('path/to/module.js', FileType
.Authorization
, error
, 'log prefix |', {
50 handleFileException('path/to/module.js', FileType
.Authorization
, error
, 'log prefix |', {
55 expect(console
.warn
.mock
.calls
.length
).toBe(1)
56 expect(console
.error
.mock
.calls
.length
).toBe(1)
59 await it('Verify handleSendMessageError()', t
=> {
60 t
.mock
.method(logger
, 'error')
61 t
.mock
.method(chargingStation
, 'logPrefix')
62 const error
= new Error()
64 handleSendMessageError(
66 RequestCommand
.BOOT_NOTIFICATION
,
67 MessageType
.CALL_MESSAGE
,
72 handleSendMessageError(
74 RequestCommand
.BOOT_NOTIFICATION
,
75 MessageType
.CALL_MESSAGE
,
80 expect(chargingStation
.logPrefix
.mock
.calls
.length
).toBe(2)
81 expect(logger
.error
.mock
.calls
.length
).toBe(2)
84 await it('Verify handleIncomingRequestError()', t
=> {
85 t
.mock
.method(logger
, 'error')
86 t
.mock
.method(chargingStation
, 'logPrefix')
87 const error
= new Error()
89 handleIncomingRequestError(chargingStation
, IncomingRequestCommand
.CLEAR_CACHE
, error
)
92 handleIncomingRequestError(chargingStation
, IncomingRequestCommand
.CLEAR_CACHE
, error
, {
96 const errorResponse
= {
97 status: GenericStatus
.Rejected
100 handleIncomingRequestError(chargingStation
, IncomingRequestCommand
.CLEAR_CACHE
, error
, {
104 ).toStrictEqual(errorResponse
)
105 expect(chargingStation
.logPrefix
.mock
.calls
.length
).toBe(3)
106 expect(logger
.error
.mock
.calls
.length
).toBe(3)