@creator.co/wapi 1.2.5 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +216 -5
- package/dist/index.d.ts +15 -0
- package/dist/index.js.map +1 -1
- package/dist/package.json +6 -1
- package/dist/src/API/Request.d.ts +45 -82
- package/dist/src/API/Request.js +49 -77
- package/dist/src/API/Request.js.map +1 -1
- package/dist/src/API/Response.d.ts +94 -163
- package/dist/src/API/Response.js +101 -161
- package/dist/src/API/Response.js.map +1 -1
- package/dist/src/API/Utils.d.ts +21 -42
- package/dist/src/API/Utils.js +22 -43
- package/dist/src/API/Utils.js.map +1 -1
- package/dist/src/BaseEvent/EventProcessor.d.ts +32 -55
- package/dist/src/BaseEvent/EventProcessor.js +30 -38
- package/dist/src/BaseEvent/EventProcessor.js.map +1 -1
- package/dist/src/BaseEvent/Process.d.ts +20 -43
- package/dist/src/BaseEvent/Process.js +16 -27
- package/dist/src/BaseEvent/Process.js.map +1 -1
- package/dist/src/BaseEvent/Transaction.d.ts +94 -2
- package/dist/src/BaseEvent/Transaction.js +49 -4
- package/dist/src/BaseEvent/Transaction.js.map +1 -1
- package/dist/src/Config/Configuration.d.ts +48 -66
- package/dist/src/Config/Configuration.js +25 -42
- package/dist/src/Config/Configuration.js.map +1 -1
- package/dist/src/Config/EnvironmentVar.d.ts +30 -57
- package/dist/src/Config/EnvironmentVar.js +28 -41
- package/dist/src/Config/EnvironmentVar.js.map +1 -1
- package/dist/src/Crypto/Crypto.d.ts +17 -35
- package/dist/src/Crypto/Crypto.js +12 -21
- package/dist/src/Crypto/Crypto.js.map +1 -1
- package/dist/src/Crypto/JWT.d.ts +21 -32
- package/dist/src/Crypto/JWT.js +14 -22
- package/dist/src/Crypto/JWT.js.map +1 -1
- package/dist/src/Globals.d.ts +26 -94
- package/dist/src/Globals.js +26 -95
- package/dist/src/Globals.js.map +1 -1
- package/dist/src/Logger/Logger.d.ts +82 -105
- package/dist/src/Logger/Logger.js +111 -136
- package/dist/src/Logger/Logger.js.map +1 -1
- package/dist/src/Mailer/Mailer.d.ts +39 -75
- package/dist/src/Mailer/Mailer.js +36 -65
- package/dist/src/Mailer/Mailer.js.map +1 -1
- package/dist/src/Publisher/Publisher.d.ts +17 -25
- package/dist/src/Publisher/Publisher.js +21 -32
- package/dist/src/Publisher/Publisher.js.map +1 -1
- package/dist/src/Server/RouteResolver.d.ts +14 -22
- package/dist/src/Server/RouteResolver.js +21 -34
- package/dist/src/Server/RouteResolver.js.map +1 -1
- package/dist/src/Server/Router.d.ts +72 -51
- package/dist/src/Server/Router.js +8 -17
- package/dist/src/Server/Router.js.map +1 -1
- package/dist/src/Server/lib/ContainerServer.d.ts +15 -31
- package/dist/src/Server/lib/ContainerServer.js +13 -28
- package/dist/src/Server/lib/ContainerServer.js.map +1 -1
- package/dist/src/Server/lib/Server.d.ts +17 -32
- package/dist/src/Server/lib/Server.js +18 -28
- package/dist/src/Server/lib/Server.js.map +1 -1
- package/dist/src/Server/lib/container/GenericHandler.d.ts +5 -0
- package/dist/src/Server/lib/container/GenericHandler.js +16 -3
- package/dist/src/Server/lib/container/GenericHandler.js.map +1 -1
- package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +22 -37
- package/dist/src/Server/lib/container/GenericHandlerEvent.js +29 -41
- package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -1
- package/dist/src/Server/lib/container/HealthHandler.d.ts +6 -0
- package/dist/src/Server/lib/container/HealthHandler.js +6 -0
- package/dist/src/Server/lib/container/HealthHandler.js.map +1 -1
- package/dist/src/Server/lib/container/Proxy.d.ts +24 -52
- package/dist/src/Server/lib/container/Proxy.js +49 -50
- package/dist/src/Server/lib/container/Proxy.js.map +1 -1
- package/dist/src/Server/lib/container/Utils.d.ts +6 -10
- package/dist/src/Server/lib/container/Utils.js +6 -10
- package/dist/src/Server/lib/container/Utils.js.map +1 -1
- package/dist/src/Validation/Validator.d.ts +9 -13
- package/dist/src/Validation/Validator.js +8 -12
- package/dist/src/Validation/Validator.js.map +1 -1
- package/index.ts +15 -0
- package/package.json +6 -1
- package/src/API/Request.ts +66 -84
- package/src/API/Response.ts +144 -203
- package/src/API/Utils.ts +28 -44
- package/src/BaseEvent/EventProcessor.ts +52 -77
- package/src/BaseEvent/Process.ts +27 -52
- package/src/BaseEvent/Transaction.ts +100 -10
- package/src/Config/Configuration.ts +59 -76
- package/src/Config/EnvironmentVar.ts +39 -62
- package/src/Crypto/Crypto.ts +20 -36
- package/src/Crypto/JWT.ts +31 -35
- package/src/Globals.ts +28 -96
- package/src/Logger/Logger.ts +141 -160
- package/src/Mailer/Mailer.ts +43 -76
- package/src/Publisher/Publisher.ts +31 -40
- package/src/Server/RouteResolver.ts +31 -52
- package/src/Server/Router.ts +75 -54
- package/src/Server/lib/ContainerServer.ts +20 -32
- package/src/Server/lib/Server.ts +19 -34
- package/src/Server/lib/container/GenericHandler.ts +17 -3
- package/src/Server/lib/container/GenericHandlerEvent.ts +44 -54
- package/src/Server/lib/container/HealthHandler.ts +6 -0
- package/src/Server/lib/container/Proxy.ts +37 -57
- package/src/Server/lib/container/Utils.ts +7 -10
- package/src/Validation/Validator.ts +11 -13
- package/tests/API/Response.test.ts +55 -56
- package/tests/BaseEvent/EventProcessor.test.ts +49 -50
- package/tests/BaseEvent/Process.test.ts +2 -2
- package/tests/BaseEvent/Transaction.test.ts +48 -49
- package/tests/Config/Config.test.ts +27 -27
- package/tests/Config/EnvironmentVar.test.ts +54 -18
- package/tests/Publisher/Publisher.test.ts +3 -3
- package/tests/Server/lib/ContainerServer.test.ts +21 -22
- package/tests/Server/lib/container/GenericHandler.test.ts +31 -32
- package/tests/Server/lib/container/GenericHandlerEvent.test.ts +2 -2
- package/tests/Server/lib/container/HealthHandler.test.ts +6 -7
- package/tests/Server/lib/container/Proxy.test.ts +37 -35
- package/tsconfig.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SSMClient, GetParameterCommand } from '@aws-sdk/client-ssm'
|
|
2
2
|
import { mockClient } from 'aws-sdk-client-mock'
|
|
3
|
-
import { expect } from 'chai'
|
|
3
|
+
import { expect as c_expect } from 'chai'
|
|
4
4
|
|
|
5
5
|
import Configuration from '../../src/Config/Configuration'
|
|
6
6
|
import { SampleConfig, SampleConfigSchema } from '../Test.utils'
|
|
@@ -22,8 +22,8 @@ describe(`Optional remote environment`, () => {
|
|
|
22
22
|
} catch (e) {
|
|
23
23
|
err = e
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
c_expect(err).is.not.null
|
|
26
|
+
c_expect(err?.['message']).is.not.null
|
|
27
27
|
})
|
|
28
28
|
|
|
29
29
|
test('Optional value with null value', async () => {
|
|
@@ -33,13 +33,13 @@ describe(`Optional remote environment`, () => {
|
|
|
33
33
|
},
|
|
34
34
|
})
|
|
35
35
|
const token = await config.asyncGet('TOKEN_SECRET_FALSY')
|
|
36
|
-
|
|
36
|
+
c_expect(token).is.undefined
|
|
37
37
|
})
|
|
38
38
|
|
|
39
39
|
test('Optional value with empty response', async () => {
|
|
40
40
|
SSMMock.on(GetParameterCommand).resolves({})
|
|
41
41
|
const token = await config.asyncGet('TOKEN_SECRET_FALSY')
|
|
42
|
-
|
|
42
|
+
c_expect(token).is.undefined
|
|
43
43
|
})
|
|
44
44
|
|
|
45
45
|
test('Optional value with valid response', async () => {
|
|
@@ -50,14 +50,14 @@ describe(`Optional remote environment`, () => {
|
|
|
50
50
|
},
|
|
51
51
|
})
|
|
52
52
|
const token = await config.asyncGet('TOKEN_SECRET_FALSY')
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
c_expect(token).is.not.undefined
|
|
54
|
+
c_expect(token).to.be.equals(value)
|
|
55
55
|
})
|
|
56
56
|
|
|
57
57
|
test('Optional value rejection', async () => {
|
|
58
58
|
SSMMock.on(GetParameterCommand).rejects(new Error('failed!'))
|
|
59
59
|
const token = await config.asyncGet('TOKEN_SECRET_FALSY')
|
|
60
|
-
|
|
60
|
+
c_expect(token).is.undefined
|
|
61
61
|
})
|
|
62
62
|
})
|
|
63
63
|
|
|
@@ -76,8 +76,8 @@ describe(`Required remote environment`, () => {
|
|
|
76
76
|
} catch (e) {
|
|
77
77
|
err = e
|
|
78
78
|
}
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
c_expect(err).is.not.null
|
|
80
|
+
c_expect(err?.['message']).is.not.null
|
|
81
81
|
})
|
|
82
82
|
|
|
83
83
|
test('Required value with null value', async () => {
|
|
@@ -92,8 +92,8 @@ describe(`Required remote environment`, () => {
|
|
|
92
92
|
} catch (e) {
|
|
93
93
|
err = e
|
|
94
94
|
}
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
c_expect(err).is.not.null
|
|
96
|
+
c_expect(err?.['message']).is.not.null
|
|
97
97
|
})
|
|
98
98
|
|
|
99
99
|
test('Required value with empty response', async () => {
|
|
@@ -104,8 +104,8 @@ describe(`Required remote environment`, () => {
|
|
|
104
104
|
} catch (e) {
|
|
105
105
|
err = e
|
|
106
106
|
}
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
c_expect(err).is.not.null
|
|
108
|
+
c_expect(err?.['message']).is.not.null
|
|
109
109
|
})
|
|
110
110
|
|
|
111
111
|
test('Required value with valid response', async () => {
|
|
@@ -116,8 +116,8 @@ describe(`Required remote environment`, () => {
|
|
|
116
116
|
},
|
|
117
117
|
})
|
|
118
118
|
const token = await config.asyncGet('TOKEN_SECRET')
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
c_expect(token).is.not.undefined
|
|
120
|
+
c_expect(token).to.be.equals(value)
|
|
121
121
|
})
|
|
122
122
|
|
|
123
123
|
test('Required value rejection', async () => {
|
|
@@ -128,8 +128,8 @@ describe(`Required remote environment`, () => {
|
|
|
128
128
|
} catch (e) {
|
|
129
129
|
err = e
|
|
130
130
|
}
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
c_expect(err).is.not.null
|
|
132
|
+
c_expect(err?.['message']).is.not.null
|
|
133
133
|
})
|
|
134
134
|
})
|
|
135
135
|
|
|
@@ -140,7 +140,7 @@ describe(`Optional local environment`, () => {
|
|
|
140
140
|
|
|
141
141
|
test('Optional value with null value', async () => {
|
|
142
142
|
const token = config.get('PATH123')
|
|
143
|
-
|
|
143
|
+
c_expect(token).is.undefined
|
|
144
144
|
})
|
|
145
145
|
})
|
|
146
146
|
|
|
@@ -156,15 +156,15 @@ describe(`Required local environment`, () => {
|
|
|
156
156
|
} catch (e) {
|
|
157
157
|
err = e
|
|
158
158
|
}
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
c_expect(err).is.not.null
|
|
160
|
+
c_expect(err?.['message']).is.not.null
|
|
161
161
|
})
|
|
162
162
|
|
|
163
163
|
test('Required value with valid response', async () => {
|
|
164
164
|
const key = 'PATH'
|
|
165
165
|
const v = config.get(key)
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
c_expect(v).is.not.null
|
|
167
|
+
c_expect(v).to.be.equals(process.env[key])
|
|
168
168
|
})
|
|
169
169
|
})
|
|
170
170
|
|
|
@@ -179,14 +179,14 @@ describe(`Caching test`, () => {
|
|
|
179
179
|
},
|
|
180
180
|
})
|
|
181
181
|
const v = await config.asyncGet(key)
|
|
182
|
-
|
|
183
|
-
|
|
182
|
+
c_expect(v).is.not.null
|
|
183
|
+
c_expect(v).to.be.equals(value)
|
|
184
184
|
// subsequent fetch
|
|
185
185
|
SSMMock.reset()
|
|
186
186
|
SSMMock.on(GetParameterCommand).rejects(new Error('failed!'))
|
|
187
187
|
const v2 = await config.asyncGet(key)
|
|
188
|
-
|
|
189
|
-
|
|
188
|
+
c_expect(v2).is.not.null
|
|
189
|
+
c_expect(v2).to.be.equals(value)
|
|
190
190
|
})
|
|
191
191
|
})
|
|
192
192
|
|
|
@@ -17,9 +17,15 @@ function testRemoteEnv(mock, type, command) {
|
|
|
17
17
|
|
|
18
18
|
test('Does not accept sync resolve', async () => {
|
|
19
19
|
mock.on(command).resolves({
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
...(type == EnvironmentType.PlainRemote
|
|
21
|
+
? {
|
|
22
|
+
Parameter: {
|
|
23
|
+
Value: undefined,
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
: {
|
|
27
|
+
SecretString: undefined,
|
|
28
|
+
}),
|
|
23
29
|
})
|
|
24
30
|
let err = null
|
|
25
31
|
try {
|
|
@@ -34,9 +40,15 @@ function testRemoteEnv(mock, type, command) {
|
|
|
34
40
|
|
|
35
41
|
test('Optional value with null value', async () => {
|
|
36
42
|
mock.on(command).resolves({
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
...(type == EnvironmentType.PlainRemote
|
|
44
|
+
? {
|
|
45
|
+
Parameter: {
|
|
46
|
+
Value: undefined,
|
|
47
|
+
},
|
|
48
|
+
}
|
|
49
|
+
: {
|
|
50
|
+
SecretString: undefined,
|
|
51
|
+
}),
|
|
40
52
|
})
|
|
41
53
|
const env = new EnvironmentVar('abc', type, true)
|
|
42
54
|
const token = await env.resolve()
|
|
@@ -53,9 +65,15 @@ function testRemoteEnv(mock, type, command) {
|
|
|
53
65
|
test('Optional value with valid response', async () => {
|
|
54
66
|
const value = 'abc'
|
|
55
67
|
mock.on(command).resolves({
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
68
|
+
...(type == EnvironmentType.PlainRemote
|
|
69
|
+
? {
|
|
70
|
+
Parameter: {
|
|
71
|
+
Value: value,
|
|
72
|
+
},
|
|
73
|
+
}
|
|
74
|
+
: {
|
|
75
|
+
SecretString: value,
|
|
76
|
+
}),
|
|
59
77
|
})
|
|
60
78
|
const env = new EnvironmentVar(value, type, true)
|
|
61
79
|
const token = await env.resolve()
|
|
@@ -80,9 +98,15 @@ function testRemoteEnv(mock, type, command) {
|
|
|
80
98
|
|
|
81
99
|
test('Does not accept sync resolve', async () => {
|
|
82
100
|
mock.on(command).resolves({
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
101
|
+
...(type == EnvironmentType.PlainRemote
|
|
102
|
+
? {
|
|
103
|
+
Parameter: {
|
|
104
|
+
Value: undefined,
|
|
105
|
+
},
|
|
106
|
+
}
|
|
107
|
+
: {
|
|
108
|
+
SecretString: undefined,
|
|
109
|
+
}),
|
|
86
110
|
})
|
|
87
111
|
let err = null
|
|
88
112
|
try {
|
|
@@ -97,9 +121,15 @@ function testRemoteEnv(mock, type, command) {
|
|
|
97
121
|
|
|
98
122
|
test('Required fails when null', async () => {
|
|
99
123
|
mock.on(command).resolves({
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
124
|
+
...(type == EnvironmentType.PlainRemote
|
|
125
|
+
? {
|
|
126
|
+
Parameter: {
|
|
127
|
+
Value: undefined,
|
|
128
|
+
},
|
|
129
|
+
}
|
|
130
|
+
: {
|
|
131
|
+
SecretString: undefined,
|
|
132
|
+
}),
|
|
103
133
|
})
|
|
104
134
|
let err = null
|
|
105
135
|
try {
|
|
@@ -129,9 +159,15 @@ function testRemoteEnv(mock, type, command) {
|
|
|
129
159
|
test('Required value with valid response', async () => {
|
|
130
160
|
const value = 'abc'
|
|
131
161
|
mock.on(command).resolves({
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
162
|
+
...(type == EnvironmentType.PlainRemote
|
|
163
|
+
? {
|
|
164
|
+
Parameter: {
|
|
165
|
+
Value: value,
|
|
166
|
+
},
|
|
167
|
+
}
|
|
168
|
+
: {
|
|
169
|
+
SecretString: value,
|
|
170
|
+
}),
|
|
135
171
|
})
|
|
136
172
|
const env = new EnvironmentVar(value, type)
|
|
137
173
|
const token = await env.resolve()
|
|
@@ -28,7 +28,7 @@ describe('Encryption', () => {
|
|
|
28
28
|
})
|
|
29
29
|
const res = await provider.publishOnTopic(msg, topic)
|
|
30
30
|
expect(res).is.not.null
|
|
31
|
-
expect(res
|
|
31
|
+
expect(res?.MessageId).to.be.equals(messageId)
|
|
32
32
|
})
|
|
33
33
|
|
|
34
34
|
test('Publishes with success (additional props)', async () => {
|
|
@@ -45,7 +45,7 @@ describe('Encryption', () => {
|
|
|
45
45
|
FifoGroup: 123,
|
|
46
46
|
})
|
|
47
47
|
expect(res).is.not.null
|
|
48
|
-
expect(res
|
|
48
|
+
expect(res?.MessageId).to.be.equals(messageId)
|
|
49
49
|
})
|
|
50
50
|
|
|
51
51
|
test('Publish failure', async () => {
|
|
@@ -53,7 +53,7 @@ describe('Encryption', () => {
|
|
|
53
53
|
const topic = '123'
|
|
54
54
|
SNSMock.on(PublishCommand).rejects(new Error('failed!'))
|
|
55
55
|
const res = await provider.publishOnTopic(msg, topic)
|
|
56
|
-
expect(res).is.
|
|
56
|
+
expect(res).is.undefined
|
|
57
57
|
})
|
|
58
58
|
})
|
|
59
59
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { expect as
|
|
2
|
-
import { expect } from 'chai'
|
|
1
|
+
import { expect as c_expect } from 'chai'
|
|
3
2
|
import * as request from 'supertest'
|
|
4
3
|
import { z } from 'zod'
|
|
5
4
|
|
|
@@ -37,7 +36,7 @@ describe('Container server routing', () => {
|
|
|
37
36
|
.get(Globals.Listener_HTTP_DefaultHealthCheckRoute)
|
|
38
37
|
.expect('Content-Type', 'text/html; charset=utf-8')
|
|
39
38
|
.expect(200)
|
|
40
|
-
|
|
39
|
+
c_expect(res.text).to.be.equals('Healthy!')
|
|
41
40
|
// Not handled
|
|
42
41
|
await request(defaultUrl)
|
|
43
42
|
.get(`/abc`)
|
|
@@ -46,8 +45,8 @@ describe('Container server routing', () => {
|
|
|
46
45
|
|
|
47
46
|
// Unload
|
|
48
47
|
await server.stop('Error')
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
expect(mockExit).toHaveBeenCalledTimes(1)
|
|
49
|
+
expect(mockExit).toBeCalledWith(1)
|
|
51
50
|
})
|
|
52
51
|
|
|
53
52
|
test('Simple route', async () => {
|
|
@@ -68,14 +67,14 @@ describe('Container server routing', () => {
|
|
|
68
67
|
.get(Globals.Listener_HTTP_DefaultHealthCheckRoute)
|
|
69
68
|
.expect('Content-Type', 'text/html; charset=utf-8')
|
|
70
69
|
.expect(200)
|
|
71
|
-
|
|
70
|
+
c_expect(res.text).to.be.equals('Healthy!')
|
|
72
71
|
// Found route
|
|
73
72
|
const resG = await request(defaultUrl)
|
|
74
73
|
.get(`/abc`)
|
|
75
74
|
.expect('Content-Type', 'application/json; charset=utf-8')
|
|
76
75
|
.expect(200)
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
c_expect(resG.body['name']).to.be.deep.equals('abc')
|
|
77
|
+
c_expect(resG.body['transactionID']).to.not.be.null
|
|
79
78
|
// Found route, but not method
|
|
80
79
|
await request(defaultUrl)
|
|
81
80
|
.post(`/abc`)
|
|
@@ -88,8 +87,8 @@ describe('Container server routing', () => {
|
|
|
88
87
|
.expect(404)
|
|
89
88
|
// Unload
|
|
90
89
|
await server.stop('Error')
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
expect(mockExit).toHaveBeenCalledTimes(1)
|
|
91
|
+
expect(mockExit).toBeCalledWith(1)
|
|
93
92
|
})
|
|
94
93
|
})
|
|
95
94
|
|
|
@@ -117,11 +116,11 @@ describe('Container server basics', () => {
|
|
|
117
116
|
.get(Globals.Listener_HTTP_DefaultHealthCheckRoute)
|
|
118
117
|
.expect('Content-Type', 'text/html; charset=utf-8')
|
|
119
118
|
.expect(200)
|
|
120
|
-
|
|
119
|
+
c_expect(res.text).to.be.equals('Healthy!')
|
|
121
120
|
// Unload
|
|
122
121
|
await server.stop()
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
expect(mockExit).toHaveBeenCalledTimes(1)
|
|
123
|
+
expect(mockExit).toBeCalledWith(0)
|
|
125
124
|
resolve(null)
|
|
126
125
|
}, 2000)
|
|
127
126
|
})
|
|
@@ -133,8 +132,8 @@ describe('Container server basics', () => {
|
|
|
133
132
|
process.emit('SIGINT')
|
|
134
133
|
return new Promise(resolve => {
|
|
135
134
|
setTimeout(async () => {
|
|
136
|
-
|
|
137
|
-
|
|
135
|
+
expect(mockExit).toHaveBeenCalledTimes(1)
|
|
136
|
+
expect(mockExit).toBeCalledWith(0)
|
|
138
137
|
resolve(null)
|
|
139
138
|
}, 2000)
|
|
140
139
|
})
|
|
@@ -147,8 +146,8 @@ describe('Container server basics', () => {
|
|
|
147
146
|
process.emit('unhandledRejection')
|
|
148
147
|
return new Promise(resolve => {
|
|
149
148
|
setTimeout(async () => {
|
|
150
|
-
|
|
151
|
-
|
|
149
|
+
expect(mockExit).toHaveBeenCalledTimes(1)
|
|
150
|
+
expect(mockExit).toBeCalledWith(0)
|
|
152
151
|
resolve(null)
|
|
153
152
|
}, 2000)
|
|
154
153
|
})
|
|
@@ -170,11 +169,11 @@ describe('Container server validation', () => {
|
|
|
170
169
|
})
|
|
171
170
|
|
|
172
171
|
function validateValidationFailure(res: any, failureCount?: number) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
172
|
+
c_expect(res.body['err']).to.be.equals(Globals.ErrorResponseValidationFail)
|
|
173
|
+
c_expect(res.body['errCode']).to.be.equals(Globals.ErrorCode_InvalidInput)
|
|
174
|
+
c_expect(res.body['transactionID']).to.not.be.null
|
|
175
|
+
c_expect(res.body['transactionID']).to.be.an('string')
|
|
176
|
+
c_expect(res.body['validationFailure']?.length).to.be.equals(failureCount || 4)
|
|
178
177
|
}
|
|
179
178
|
|
|
180
179
|
test('Validates empty body', async () => {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { expect as j_expect } from '@jest/globals'
|
|
2
1
|
import { APIGatewayProxyEvent, Context } from 'aws-lambda'
|
|
3
|
-
import { expect } from 'chai'
|
|
2
|
+
import { expect as c_expect } from 'chai'
|
|
4
3
|
import { Request, Response } from 'express'
|
|
5
4
|
|
|
6
5
|
import Globals from '../../../../src/Globals'
|
|
@@ -28,11 +27,11 @@ describe('GenericHandler success invocation path', () => {
|
|
|
28
27
|
const resp = observableResponse()
|
|
29
28
|
const handlerResp = await handler(<Request>(<unknown>{}), resp)
|
|
30
29
|
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
c_expect(handlerResp).to.be.undefined
|
|
31
|
+
expect(resp.send).not.toBeCalled()
|
|
32
|
+
expect(resp.json).toBeCalledWith(JSON.parse(v.body))
|
|
33
|
+
expect(resp.status).toBeCalledWith(v.statusCode)
|
|
34
|
+
expect(resp.header).not.toBeCalled()
|
|
36
35
|
})
|
|
37
36
|
|
|
38
37
|
test('Simple success w/ headers', async () => {
|
|
@@ -47,11 +46,11 @@ describe('GenericHandler success invocation path', () => {
|
|
|
47
46
|
const resp = observableResponse()
|
|
48
47
|
const handlerResp = await handler(<Request>(<unknown>{}), resp)
|
|
49
48
|
//
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
c_expect(handlerResp).to.be.undefined
|
|
50
|
+
expect(resp.send).not.toBeCalled()
|
|
51
|
+
expect(resp.json).toBeCalledWith(JSON.parse(v.body))
|
|
52
|
+
expect(resp.status).toBeCalledWith(v.statusCode)
|
|
53
|
+
expect(resp.header).toBeCalledTimes(Object.keys(v.headers).length)
|
|
55
54
|
})
|
|
56
55
|
|
|
57
56
|
test('Simple success w/ null body', async () => {
|
|
@@ -65,11 +64,11 @@ describe('GenericHandler success invocation path', () => {
|
|
|
65
64
|
const resp = observableResponse()
|
|
66
65
|
const handlerResp = await handler(<Request>(<unknown>{}), resp)
|
|
67
66
|
//
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
c_expect(handlerResp).to.be.undefined
|
|
68
|
+
expect(resp.send).not.toBeCalled()
|
|
69
|
+
expect(resp.json).toBeCalledWith({})
|
|
70
|
+
expect(resp.status).toBeCalledWith(v.statusCode)
|
|
71
|
+
expect(resp.header).toBeCalledTimes(Object.keys(v.headers).length)
|
|
73
72
|
})
|
|
74
73
|
})
|
|
75
74
|
|
|
@@ -81,14 +80,14 @@ describe('GenericHandler failure invocation path', () => {
|
|
|
81
80
|
const resp = observableResponse()
|
|
82
81
|
const handlerResp = await handler(<Request>(<unknown>{}), resp)
|
|
83
82
|
//
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
c_expect(handlerResp).to.be.undefined
|
|
84
|
+
expect(resp.send).not.toBeCalled()
|
|
85
|
+
expect(resp.header).not.toBeCalled()
|
|
86
|
+
expect(resp.json).toBeCalledWith({
|
|
88
87
|
err: Globals.Resp_MSG_INVALIDRESP,
|
|
89
88
|
errCode: Globals.Resp_CODE_INVALIDRESP,
|
|
90
89
|
})
|
|
91
|
-
|
|
90
|
+
expect(resp.status).toBeCalledWith(Globals.Resp_STATUSCODE_INVALIDRESP)
|
|
92
91
|
})
|
|
93
92
|
|
|
94
93
|
test('Error response', async () => {
|
|
@@ -99,13 +98,13 @@ describe('GenericHandler failure invocation path', () => {
|
|
|
99
98
|
const resp = observableResponse()
|
|
100
99
|
const handlerResp = await handler(<Request>(<unknown>{}), resp)
|
|
101
100
|
//
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
101
|
+
c_expect(handlerResp).to.be.undefined
|
|
102
|
+
expect(resp.send).not.toBeCalled()
|
|
103
|
+
expect(resp.header).not.toBeCalled()
|
|
104
|
+
expect(resp.json).toBeCalledWith({
|
|
106
105
|
err,
|
|
107
106
|
})
|
|
108
|
-
|
|
107
|
+
expect(resp.status).toBeCalledWith(400)
|
|
109
108
|
})
|
|
110
109
|
|
|
111
110
|
test('Exception response', async () => {
|
|
@@ -116,15 +115,15 @@ describe('GenericHandler failure invocation path', () => {
|
|
|
116
115
|
const resp = observableResponse()
|
|
117
116
|
const handlerResp = await handler(<Request>(<unknown>{}), resp)
|
|
118
117
|
//
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
118
|
+
c_expect(handlerResp).to.be.undefined
|
|
119
|
+
expect(resp.send).not.toBeCalled()
|
|
120
|
+
expect(resp.header).not.toBeCalled()
|
|
121
|
+
expect(resp.json).toBeCalledWith({
|
|
123
122
|
...err,
|
|
124
123
|
err: Globals.Resp_MSG_EXCEPTION,
|
|
125
124
|
errCode: Globals.Resp_CODE_EXCEPTION,
|
|
126
125
|
})
|
|
127
|
-
|
|
126
|
+
expect(resp.status).toBeCalledWith(Globals.Resp_STATUSCODE_EXCEPTION)
|
|
128
127
|
})
|
|
129
128
|
})
|
|
130
129
|
|
|
@@ -17,7 +17,7 @@ describe('GenericHandlerEvent invocation paths', () => {
|
|
|
17
17
|
)
|
|
18
18
|
const resp = await event.invoke()
|
|
19
19
|
expect(resp).to.not.be.null
|
|
20
|
-
expect(resp.err).to.be.
|
|
20
|
+
expect(resp.err).to.be.undefined
|
|
21
21
|
expect(resp.data).to.be.equals('Success')
|
|
22
22
|
})
|
|
23
23
|
|
|
@@ -94,7 +94,7 @@ describe('GenericHandlerEvent event test', () => {
|
|
|
94
94
|
)
|
|
95
95
|
const resp = await event.invoke()
|
|
96
96
|
expect(resp).to.not.be.null
|
|
97
|
-
expect(resp.err).to.be.
|
|
97
|
+
expect(resp.err).to.be.undefined
|
|
98
98
|
expect(resp.data).to.be.equals('Success')
|
|
99
99
|
})
|
|
100
100
|
})
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { expect as
|
|
2
|
-
import { expect } from 'chai'
|
|
1
|
+
import { expect as c_expect } from 'chai'
|
|
3
2
|
import { Request, Response } from 'express'
|
|
4
3
|
|
|
5
4
|
import HealthHandler from '../../../../src/Server/lib/container/HealthHandler'
|
|
@@ -19,11 +18,11 @@ describe('HealthHandler invocation path', () => {
|
|
|
19
18
|
const resp = observableResponse()
|
|
20
19
|
const handlerResp = await HealthHandler(<Request>(<unknown>{}), resp)
|
|
21
20
|
//
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
c_expect(handlerResp).to.be.undefined
|
|
22
|
+
expect(resp.send).toBeCalledWith('Healthy!')
|
|
23
|
+
expect(resp.json).not.toBeCalled()
|
|
24
|
+
expect(resp.status).not.toBeCalled()
|
|
25
|
+
expect(resp.header).not.toBeCalled()
|
|
27
26
|
})
|
|
28
27
|
})
|
|
29
28
|
|