907d05fad5f136fbfed17f7fe527a813aa8114e9
[e-mobility-charging-stations-simulator.git] / tests / utils / ErrorUtils.test.ts
1 import { describe, it } from 'node:test'
2
3 import { expect } from 'expect'
4
5 import { FileType } from '../../src/types/index.js'
6 import { handleFileException, setDefaultErrorParams } from '../../src/utils/ErrorUtils.js'
7
8 await describe('ErrorUtils test suite', async () => {
9 await it('Verify handleFileException()', () => {
10 const error = new Error()
11 error.code = 'ENOENT'
12 expect(() => {
13 handleFileException('path/to/module.js', FileType.Authorization, error, 'log prefix |', {})
14 }).toThrow(error)
15 expect(() => {
16 handleFileException('path/to/module.js', FileType.Authorization, error, 'log prefix |', {
17 throwError: false
18 })
19 }).not.toThrow()
20 })
21
22 await it('Verify setDefaultErrorParams()', () => {
23 expect(setDefaultErrorParams({})).toStrictEqual({ throwError: true, consoleOut: false })
24 expect(setDefaultErrorParams({ throwError: false })).toStrictEqual({
25 throwError: false,
26 consoleOut: false
27 })
28 expect(setDefaultErrorParams({ throwError: false, consoleOut: true })).toStrictEqual({
29 throwError: false,
30 consoleOut: true
31 })
32 expect(setDefaultErrorParams({ throwError: true, consoleOut: true })).toStrictEqual({
33 throwError: true,
34 consoleOut: true
35 })
36 expect(setDefaultErrorParams({}, { throwError: false, consoleOut: false })).toStrictEqual({
37 throwError: false,
38 consoleOut: false
39 })
40 })
41 })