1 import { describe
, it
} from
'node:test'
3 import { expect
} from
'expect'
5 import type { ChargingStation
} from
'../../src/charging-station/index.js'
9 IncomingRequestCommand
,
12 } from
'../../src/types/index.js'
15 handleIncomingRequestError
,
16 handleSendMessageError
,
18 } from
'../../src/utils/ErrorUtils.js'
20 await describe('ErrorUtils test suite', async () => {
21 // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
22 const chargingStation
= {
23 logPrefix
: () => 'CS-TEST |'
26 await it('Verify handleFileException()', () => {
27 const error
= new Error()
30 handleFileException('path/to/module.js', FileType
.Authorization
, error
, 'log prefix |', {})
33 handleFileException('path/to/module.js', FileType
.Authorization
, error
, 'log prefix |', {
39 await it('Verify handleSendMessageError()', () => {
40 const error
= new Error()
42 handleSendMessageError(
44 RequestCommand
.BOOT_NOTIFICATION
,
45 MessageType
.CALL_MESSAGE
,
50 handleSendMessageError(
52 RequestCommand
.BOOT_NOTIFICATION
,
53 MessageType
.CALL_MESSAGE
,
60 await it('Verify handleIncomingRequestError()', () => {
61 const error
= new Error()
63 handleIncomingRequestError(chargingStation
, IncomingRequestCommand
.CLEAR_CACHE
, error
)
66 handleIncomingRequestError(chargingStation
, IncomingRequestCommand
.CLEAR_CACHE
, error
, {
70 const errorResponse
= {
71 status: GenericStatus
.Rejected
74 handleIncomingRequestError(chargingStation
, IncomingRequestCommand
.CLEAR_CACHE
, error
, {
78 ).toStrictEqual(errorResponse
)
81 await it('Verify setDefaultErrorParams()', () => {
82 expect(setDefaultErrorParams({})).toStrictEqual({ throwError
: true, consoleOut
: false })
83 expect(setDefaultErrorParams({ throwError
: false })).toStrictEqual({
87 expect(setDefaultErrorParams({ throwError
: false, consoleOut
: true })).toStrictEqual({
91 expect(setDefaultErrorParams({ throwError
: true, consoleOut
: true })).toStrictEqual({
95 expect(setDefaultErrorParams({}, { throwError
: false, consoleOut
: false })).toStrictEqual({