1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | 'use strict'
|
34 |
|
35 | const Test = require('tape')
|
36 | const ErrorEnums = require('../src/enums')
|
37 |
|
38 | Test('Enum should', enumTest => {
|
39 | enumTest.test('return correct error code string', function (test) {
|
40 | const fspiopErrorCode = ErrorEnums.findFSPIOPErrorCode(ErrorEnums.FSPIOPErrorCodes.PAYEE_FSP_INSUFFICIENT_LIQUIDITY.code)
|
41 | test.ok(fspiopErrorCode)
|
42 | test.equal(fspiopErrorCode.code, ErrorEnums.FSPIOPErrorCodes.PAYEE_FSP_INSUFFICIENT_LIQUIDITY.code)
|
43 | test.equal(fspiopErrorCode.message, ErrorEnums.FSPIOPErrorCodes.PAYEE_FSP_INSUFFICIENT_LIQUIDITY.message)
|
44 | test.end()
|
45 | })
|
46 |
|
47 | enumTest.test('return correct error code integer', function (test) {
|
48 | const fspiopErrorCode = ErrorEnums.findFSPIOPErrorCode(parseInt(ErrorEnums.FSPIOPErrorCodes.PAYEE_FSP_INSUFFICIENT_LIQUIDITY.code))
|
49 | test.ok(fspiopErrorCode)
|
50 | test.equal(fspiopErrorCode.code, ErrorEnums.FSPIOPErrorCodes.PAYEE_FSP_INSUFFICIENT_LIQUIDITY.code)
|
51 | test.equal(fspiopErrorCode.message, ErrorEnums.FSPIOPErrorCodes.PAYEE_FSP_INSUFFICIENT_LIQUIDITY.message)
|
52 | test.end()
|
53 | })
|
54 |
|
55 | enumTest.test('return undefined result with incorrect error code', function (test) {
|
56 | const fspiopErrorCode = ErrorEnums.findFSPIOPErrorCode(parseInt('9999'))
|
57 | test.equals(fspiopErrorCode, undefined)
|
58 | test.end()
|
59 | })
|
60 |
|
61 | enumTest.test('test FSPIOPErrorTypes are correctly added to FSPIOPErrorCodes by validating each entry by its associated regex', function (test) {
|
62 | const fspiopErrorCode = ErrorEnums.findFSPIOPErrorCode(ErrorEnums.FSPIOPErrorCodes.PAYEE_FSP_INSUFFICIENT_LIQUIDITY.code)
|
63 | for (const errorCodeValue of Object.values(ErrorEnums.FSPIOPErrorCodes)) {
|
64 | const regExp = new RegExp(errorCodeValue.type.regex)
|
65 | test.ok(regExp.test(errorCodeValue.code))
|
66 | }
|
67 | test.ok(fspiopErrorCode)
|
68 | test.equal(fspiopErrorCode.code, ErrorEnums.FSPIOPErrorCodes.PAYEE_FSP_INSUFFICIENT_LIQUIDITY.code)
|
69 | test.equal(fspiopErrorCode.message, ErrorEnums.FSPIOPErrorCodes.PAYEE_FSP_INSUFFICIENT_LIQUIDITY.message)
|
70 | test.end()
|
71 | })
|
72 |
|
73 | enumTest.test('test FSPIOPErrorCodeMaps contains every error found in the FSPIOPErrorCodes object using the findFSPIOPErrorCode method', function (test) {
|
74 | for (const errorCodeValue of Object.values(ErrorEnums.FSPIOPErrorCodes)) {
|
75 | const errorCodeResult = ErrorEnums.findFSPIOPErrorCode(errorCodeValue.code)
|
76 | test.ok(errorCodeResult)
|
77 | }
|
78 | test.end()
|
79 | })
|
80 |
|
81 | enumTest.test('populateOverrides redefines existing errors and allows adding new errors', function (test) {
|
82 | const errorCodes = {
|
83 | INTERNAL_SERVER_ERROR: { code: '2001', message: 'Internal Server Error' }
|
84 | }
|
85 | const override = {
|
86 | INTERNAL_SERVER_ERROR: { code: '9000' },
|
87 | NEW_CUSTOM_ERROR: { code: '9001', message: 'Custom Error' }
|
88 | }
|
89 | const expected = {
|
90 | INTERNAL_SERVER_ERROR: { code: '9000', message: 'Internal Server Error' },
|
91 | NEW_CUSTOM_ERROR: { code: '9001', message: 'Custom Error' }
|
92 | }
|
93 |
|
94 | const result = ErrorEnums._populateOverrides(errorCodes, override)
|
95 | test.deepEqual(result, expected)
|
96 | test.end()
|
97 | })
|
98 |
|
99 | enumTest.end()
|
100 | })
|