1 /* eslint-disable @typescript-eslint/no-unsafe-member-access */
2 import { expect
} from
'expect'
3 import { describe
, it
} from
'node:test'
5 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 const chargingStation
= {
23 logPrefix
: () => 'CS-TEST |',
26 await it('Verify handleFileException()', t
=> {
27 t
.mock
.method(console
, 'warn')
28 t
.mock
.method(console
, 'error')
29 t
.mock
.method(logger
, 'warn')
30 t
.mock
.method(logger
, 'error')
31 const error
= new Error()
34 handleFileException('path/to/module.js', FileType
.Authorization
, error
, 'log prefix |', {})
37 handleFileException('path/to/module.js', FileType
.Authorization
, error
, 'log prefix |', {
41 expect(logger
.warn
.mock
.calls
.length
).toBe(1)
42 expect(logger
.error
.mock
.calls
.length
).toBe(1)
44 handleFileException('path/to/module.js', FileType
.Authorization
, error
, 'log prefix |', {
49 handleFileException('path/to/module.js', FileType
.Authorization
, error
, 'log prefix |', {
54 expect(console
.warn
.mock
.calls
.length
).toBe(1)
55 expect(console
.error
.mock
.calls
.length
).toBe(1)
58 await it('Verify handleSendMessageError()', t
=> {
59 t
.mock
.method(logger
, 'error')
60 t
.mock
.method(chargingStation
, 'logPrefix')
61 const error
= new Error()
63 handleSendMessageError(
65 RequestCommand
.BOOT_NOTIFICATION
,
66 MessageType
.CALL_MESSAGE
,
71 handleSendMessageError(
73 RequestCommand
.BOOT_NOTIFICATION
,
74 MessageType
.CALL_MESSAGE
,
79 expect(chargingStation
.logPrefix
.mock
.calls
.length
).toBe(2)
80 expect(logger
.error
.mock
.calls
.length
).toBe(2)
83 await it('Verify handleIncomingRequestError()', t
=> {
84 t
.mock
.method(logger
, 'error')
85 t
.mock
.method(chargingStation
, 'logPrefix')
86 const error
= new Error()
88 handleIncomingRequestError(chargingStation
, IncomingRequestCommand
.CLEAR_CACHE
, error
)
91 handleIncomingRequestError(chargingStation
, IncomingRequestCommand
.CLEAR_CACHE
, error
, {
95 const errorResponse
= {
96 status: GenericStatus
.Rejected
,
99 handleIncomingRequestError(chargingStation
, IncomingRequestCommand
.CLEAR_CACHE
, error
, {
103 ).toStrictEqual(errorResponse
)
104 expect(chargingStation
.logPrefix
.mock
.calls
.length
).toBe(3)
105 expect(logger
.error
.mock
.calls
.length
).toBe(3)