@creator.co/wapi 1.2.2 → 1.2.3
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/.eslintrc.cjs +29 -22
- package/.github/workflows/npmpublish.yml +1 -1
- package/.github/workflows/prs.yml +1 -1
- package/index.ts +12 -10
- package/jest.config.ts +19 -19
- package/package.json +1 -1
- package/src/API/Request.ts +17 -35
- package/src/API/Response.ts +24 -42
- package/src/API/Utils.ts +5 -7
- package/src/BaseEvent/EventProcessor.ts +16 -24
- package/src/BaseEvent/Process.ts +7 -12
- package/src/BaseEvent/Transaction.ts +25 -43
- package/src/Config/Configuration.ts +8 -14
- package/src/Config/EnvironmentVar.ts +10 -20
- package/src/Crypto/Crypto.ts +10 -10
- package/src/Crypto/JWT.ts +4 -10
- package/src/Globals.ts +19 -25
- package/src/Logger/Logger.ts +36 -51
- package/src/Mailer/Mailer.ts +19 -31
- package/src/Publisher/Publisher.ts +7 -12
- package/src/Server/RouteResolver.ts +5 -6
- package/src/Server/Router.ts +7 -12
- package/src/Server/lib/ContainerServer.ts +5 -5
- package/src/Server/lib/Server.ts +26 -38
- package/src/Server/lib/container/GenericHandler.ts +8 -13
- package/src/Server/lib/container/GenericHandlerEvent.ts +21 -35
- package/src/Server/lib/container/HealthHandler.ts +2 -2
- package/src/Server/lib/container/Proxy.ts +26 -38
- package/src/Server/lib/container/Utils.ts +2 -2
- package/src/Validation/Validator.ts +6 -6
- package/tests/API/Request.test.ts +107 -111
- package/tests/API/Response.test.ts +86 -91
- package/tests/API/Utils.test.ts +64 -64
- package/tests/BaseEvent/EventProcessor.test.ts +68 -84
- package/tests/BaseEvent/Process.test.ts +11 -11
- package/tests/BaseEvent/Transaction.test.ts +44 -53
- package/tests/Config/Config.test.ts +50 -50
- package/tests/Config/EnvironmentVar.test.ts +50 -59
- package/tests/Crypto/Crypto.test.ts +20 -22
- package/tests/Crypto/JWT.test.ts +40 -40
- package/tests/Logger/Logger.test.ts +24 -36
- package/tests/Mailer/Mailer.test.ts +21 -29
- package/tests/Publisher/Publisher.test.ts +18 -18
- package/tests/Server/RouteResolver.test.ts +56 -59
- package/tests/Server/Router.test.ts +16 -16
- package/tests/Server/lib/ContainerServer.test.ts +83 -85
- package/tests/Server/lib/Server.test.ts +4 -4
- package/tests/Server/lib/container/GenericHandler.test.ts +31 -41
- package/tests/Server/lib/container/GenericHandlerEvent.test.ts +35 -36
- package/tests/Server/lib/container/HealthHandler.test.ts +7 -7
- package/tests/Server/lib/container/Proxy.test.ts +66 -79
- package/tests/Server/lib/container/Utils.test.ts +16 -17
- package/tests/Test.utils.ts +9 -9
- package/tests/Validation/Validator.test.ts +28 -40
- package/tests/main.test.ts +2 -2
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { expect as j_expect } from
|
|
2
|
-
import { expect } from
|
|
3
|
-
import * as request from
|
|
4
|
-
import { z } from
|
|
1
|
+
import { expect as j_expect } from '@jest/globals'
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import * as request from 'supertest'
|
|
4
|
+
import { z } from 'zod'
|
|
5
5
|
|
|
6
|
-
import Response from
|
|
7
|
-
import Globals from
|
|
8
|
-
import ContainerServer from
|
|
9
|
-
import { defaultUrl } from
|
|
6
|
+
import Response from '../../../src/API/Response'
|
|
7
|
+
import Globals from '../../../src/Globals'
|
|
8
|
+
import ContainerServer from '../../../src/Server/lib/ContainerServer'
|
|
9
|
+
import { defaultUrl } from '../../Test.utils'
|
|
10
10
|
|
|
11
11
|
export const ViewSchema = z.object({
|
|
12
12
|
id: z.string(),
|
|
@@ -15,12 +15,12 @@ export const ViewSchema = z.object({
|
|
|
15
15
|
updatedAt: z.string(),
|
|
16
16
|
})
|
|
17
17
|
|
|
18
|
-
describe(
|
|
18
|
+
describe('Container server routing', () => {
|
|
19
19
|
// @ts-ignore
|
|
20
|
-
let mockExit = jest.spyOn(process,
|
|
20
|
+
let mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {})
|
|
21
21
|
beforeAll(() => {
|
|
22
22
|
// @ts-ignore
|
|
23
|
-
mockExit = jest.spyOn(process,
|
|
23
|
+
mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {})
|
|
24
24
|
})
|
|
25
25
|
afterAll(() => {
|
|
26
26
|
mockExit.mockRestore()
|
|
@@ -29,35 +29,35 @@ describe("Container server routing", () => {
|
|
|
29
29
|
mockExit.mockReset()
|
|
30
30
|
})
|
|
31
31
|
|
|
32
|
-
test(
|
|
32
|
+
test('Health & 404 handler', async () => {
|
|
33
33
|
const server = new ContainerServer({ routes: [] })
|
|
34
34
|
await server.start()
|
|
35
35
|
// Health check
|
|
36
36
|
const res = await request(defaultUrl)
|
|
37
37
|
.get(Globals.Listener_HTTP_DefaultHealthCheckRoute)
|
|
38
|
-
.expect(
|
|
38
|
+
.expect('Content-Type', 'text/html; charset=utf-8')
|
|
39
39
|
.expect(200)
|
|
40
|
-
expect(res.text).to.be.equals(
|
|
40
|
+
expect(res.text).to.be.equals('Healthy!')
|
|
41
41
|
// Not handled
|
|
42
42
|
await request(defaultUrl)
|
|
43
43
|
.get(`/abc`)
|
|
44
|
-
.expect(
|
|
44
|
+
.expect('Content-Type', 'application/json; charset=utf-8')
|
|
45
45
|
.expect(404)
|
|
46
46
|
|
|
47
47
|
// Unload
|
|
48
|
-
await server.stop(
|
|
48
|
+
await server.stop('Error')
|
|
49
49
|
j_expect(mockExit).toHaveBeenCalledTimes(1)
|
|
50
50
|
j_expect(mockExit).toBeCalledWith(1)
|
|
51
51
|
})
|
|
52
52
|
|
|
53
|
-
test(
|
|
53
|
+
test('Simple route', async () => {
|
|
54
54
|
const server = new ContainerServer({
|
|
55
55
|
routes: [
|
|
56
56
|
{
|
|
57
|
-
path:
|
|
58
|
-
method:
|
|
57
|
+
path: '/abc',
|
|
58
|
+
method: 'get',
|
|
59
59
|
handler: async () => {
|
|
60
|
-
return Response.SimpleResponse({ name:
|
|
60
|
+
return Response.SimpleResponse({ name: 'abc' })
|
|
61
61
|
},
|
|
62
62
|
},
|
|
63
63
|
],
|
|
@@ -66,39 +66,39 @@ describe("Container server routing", () => {
|
|
|
66
66
|
// Health check
|
|
67
67
|
const res = await request(defaultUrl)
|
|
68
68
|
.get(Globals.Listener_HTTP_DefaultHealthCheckRoute)
|
|
69
|
-
.expect(
|
|
69
|
+
.expect('Content-Type', 'text/html; charset=utf-8')
|
|
70
70
|
.expect(200)
|
|
71
|
-
expect(res.text).to.be.equals(
|
|
71
|
+
expect(res.text).to.be.equals('Healthy!')
|
|
72
72
|
// Found route
|
|
73
73
|
const resG = await request(defaultUrl)
|
|
74
74
|
.get(`/abc`)
|
|
75
|
-
.expect(
|
|
75
|
+
.expect('Content-Type', 'application/json; charset=utf-8')
|
|
76
76
|
.expect(200)
|
|
77
|
-
expect(resG.body[
|
|
78
|
-
expect(resG.body[
|
|
77
|
+
expect(resG.body['name']).to.be.deep.equals('abc')
|
|
78
|
+
expect(resG.body['transactionID']).to.not.be.null
|
|
79
79
|
// Found route, but not method
|
|
80
80
|
await request(defaultUrl)
|
|
81
81
|
.post(`/abc`)
|
|
82
|
-
.expect(
|
|
82
|
+
.expect('Content-Type', 'application/json; charset=utf-8')
|
|
83
83
|
.expect(404)
|
|
84
84
|
// Not found route
|
|
85
85
|
await request(defaultUrl)
|
|
86
86
|
.get(`/abc/123`)
|
|
87
|
-
.expect(
|
|
87
|
+
.expect('Content-Type', 'application/json; charset=utf-8')
|
|
88
88
|
.expect(404)
|
|
89
89
|
// Unload
|
|
90
|
-
await server.stop(
|
|
90
|
+
await server.stop('Error')
|
|
91
91
|
j_expect(mockExit).toHaveBeenCalledTimes(1)
|
|
92
92
|
j_expect(mockExit).toBeCalledWith(1)
|
|
93
93
|
})
|
|
94
94
|
})
|
|
95
95
|
|
|
96
|
-
describe(
|
|
96
|
+
describe('Container server basics', () => {
|
|
97
97
|
// @ts-ignore
|
|
98
|
-
let mockExit = jest.spyOn(process,
|
|
98
|
+
let mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {})
|
|
99
99
|
beforeAll(() => {
|
|
100
100
|
// @ts-ignore
|
|
101
|
-
mockExit = jest.spyOn(process,
|
|
101
|
+
mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {})
|
|
102
102
|
})
|
|
103
103
|
afterAll(() => {
|
|
104
104
|
mockExit.mockRestore()
|
|
@@ -107,17 +107,17 @@ describe("Container server basics", () => {
|
|
|
107
107
|
mockExit.mockReset()
|
|
108
108
|
})
|
|
109
109
|
|
|
110
|
-
test(
|
|
110
|
+
test('Starts with exports', async () => {
|
|
111
111
|
const server = new ContainerServer({ routes: [] })
|
|
112
112
|
server.getExport()
|
|
113
|
-
return new Promise(
|
|
113
|
+
return new Promise(resolve => {
|
|
114
114
|
setTimeout(async () => {
|
|
115
115
|
// Health check
|
|
116
116
|
const res = await request(defaultUrl)
|
|
117
117
|
.get(Globals.Listener_HTTP_DefaultHealthCheckRoute)
|
|
118
|
-
.expect(
|
|
118
|
+
.expect('Content-Type', 'text/html; charset=utf-8')
|
|
119
119
|
.expect(200)
|
|
120
|
-
expect(res.text).to.be.equals(
|
|
120
|
+
expect(res.text).to.be.equals('Healthy!')
|
|
121
121
|
// Unload
|
|
122
122
|
await server.stop()
|
|
123
123
|
j_expect(mockExit).toHaveBeenCalledTimes(1)
|
|
@@ -127,11 +127,11 @@ describe("Container server basics", () => {
|
|
|
127
127
|
})
|
|
128
128
|
})
|
|
129
129
|
|
|
130
|
-
test(
|
|
130
|
+
test('Stops if process sends message SIGINT', async () => {
|
|
131
131
|
const server = new ContainerServer({ routes: [] })
|
|
132
132
|
await server.start()
|
|
133
|
-
process.emit(
|
|
134
|
-
return new Promise(
|
|
133
|
+
process.emit('SIGINT')
|
|
134
|
+
return new Promise(resolve => {
|
|
135
135
|
setTimeout(async () => {
|
|
136
136
|
j_expect(mockExit).toHaveBeenCalledTimes(1)
|
|
137
137
|
j_expect(mockExit).toBeCalledWith(0)
|
|
@@ -140,12 +140,12 @@ describe("Container server basics", () => {
|
|
|
140
140
|
})
|
|
141
141
|
}, 10000)
|
|
142
142
|
|
|
143
|
-
test(
|
|
143
|
+
test('Stops if process sends message unhandledRejection', async () => {
|
|
144
144
|
const server = new ContainerServer({ routes: [] })
|
|
145
145
|
await server.start()
|
|
146
146
|
// @ts-ignore
|
|
147
|
-
process.emit(
|
|
148
|
-
return new Promise(
|
|
147
|
+
process.emit('unhandledRejection')
|
|
148
|
+
return new Promise(resolve => {
|
|
149
149
|
setTimeout(async () => {
|
|
150
150
|
j_expect(mockExit).toHaveBeenCalledTimes(1)
|
|
151
151
|
j_expect(mockExit).toBeCalledWith(0)
|
|
@@ -155,12 +155,12 @@ describe("Container server basics", () => {
|
|
|
155
155
|
}, 10000)
|
|
156
156
|
})
|
|
157
157
|
|
|
158
|
-
describe(
|
|
158
|
+
describe('Container server validation', () => {
|
|
159
159
|
// @ts-ignore
|
|
160
|
-
let mockExit = jest.spyOn(process,
|
|
160
|
+
let mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {})
|
|
161
161
|
beforeAll(() => {
|
|
162
162
|
// @ts-ignore
|
|
163
|
-
mockExit = jest.spyOn(process,
|
|
163
|
+
mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {})
|
|
164
164
|
})
|
|
165
165
|
afterAll(() => {
|
|
166
166
|
mockExit.mockRestore()
|
|
@@ -170,24 +170,22 @@ describe("Container server validation", () => {
|
|
|
170
170
|
})
|
|
171
171
|
|
|
172
172
|
function validateValidationFailure(res: any, failureCount?: number) {
|
|
173
|
-
expect(res.body[
|
|
174
|
-
expect(res.body[
|
|
175
|
-
expect(res.body[
|
|
176
|
-
expect(res.body[
|
|
177
|
-
expect(res.body[
|
|
178
|
-
failureCount || 4,
|
|
179
|
-
)
|
|
173
|
+
expect(res.body['err']).to.be.equals(Globals.ErrorResponseValidationFail)
|
|
174
|
+
expect(res.body['errCode']).to.be.equals(Globals.ErrorCode_InvalidInput)
|
|
175
|
+
expect(res.body['transactionID']).to.not.be.null
|
|
176
|
+
expect(res.body['transactionID']).to.be.an('string')
|
|
177
|
+
expect(res.body['validationFailure']?.length).to.be.equals(failureCount || 4)
|
|
180
178
|
}
|
|
181
179
|
|
|
182
|
-
test(
|
|
180
|
+
test('Validates empty body', async () => {
|
|
183
181
|
const server = new ContainerServer({
|
|
184
182
|
routes: [
|
|
185
183
|
{
|
|
186
|
-
path:
|
|
187
|
-
method:
|
|
184
|
+
path: '/abc',
|
|
185
|
+
method: 'post',
|
|
188
186
|
inputSchema: ViewSchema,
|
|
189
187
|
handler: async () => {
|
|
190
|
-
return Response.SimpleResponse({ name:
|
|
188
|
+
return Response.SimpleResponse({ name: 'abc' })
|
|
191
189
|
},
|
|
192
190
|
},
|
|
193
191
|
],
|
|
@@ -196,21 +194,21 @@ describe("Container server validation", () => {
|
|
|
196
194
|
// Validation fails, empty body
|
|
197
195
|
const resG = await request(defaultUrl)
|
|
198
196
|
.post(`/abc`)
|
|
199
|
-
.expect(
|
|
197
|
+
.expect('Content-Type', 'application/json; charset=utf-8')
|
|
200
198
|
.expect(400)
|
|
201
199
|
validateValidationFailure(resG)
|
|
202
200
|
await server.stop()
|
|
203
201
|
})
|
|
204
202
|
|
|
205
|
-
test(
|
|
203
|
+
test('Validates empty string body', async () => {
|
|
206
204
|
const server = new ContainerServer({
|
|
207
205
|
routes: [
|
|
208
206
|
{
|
|
209
|
-
path:
|
|
210
|
-
method:
|
|
207
|
+
path: '/abc',
|
|
208
|
+
method: 'post',
|
|
211
209
|
inputSchema: ViewSchema,
|
|
212
210
|
handler: async () => {
|
|
213
|
-
return Response.SimpleResponse({ name:
|
|
211
|
+
return Response.SimpleResponse({ name: 'abc' })
|
|
214
212
|
},
|
|
215
213
|
},
|
|
216
214
|
],
|
|
@@ -219,22 +217,22 @@ describe("Container server validation", () => {
|
|
|
219
217
|
// Validation fails, empty body
|
|
220
218
|
const resG = await request(defaultUrl)
|
|
221
219
|
.post(`/abc`)
|
|
222
|
-
.send(
|
|
223
|
-
.expect(
|
|
220
|
+
.send('')
|
|
221
|
+
.expect('Content-Type', 'application/json; charset=utf-8')
|
|
224
222
|
.expect(400)
|
|
225
223
|
validateValidationFailure(resG)
|
|
226
224
|
await server.stop()
|
|
227
225
|
})
|
|
228
226
|
|
|
229
|
-
test(
|
|
227
|
+
test('Validates empty object body', async () => {
|
|
230
228
|
const server = new ContainerServer({
|
|
231
229
|
routes: [
|
|
232
230
|
{
|
|
233
|
-
path:
|
|
234
|
-
method:
|
|
231
|
+
path: '/abc',
|
|
232
|
+
method: 'post',
|
|
235
233
|
inputSchema: ViewSchema,
|
|
236
234
|
handler: async () => {
|
|
237
|
-
return Response.SimpleResponse({ name:
|
|
235
|
+
return Response.SimpleResponse({ name: 'abc' })
|
|
238
236
|
},
|
|
239
237
|
},
|
|
240
238
|
],
|
|
@@ -244,21 +242,21 @@ describe("Container server validation", () => {
|
|
|
244
242
|
const resG = await request(defaultUrl)
|
|
245
243
|
.post(`/abc`)
|
|
246
244
|
.send({})
|
|
247
|
-
.expect(
|
|
245
|
+
.expect('Content-Type', 'application/json; charset=utf-8')
|
|
248
246
|
.expect(400)
|
|
249
247
|
validateValidationFailure(resG)
|
|
250
248
|
await server.stop()
|
|
251
249
|
})
|
|
252
250
|
|
|
253
|
-
test(
|
|
251
|
+
test('Validates missing props body', async () => {
|
|
254
252
|
const server = new ContainerServer({
|
|
255
253
|
routes: [
|
|
256
254
|
{
|
|
257
|
-
path:
|
|
258
|
-
method:
|
|
255
|
+
path: '/abc',
|
|
256
|
+
method: 'post',
|
|
259
257
|
inputSchema: ViewSchema,
|
|
260
258
|
handler: async () => {
|
|
261
|
-
return Response.SimpleResponse({ name:
|
|
259
|
+
return Response.SimpleResponse({ name: 'abc' })
|
|
262
260
|
},
|
|
263
261
|
},
|
|
264
262
|
],
|
|
@@ -267,22 +265,22 @@ describe("Container server validation", () => {
|
|
|
267
265
|
// Validation fails, empty body
|
|
268
266
|
const resG = await request(defaultUrl)
|
|
269
267
|
.post(`/abc`)
|
|
270
|
-
.send({ id:
|
|
271
|
-
.expect(
|
|
268
|
+
.send({ id: '123' })
|
|
269
|
+
.expect('Content-Type', 'application/json; charset=utf-8')
|
|
272
270
|
.expect(400)
|
|
273
271
|
validateValidationFailure(resG, 3)
|
|
274
272
|
await server.stop()
|
|
275
273
|
})
|
|
276
274
|
|
|
277
|
-
test(
|
|
275
|
+
test('Validates wrong type props body', async () => {
|
|
278
276
|
const server = new ContainerServer({
|
|
279
277
|
routes: [
|
|
280
278
|
{
|
|
281
|
-
path:
|
|
282
|
-
method:
|
|
279
|
+
path: '/abc',
|
|
280
|
+
method: 'post',
|
|
283
281
|
inputSchema: ViewSchema,
|
|
284
282
|
handler: async () => {
|
|
285
|
-
return Response.SimpleResponse({ name:
|
|
283
|
+
return Response.SimpleResponse({ name: 'abc' })
|
|
286
284
|
},
|
|
287
285
|
},
|
|
288
286
|
],
|
|
@@ -292,21 +290,21 @@ describe("Container server validation", () => {
|
|
|
292
290
|
const resG = await request(defaultUrl)
|
|
293
291
|
.post(`/abc`)
|
|
294
292
|
.send({ id: 123 })
|
|
295
|
-
.expect(
|
|
293
|
+
.expect('Content-Type', 'application/json; charset=utf-8')
|
|
296
294
|
.expect(400)
|
|
297
295
|
validateValidationFailure(resG)
|
|
298
296
|
await server.stop()
|
|
299
297
|
})
|
|
300
298
|
|
|
301
|
-
test(
|
|
299
|
+
test('Validates successfully', async () => {
|
|
302
300
|
const server = new ContainerServer({
|
|
303
301
|
routes: [
|
|
304
302
|
{
|
|
305
|
-
path:
|
|
306
|
-
method:
|
|
303
|
+
path: '/abc',
|
|
304
|
+
method: 'post',
|
|
307
305
|
inputSchema: ViewSchema,
|
|
308
306
|
handler: async () => {
|
|
309
|
-
return Response.SimpleResponse({ name:
|
|
307
|
+
return Response.SimpleResponse({ name: 'abc' })
|
|
310
308
|
},
|
|
311
309
|
},
|
|
312
310
|
],
|
|
@@ -316,12 +314,12 @@ describe("Container server validation", () => {
|
|
|
316
314
|
await request(defaultUrl)
|
|
317
315
|
.post(`/abc`)
|
|
318
316
|
.send({
|
|
319
|
-
id:
|
|
320
|
-
content:
|
|
317
|
+
id: '123',
|
|
318
|
+
content: '123',
|
|
321
319
|
createdAt: new Date(),
|
|
322
320
|
updatedAt: new Date(),
|
|
323
321
|
})
|
|
324
|
-
.expect(
|
|
322
|
+
.expect('Content-Type', 'application/json; charset=utf-8')
|
|
325
323
|
.expect(200)
|
|
326
324
|
await server.stop()
|
|
327
325
|
})
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { expect } from
|
|
1
|
+
import { expect } from 'chai'
|
|
2
2
|
|
|
3
|
-
import Server from
|
|
3
|
+
import Server from '../../../src/Server/lib/Server'
|
|
4
4
|
|
|
5
|
-
describe(
|
|
6
|
-
test(
|
|
5
|
+
describe('Server basics', () => {
|
|
6
|
+
test('Works', async () => {
|
|
7
7
|
const server = new Server({ routes: [] })
|
|
8
8
|
expect(server.getExport()).to.not.be.undefined
|
|
9
9
|
})
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { expect as j_expect } from
|
|
2
|
-
import { APIGatewayProxyEvent, Context } from
|
|
3
|
-
import { expect } from
|
|
4
|
-
import { Request, Response } from
|
|
1
|
+
import { expect as j_expect } from '@jest/globals'
|
|
2
|
+
import { APIGatewayProxyEvent, Context } from 'aws-lambda'
|
|
3
|
+
import { expect } from 'chai'
|
|
4
|
+
import { Request, Response } from 'express'
|
|
5
5
|
|
|
6
|
-
import Globals from
|
|
7
|
-
import GenericHandler from
|
|
6
|
+
import Globals from '../../../../src/Globals'
|
|
7
|
+
import GenericHandler from '../../../../src/Server/lib/container/GenericHandler'
|
|
8
8
|
|
|
9
9
|
function observableResponse(): Response {
|
|
10
10
|
const resp = <Response>(<unknown>{
|
|
@@ -16,17 +16,15 @@ function observableResponse(): Response {
|
|
|
16
16
|
return resp
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
describe(
|
|
20
|
-
test(
|
|
19
|
+
describe('GenericHandler success invocation path', () => {
|
|
20
|
+
test('Simple success', async () => {
|
|
21
21
|
const v = {
|
|
22
22
|
statusCode: 200,
|
|
23
23
|
body: JSON.stringify({ id: 123 }),
|
|
24
24
|
}
|
|
25
|
-
const handler = GenericHandler(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
},
|
|
29
|
-
)
|
|
25
|
+
const handler = GenericHandler(async (event: APIGatewayProxyEvent, context: Context) => {
|
|
26
|
+
context.succeed(v)
|
|
27
|
+
})
|
|
30
28
|
const resp = observableResponse()
|
|
31
29
|
const handlerResp = await handler(<Request>(<unknown>{}), resp)
|
|
32
30
|
//
|
|
@@ -37,17 +35,15 @@ describe("GenericHandler success invocation path", () => {
|
|
|
37
35
|
j_expect(resp.header).not.toBeCalled()
|
|
38
36
|
})
|
|
39
37
|
|
|
40
|
-
test(
|
|
38
|
+
test('Simple success w/ headers', async () => {
|
|
41
39
|
const v = {
|
|
42
40
|
statusCode: 200,
|
|
43
41
|
body: JSON.stringify({ id: 123 }),
|
|
44
42
|
headers: { Authorization: 123 },
|
|
45
43
|
}
|
|
46
|
-
const handler = GenericHandler(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
},
|
|
50
|
-
)
|
|
44
|
+
const handler = GenericHandler(async (event: APIGatewayProxyEvent, context: Context) => {
|
|
45
|
+
context.succeed(v)
|
|
46
|
+
})
|
|
51
47
|
const resp = observableResponse()
|
|
52
48
|
const handlerResp = await handler(<Request>(<unknown>{}), resp)
|
|
53
49
|
//
|
|
@@ -58,16 +54,14 @@ describe("GenericHandler success invocation path", () => {
|
|
|
58
54
|
j_expect(resp.header).toBeCalledTimes(Object.keys(v.headers).length)
|
|
59
55
|
})
|
|
60
56
|
|
|
61
|
-
test(
|
|
57
|
+
test('Simple success w/ null body', async () => {
|
|
62
58
|
const v = {
|
|
63
59
|
statusCode: 200,
|
|
64
60
|
headers: { Authorization: 123 },
|
|
65
61
|
}
|
|
66
|
-
const handler = GenericHandler(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
},
|
|
70
|
-
)
|
|
62
|
+
const handler = GenericHandler(async (event: APIGatewayProxyEvent, context: Context) => {
|
|
63
|
+
context.succeed(v)
|
|
64
|
+
})
|
|
71
65
|
const resp = observableResponse()
|
|
72
66
|
const handlerResp = await handler(<Request>(<unknown>{}), resp)
|
|
73
67
|
//
|
|
@@ -79,13 +73,11 @@ describe("GenericHandler success invocation path", () => {
|
|
|
79
73
|
})
|
|
80
74
|
})
|
|
81
75
|
|
|
82
|
-
describe(
|
|
83
|
-
test(
|
|
84
|
-
const handler = GenericHandler(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
},
|
|
88
|
-
)
|
|
76
|
+
describe('GenericHandler failure invocation path', () => {
|
|
77
|
+
test('Invalid response', async () => {
|
|
78
|
+
const handler = GenericHandler(async (event: APIGatewayProxyEvent, context: Context) => {
|
|
79
|
+
context.succeed(null)
|
|
80
|
+
})
|
|
89
81
|
const resp = observableResponse()
|
|
90
82
|
const handlerResp = await handler(<Request>(<unknown>{}), resp)
|
|
91
83
|
//
|
|
@@ -99,13 +91,11 @@ describe("GenericHandler failure invocation path", () => {
|
|
|
99
91
|
j_expect(resp.status).toBeCalledWith(Globals.Resp_STATUSCODE_INVALIDRESP)
|
|
100
92
|
})
|
|
101
93
|
|
|
102
|
-
test(
|
|
103
|
-
const err = new Error(
|
|
104
|
-
const handler = GenericHandler(
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
},
|
|
108
|
-
)
|
|
94
|
+
test('Error response', async () => {
|
|
95
|
+
const err = new Error('Failed!')
|
|
96
|
+
const handler = GenericHandler(async (event: APIGatewayProxyEvent, context: Context) => {
|
|
97
|
+
context.fail(err)
|
|
98
|
+
})
|
|
109
99
|
const resp = observableResponse()
|
|
110
100
|
const handlerResp = await handler(<Request>(<unknown>{}), resp)
|
|
111
101
|
//
|
|
@@ -118,8 +108,8 @@ describe("GenericHandler failure invocation path", () => {
|
|
|
118
108
|
j_expect(resp.status).toBeCalledWith(400)
|
|
119
109
|
})
|
|
120
110
|
|
|
121
|
-
test(
|
|
122
|
-
const err = new Error(
|
|
111
|
+
test('Exception response', async () => {
|
|
112
|
+
const err = new Error('Failed!')
|
|
123
113
|
const handler = GenericHandler(async () => {
|
|
124
114
|
throw err
|
|
125
115
|
})
|