@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,5 @@
|
|
|
1
|
-
import { expect as j_expect } from '@jest/globals'
|
|
2
1
|
import { APIGatewayEvent, Context } from 'aws-lambda'
|
|
3
|
-
import { expect } from 'chai'
|
|
2
|
+
import { expect as c_expect } from 'chai'
|
|
4
3
|
|
|
5
4
|
import Response from '../../src/API/Response'
|
|
6
5
|
import Transaction from '../../src/BaseEvent/Transaction'
|
|
@@ -11,11 +10,11 @@ async function testResponse(r: Response<any>, body: any, optCode?: number, optHe
|
|
|
11
10
|
const t = observableTransaction()
|
|
12
11
|
const context = t['context']
|
|
13
12
|
const buildR = await r.build(context, t, false)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
c_expect(buildR).to.be.undefined
|
|
14
|
+
expect(t.responseProxy).toBeCalledTimes(1)
|
|
15
|
+
expect(context.fail).not.toBeCalled()
|
|
16
|
+
expect(context.done).not.toBeCalled()
|
|
17
|
+
expect(context.succeed).toHaveBeenCalledWith({
|
|
19
18
|
statusCode: optCode || 400,
|
|
20
19
|
headers: {
|
|
21
20
|
...defaultHeaders,
|
|
@@ -35,28 +34,28 @@ async function testResponse(r: Response<any>, body: any, optCode?: number, optHe
|
|
|
35
34
|
describe('Response basics', () => {
|
|
36
35
|
test('Null body', () => {
|
|
37
36
|
const r = new Response<null>(200, null)
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
c_expect(r.getCode()).to.be.equals(200)
|
|
38
|
+
c_expect(r.getBody()).to.be.null
|
|
40
39
|
})
|
|
41
40
|
|
|
42
41
|
test('String body', () => {
|
|
43
42
|
const r = new Response<string>(200, 'abc')
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
c_expect(r.getCode()).to.be.equals(200)
|
|
44
|
+
c_expect(r.getBody()).to.be.equals('abc')
|
|
46
45
|
})
|
|
47
46
|
|
|
48
47
|
test('Generic body', () => {
|
|
49
48
|
const r = new Response<any>(200, { name: 'abc' })
|
|
50
49
|
r.appendIntoBody('name2', '123')
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
c_expect(r.getCode()).to.be.equals(200)
|
|
51
|
+
c_expect(r.getBody().name).to.be.equals('abc')
|
|
52
|
+
c_expect(r.getBody().name2).to.be.equals('123')
|
|
54
53
|
})
|
|
55
54
|
|
|
56
55
|
test('Append/validate header', () => {
|
|
57
56
|
const r = new Response<any>(200, {})
|
|
58
57
|
r.appendHeader('name2', '123')
|
|
59
|
-
|
|
58
|
+
c_expect(r['headers']['name2']).to.be.equals('123')
|
|
60
59
|
})
|
|
61
60
|
})
|
|
62
61
|
|
|
@@ -76,10 +75,10 @@ describe('Response build', () => {
|
|
|
76
75
|
)
|
|
77
76
|
const context = t['context']
|
|
78
77
|
const buildR = await r.build(context, t, false)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
c_expect(buildR).to.be.undefined
|
|
79
|
+
expect(context.fail).not.toBeCalled()
|
|
80
|
+
expect(context.done).not.toBeCalled()
|
|
81
|
+
expect(context.succeed).toHaveBeenCalledWith({
|
|
83
82
|
statusCode: 200,
|
|
84
83
|
headers: {
|
|
85
84
|
...defaultHeaders,
|
|
@@ -98,10 +97,10 @@ describe('Response build', () => {
|
|
|
98
97
|
const t = observableTransaction()
|
|
99
98
|
const context = t['context']
|
|
100
99
|
const buildR = await r.build(context, t, true)
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
100
|
+
c_expect(buildR).to.be.undefined
|
|
101
|
+
expect(context.fail).not.toBeCalled()
|
|
102
|
+
expect(context.done).not.toBeCalled()
|
|
103
|
+
expect(context.succeed).not.toBeCalled()
|
|
105
104
|
})
|
|
106
105
|
|
|
107
106
|
test('Succeeds to transaction context as RAW', async () => {
|
|
@@ -112,10 +111,10 @@ describe('Response build', () => {
|
|
|
112
111
|
const t = observableTransaction()
|
|
113
112
|
const context = t['context']
|
|
114
113
|
const buildR = await r.build(context, t, false)
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
114
|
+
c_expect(buildR).to.be.undefined
|
|
115
|
+
expect(context.fail).not.toBeCalled()
|
|
116
|
+
expect(context.done).not.toBeCalled()
|
|
117
|
+
expect(context.succeed).toHaveBeenCalledWith({
|
|
119
118
|
...b,
|
|
120
119
|
transactionID: 'unknown',
|
|
121
120
|
})
|
|
@@ -130,11 +129,11 @@ describe('Response build', () => {
|
|
|
130
129
|
const context = t['context']
|
|
131
130
|
const buildR = await r.build(context, t, false)
|
|
132
131
|
await r.build(context, t, false) //pipe twice, should not affect
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
132
|
+
c_expect(buildR).to.be.undefined
|
|
133
|
+
expect(context.fail).not.toBeCalled()
|
|
134
|
+
expect(context.done).not.toBeCalled()
|
|
135
|
+
expect(context.succeed).toHaveBeenCalledTimes(1)
|
|
136
|
+
expect(context.succeed).toHaveBeenCalledWith({
|
|
138
137
|
statusCode: 200,
|
|
139
138
|
headers: {
|
|
140
139
|
...defaultHeaders,
|
|
@@ -153,10 +152,10 @@ describe('Response build', () => {
|
|
|
153
152
|
const t = observableTransaction()
|
|
154
153
|
const context = t['context']
|
|
155
154
|
const buildR = await r.build(context, t, false)
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
155
|
+
c_expect(buildR).to.be.undefined
|
|
156
|
+
expect(context.done).not.toBeCalled()
|
|
157
|
+
expect(context.succeed).not.toBeCalled()
|
|
158
|
+
expect(context.fail).toHaveBeenCalledTimes(1)
|
|
160
159
|
})
|
|
161
160
|
|
|
162
161
|
test('Failure exception to transaction context as RAW', async () => {
|
|
@@ -174,11 +173,11 @@ describe('Response build', () => {
|
|
|
174
173
|
} catch (e) {
|
|
175
174
|
exception = e
|
|
176
175
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
176
|
+
c_expect(buildR).to.be.null
|
|
177
|
+
c_expect(exception).to.not.be.null
|
|
178
|
+
expect(context.done).not.toBeCalled()
|
|
179
|
+
expect(context.succeed).not.toBeCalled()
|
|
180
|
+
expect(context.fail).not.toBeCalled()
|
|
182
181
|
})
|
|
183
182
|
|
|
184
183
|
test('Failure exception to transaction context as RAW and null body', async () => {
|
|
@@ -196,11 +195,11 @@ describe('Response build', () => {
|
|
|
196
195
|
} catch (e) {
|
|
197
196
|
exception = e
|
|
198
197
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
198
|
+
c_expect(buildR).to.be.null
|
|
199
|
+
c_expect(exception).to.not.be.null
|
|
200
|
+
expect(context.done).not.toBeCalled()
|
|
201
|
+
expect(context.succeed).not.toBeCalled()
|
|
202
|
+
expect(context.fail).not.toBeCalled()
|
|
204
203
|
})
|
|
205
204
|
|
|
206
205
|
test('Failure exception to transaction context as RAW and custom ero', async () => {
|
|
@@ -218,11 +217,11 @@ describe('Response build', () => {
|
|
|
218
217
|
} catch (e) {
|
|
219
218
|
exception = e
|
|
220
219
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
220
|
+
c_expect(buildR).to.be.null
|
|
221
|
+
c_expect(exception).to.not.be.null
|
|
222
|
+
expect(context.done).not.toBeCalled()
|
|
223
|
+
expect(context.succeed).not.toBeCalled()
|
|
224
|
+
expect(context.fail).not.toBeCalled()
|
|
226
225
|
})
|
|
227
226
|
})
|
|
228
227
|
|
|
@@ -346,11 +345,11 @@ describe('Response shortcuts', () => {
|
|
|
346
345
|
const context = t['context']
|
|
347
346
|
const buildR = await r.build(context, t, false)
|
|
348
347
|
await r.build(context, t, false) //pipe twice, should not affect
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
348
|
+
c_expect(buildR).to.be.undefined
|
|
349
|
+
expect(context.fail).not.toBeCalled()
|
|
350
|
+
expect(context.done).not.toBeCalled()
|
|
351
|
+
expect(context.succeed).toHaveBeenCalledTimes(1)
|
|
352
|
+
expect(context.succeed).toHaveBeenCalledWith({
|
|
354
353
|
statusCode: 200,
|
|
355
354
|
headers: {
|
|
356
355
|
...defaultHeaders,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { expect as
|
|
2
|
-
import { expect } from 'chai'
|
|
1
|
+
import { expect as c_expect } from 'chai'
|
|
3
2
|
|
|
4
3
|
import Response from '../../src/API/Response'
|
|
5
4
|
import EventProcessor from '../../src/BaseEvent/EventProcessor'
|
|
@@ -19,23 +18,23 @@ describe('EventProcessor success invocation path', () => {
|
|
|
19
18
|
)
|
|
20
19
|
let count = 0
|
|
21
20
|
const handlerResp = await transaction.processEvent(async (transaction, eventRecord) => {
|
|
22
|
-
|
|
21
|
+
c_expect(eventRecord).to.be.deep.equal(b)
|
|
23
22
|
count++
|
|
24
23
|
return Response.SuccessResponse(null)
|
|
25
24
|
})
|
|
26
25
|
// check resp
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
c_expect(count).to.be.equals(2)
|
|
27
|
+
c_expect(handlerResp).to.be.an.instanceof(Response)
|
|
29
28
|
if (handlerResp instanceof Response) {
|
|
30
|
-
|
|
29
|
+
c_expect(handlerResp?.getBody()).to.be.deep.equal({
|
|
31
30
|
transactionID: 'unknown',
|
|
32
31
|
})
|
|
33
|
-
|
|
32
|
+
c_expect(handlerResp.getCode()).to.be.equal(200)
|
|
34
33
|
}
|
|
35
34
|
// ctx
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
expect(context.fail).not.toBeCalled()
|
|
36
|
+
expect(context.done).not.toBeCalled()
|
|
37
|
+
expect(context.succeed).not.toBeCalled()
|
|
39
38
|
})
|
|
40
39
|
|
|
41
40
|
test('Simple success - do not decode', async () => {
|
|
@@ -50,23 +49,23 @@ describe('EventProcessor success invocation path', () => {
|
|
|
50
49
|
)
|
|
51
50
|
let count = 0
|
|
52
51
|
const handlerResp = await transaction.processEvent(async (transaction, eventRecord) => {
|
|
53
|
-
|
|
52
|
+
c_expect(eventRecord).to.be.deep.equal(JSON.stringify(b))
|
|
54
53
|
count++
|
|
55
54
|
return Response.SuccessResponse(null)
|
|
56
55
|
}, true)
|
|
57
56
|
// check resp
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
c_expect(count).to.be.equals(2)
|
|
58
|
+
c_expect(handlerResp).to.be.an.instanceof(Response)
|
|
60
59
|
if (handlerResp instanceof Response) {
|
|
61
|
-
|
|
60
|
+
c_expect(handlerResp?.getBody()).to.be.deep.equal({
|
|
62
61
|
transactionID: 'unknown',
|
|
63
62
|
})
|
|
64
|
-
|
|
63
|
+
c_expect(handlerResp.getCode()).to.be.equal(200)
|
|
65
64
|
}
|
|
66
65
|
// ctx
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
expect(context.fail).not.toBeCalled()
|
|
67
|
+
expect(context.done).not.toBeCalled()
|
|
68
|
+
expect(context.succeed).not.toBeCalled()
|
|
70
69
|
})
|
|
71
70
|
})
|
|
72
71
|
|
|
@@ -90,7 +89,7 @@ describe('EventProcessor failure invocation path', () => {
|
|
|
90
89
|
err: any = null
|
|
91
90
|
try {
|
|
92
91
|
handlerResp = await transaction.processEvent(async (transaction, eventRecord) => {
|
|
93
|
-
|
|
92
|
+
c_expect(eventRecord).to.be.deep.equal(b)
|
|
94
93
|
count++
|
|
95
94
|
return count == 1 ? Response.SuccessResponse(null) : Response.BadRequestResponse('Failed!')
|
|
96
95
|
})
|
|
@@ -98,9 +97,9 @@ describe('EventProcessor failure invocation path', () => {
|
|
|
98
97
|
err = e
|
|
99
98
|
}
|
|
100
99
|
// check resp
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
100
|
+
c_expect(count).to.be.equals(2)
|
|
101
|
+
c_expect(handlerResp).to.be.null
|
|
102
|
+
c_expect(err).to.be.deep.equal(
|
|
104
103
|
new Error(
|
|
105
104
|
JSON.stringify({
|
|
106
105
|
err: 'Failed!',
|
|
@@ -109,9 +108,9 @@ describe('EventProcessor failure invocation path', () => {
|
|
|
109
108
|
)
|
|
110
109
|
)
|
|
111
110
|
// ctx
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
expect(context.fail).not.toBeCalled()
|
|
112
|
+
expect(context.done).not.toBeCalled()
|
|
113
|
+
expect(context.succeed).not.toBeCalled()
|
|
115
114
|
})
|
|
116
115
|
|
|
117
116
|
test('Simple failure w/ null', async () => {
|
|
@@ -135,7 +134,7 @@ describe('EventProcessor failure invocation path', () => {
|
|
|
135
134
|
handlerResp = await transaction.processEvent(
|
|
136
135
|
// @ts-ignore
|
|
137
136
|
async (transaction, eventRecord) => {
|
|
138
|
-
|
|
137
|
+
c_expect(eventRecord).to.be.deep.equal(b)
|
|
139
138
|
count++
|
|
140
139
|
return null
|
|
141
140
|
}
|
|
@@ -144,9 +143,9 @@ describe('EventProcessor failure invocation path', () => {
|
|
|
144
143
|
err = e
|
|
145
144
|
}
|
|
146
145
|
// check resp
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
146
|
+
c_expect(count).to.be.equals(1)
|
|
147
|
+
c_expect(handlerResp).to.be.null
|
|
148
|
+
c_expect(err).to.be.deep.equal(
|
|
150
149
|
new Error(
|
|
151
150
|
JSON.stringify({
|
|
152
151
|
err: Globals.ErrorResponseInvalidServerResponse,
|
|
@@ -157,9 +156,9 @@ describe('EventProcessor failure invocation path', () => {
|
|
|
157
156
|
)
|
|
158
157
|
)
|
|
159
158
|
// ctx
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
159
|
+
expect(context.fail).not.toBeCalled()
|
|
160
|
+
expect(context.done).not.toBeCalled()
|
|
161
|
+
expect(context.succeed).not.toBeCalled()
|
|
163
162
|
})
|
|
164
163
|
|
|
165
164
|
test('Simple failure - allow failures', async () => {
|
|
@@ -175,19 +174,19 @@ describe('EventProcessor failure invocation path', () => {
|
|
|
175
174
|
)
|
|
176
175
|
let count = 0
|
|
177
176
|
const handlerResp = await transaction.processEvent(async (transaction, eventRecord) => {
|
|
178
|
-
|
|
177
|
+
c_expect(eventRecord).to.be.deep.equal(b)
|
|
179
178
|
count++
|
|
180
179
|
return count == 1 ? Response.SuccessResponse(null) : Response.BadRequestResponse('Failed!')
|
|
181
180
|
})
|
|
182
181
|
// check resp
|
|
183
|
-
|
|
184
|
-
|
|
182
|
+
c_expect(count).to.be.equals(2)
|
|
183
|
+
c_expect(handlerResp).to.be.deep.equal({
|
|
185
184
|
batchItemFailures: [{ itemIdentifier: '123' }],
|
|
186
185
|
})
|
|
187
186
|
// ctx
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
187
|
+
expect(context.fail).not.toBeCalled()
|
|
188
|
+
expect(context.done).not.toBeCalled()
|
|
189
|
+
expect(context.succeed).not.toBeCalled()
|
|
191
190
|
})
|
|
192
191
|
|
|
193
192
|
test('Simple failure w/ null response - allow failures', async () => {
|
|
@@ -208,20 +207,20 @@ describe('EventProcessor failure invocation path', () => {
|
|
|
208
207
|
const handlerResp = await transaction.processEvent(
|
|
209
208
|
// @ts-ignore
|
|
210
209
|
async (transaction, eventRecord) => {
|
|
211
|
-
|
|
210
|
+
c_expect(eventRecord).to.be.deep.equal(b)
|
|
212
211
|
count++
|
|
213
212
|
return null
|
|
214
213
|
}
|
|
215
214
|
)
|
|
216
215
|
// check resp
|
|
217
|
-
|
|
218
|
-
|
|
216
|
+
c_expect(count).to.be.equals(2)
|
|
217
|
+
c_expect(handlerResp).to.be.deep.equal({
|
|
219
218
|
batchItemFailures: [{ itemIdentifier: '456' }, { itemIdentifier: '123' }],
|
|
220
219
|
})
|
|
221
220
|
// ctx
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
221
|
+
expect(context.fail).not.toBeCalled()
|
|
222
|
+
expect(context.done).not.toBeCalled()
|
|
223
|
+
expect(context.succeed).not.toBeCalled()
|
|
225
224
|
})
|
|
226
225
|
|
|
227
226
|
test('Simple failure no records', async () => {
|
|
@@ -242,9 +241,9 @@ describe('EventProcessor failure invocation path', () => {
|
|
|
242
241
|
err = e
|
|
243
242
|
}
|
|
244
243
|
// check resp
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
244
|
+
c_expect(count).to.be.equals(0)
|
|
245
|
+
c_expect(handlerResp).to.be.null
|
|
246
|
+
c_expect(err).to.be.deep.equal(
|
|
248
247
|
new Error(
|
|
249
248
|
JSON.stringify({
|
|
250
249
|
err: Globals.ErrorResponseNoRecords,
|
|
@@ -253,9 +252,9 @@ describe('EventProcessor failure invocation path', () => {
|
|
|
253
252
|
)
|
|
254
253
|
)
|
|
255
254
|
// ctx
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
255
|
+
expect(context.fail).not.toBeCalled()
|
|
256
|
+
expect(context.done).not.toBeCalled()
|
|
257
|
+
expect(context.succeed).not.toBeCalled()
|
|
259
258
|
})
|
|
260
259
|
})
|
|
261
260
|
|
|
@@ -18,7 +18,7 @@ describe('Process success invocation path', () => {
|
|
|
18
18
|
return new Promise(resolve => {
|
|
19
19
|
setTimeout(() => {
|
|
20
20
|
expect(count).to.be.equals(2)
|
|
21
|
-
clearInterval(proc.
|
|
21
|
+
clearInterval(proc.timeout)
|
|
22
22
|
resolve(null)
|
|
23
23
|
}, 250)
|
|
24
24
|
})
|
|
@@ -39,7 +39,7 @@ describe('Process failure invocation path', () => {
|
|
|
39
39
|
return new Promise(resolve => {
|
|
40
40
|
setTimeout(() => {
|
|
41
41
|
expect(count).to.be.equals(2)
|
|
42
|
-
clearInterval(proc.
|
|
42
|
+
clearInterval(proc.timeout)
|
|
43
43
|
resolve(null)
|
|
44
44
|
}, 250)
|
|
45
45
|
})
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { expect as
|
|
2
|
-
import { expect } from 'chai'
|
|
1
|
+
import { expect as c_expect } from 'chai'
|
|
3
2
|
|
|
4
3
|
import Response from '../../src/API/Response'
|
|
5
4
|
import Transaction from '../../src/BaseEvent/Transaction'
|
|
@@ -16,11 +15,11 @@ describe('Transaction success invocation path', () => {
|
|
|
16
15
|
return Response.SuccessResponse(b)
|
|
17
16
|
})
|
|
18
17
|
// check resp
|
|
19
|
-
|
|
18
|
+
c_expect(handlerResp).to.be.null
|
|
20
19
|
// ctx
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
expect(context.fail).not.toBeCalled()
|
|
21
|
+
expect(context.done).not.toBeCalled()
|
|
22
|
+
expect(context.succeed).toBeCalledWith({
|
|
24
23
|
statusCode: 200,
|
|
25
24
|
body: JSON.stringify(b),
|
|
26
25
|
headers: defaultHeaders,
|
|
@@ -37,13 +36,13 @@ describe('Transaction success invocation path', () => {
|
|
|
37
36
|
return Response.SuccessResponse(b)
|
|
38
37
|
})
|
|
39
38
|
// check resp
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
c_expect(handlerResp).to.be.an.instanceof(Response)
|
|
40
|
+
c_expect(handlerResp?.getBody()).to.be.deep.equals(b)
|
|
41
|
+
c_expect(handlerResp?.getCode()).to.be.equals(200)
|
|
43
42
|
// ctx
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
expect(context.fail).not.toBeCalled()
|
|
44
|
+
expect(context.done).not.toBeCalled()
|
|
45
|
+
expect(context.succeed).not.toBeCalled()
|
|
47
46
|
})
|
|
48
47
|
})
|
|
49
48
|
|
|
@@ -61,11 +60,11 @@ describe('Transaction error invocation path without response', () => {
|
|
|
61
60
|
return null
|
|
62
61
|
})
|
|
63
62
|
// check resp
|
|
64
|
-
|
|
63
|
+
c_expect(handlerResp).to.be.null
|
|
65
64
|
// ctx
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
expect(context.fail).not.toBeCalled()
|
|
66
|
+
expect(context.done).not.toBeCalled()
|
|
67
|
+
expect(context.succeed).toBeCalledWith({
|
|
69
68
|
statusCode: 400,
|
|
70
69
|
body: JSON.stringify(b),
|
|
71
70
|
headers: defaultHeaders,
|
|
@@ -93,13 +92,13 @@ describe('Transaction error invocation path without response', () => {
|
|
|
93
92
|
return null
|
|
94
93
|
})
|
|
95
94
|
// check resp
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
c_expect(handlerResp).to.be.an.instanceof(Response)
|
|
96
|
+
c_expect(handlerResp?.getBody()).to.be.deep.equals(b)
|
|
97
|
+
c_expect(handlerResp?.getCode()).to.be.equals(400)
|
|
99
98
|
// ctx
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
99
|
+
expect(context.fail).not.toBeCalled()
|
|
100
|
+
expect(context.done).not.toBeCalled()
|
|
101
|
+
expect(context.succeed).not.toBeCalled()
|
|
103
102
|
})
|
|
104
103
|
})
|
|
105
104
|
|
|
@@ -118,11 +117,11 @@ describe('Transaction error invocation path with non-Response class response', (
|
|
|
118
117
|
return b2
|
|
119
118
|
})
|
|
120
119
|
// check resp
|
|
121
|
-
|
|
120
|
+
c_expect(handlerResp).to.be.null
|
|
122
121
|
// ctx
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
122
|
+
expect(context.fail).not.toBeCalled()
|
|
123
|
+
expect(context.done).not.toBeCalled()
|
|
124
|
+
expect(context.succeed).toBeCalledWith({
|
|
126
125
|
statusCode: 400,
|
|
127
126
|
body: JSON.stringify(b),
|
|
128
127
|
headers: defaultHeaders,
|
|
@@ -139,11 +138,11 @@ describe('Transaction error invocation path with non-Response class response', (
|
|
|
139
138
|
return b2
|
|
140
139
|
})
|
|
141
140
|
// check resp
|
|
142
|
-
|
|
141
|
+
c_expect(handlerResp).to.be.deep.equals(b2)
|
|
143
142
|
// ctx
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
143
|
+
expect(context.fail).not.toBeCalled()
|
|
144
|
+
expect(context.done).not.toBeCalled()
|
|
145
|
+
expect(context.succeed).not.toBeCalled()
|
|
147
146
|
})
|
|
148
147
|
})
|
|
149
148
|
|
|
@@ -161,11 +160,11 @@ describe('Transaction error invocation path with exception', () => {
|
|
|
161
160
|
throw new Error('Failed!')
|
|
162
161
|
})
|
|
163
162
|
// check resp
|
|
164
|
-
|
|
163
|
+
c_expect(handlerResp).to.be.null
|
|
165
164
|
// ctx
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
165
|
+
expect(context.fail).not.toBeCalled()
|
|
166
|
+
expect(context.done).not.toBeCalled()
|
|
167
|
+
expect(context.succeed).toBeCalledWith({
|
|
169
168
|
statusCode: 400,
|
|
170
169
|
body: JSON.stringify(b),
|
|
171
170
|
headers: defaultHeaders,
|
|
@@ -187,12 +186,12 @@ describe('Transaction error invocation path with exception', () => {
|
|
|
187
186
|
throw new Error('Failed!')
|
|
188
187
|
})
|
|
189
188
|
// check resp
|
|
190
|
-
|
|
191
|
-
|
|
189
|
+
c_expect(handlerResp?.getBody()).to.be.deep.equals(b)
|
|
190
|
+
c_expect(handlerResp?.getCode()).to.be.equals(400)
|
|
192
191
|
// ctx
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
192
|
+
expect(context.fail).not.toBeCalled()
|
|
193
|
+
expect(context.done).not.toBeCalled()
|
|
194
|
+
expect(context.succeed).not.toBeCalled()
|
|
196
195
|
})
|
|
197
196
|
|
|
198
197
|
test('Transaction exception - sync return', async () => {
|
|
@@ -211,12 +210,12 @@ describe('Transaction error invocation path with exception', () => {
|
|
|
211
210
|
err = e
|
|
212
211
|
}
|
|
213
212
|
// check resp
|
|
214
|
-
|
|
215
|
-
|
|
213
|
+
c_expect(handlerResp).to.be.null
|
|
214
|
+
c_expect(err).to.be.deep.equals(error)
|
|
216
215
|
// ctx
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
216
|
+
expect(context.fail).not.toBeCalled()
|
|
217
|
+
expect(context.done).not.toBeCalled()
|
|
218
|
+
expect(context.succeed).not.toBeCalled()
|
|
220
219
|
})
|
|
221
220
|
})
|
|
222
221
|
|
|
@@ -255,9 +254,9 @@ describe('Transaction - db integration', () => {
|
|
|
255
254
|
|
|
256
255
|
return Response.SuccessResponse(null)
|
|
257
256
|
})
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
257
|
+
expect(mockCreate).toBeCalledWith(config)
|
|
258
|
+
expect(mockTrans.select).toBeCalledWith('name')
|
|
259
|
+
expect(mockTrans.closeSuccess).toBeCalled()
|
|
261
260
|
})
|
|
262
261
|
|
|
263
262
|
test('Errored transaction calls closeFailure', async () => {
|
|
@@ -273,8 +272,8 @@ describe('Transaction - db integration', () => {
|
|
|
273
272
|
|
|
274
273
|
console.log(ss)
|
|
275
274
|
|
|
276
|
-
|
|
277
|
-
|
|
275
|
+
expect(mockCreate).toBeCalledWith(config)
|
|
276
|
+
expect(mockTrans.closeFailure).toBeCalled()
|
|
278
277
|
})
|
|
279
278
|
})
|
|
280
279
|
|