@creator.co/wapi 1.2.2 → 1.2.4
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 +2 -5
- package/.github/workflows/prs.yml +1 -1
- package/README.md +1 -3
- package/dist/index.d.ts +11 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/jest.config.d.ts +3 -0
- package/dist/jest.config.js +34 -0
- package/dist/jest.config.js.map +1 -0
- package/dist/package.json +64 -0
- package/dist/src/API/Request.d.ts +140 -0
- package/dist/src/API/Request.js +182 -0
- package/dist/src/API/Request.js.map +1 -0
- package/dist/src/API/Response.d.ts +256 -0
- package/dist/src/API/Response.js +398 -0
- package/dist/src/API/Response.js.map +1 -0
- package/dist/src/API/Utils.d.ts +63 -0
- package/dist/src/API/Utils.js +104 -0
- package/dist/src/API/Utils.js.map +1 -0
- package/dist/src/BaseEvent/EventProcessor.d.ts +81 -0
- package/dist/src/BaseEvent/EventProcessor.js +182 -0
- package/dist/src/BaseEvent/EventProcessor.js.map +1 -0
- package/dist/src/BaseEvent/Process.d.ts +74 -0
- package/dist/src/BaseEvent/Process.js +142 -0
- package/dist/src/BaseEvent/Process.js.map +1 -0
- package/dist/src/BaseEvent/Transaction.d.ts +29 -0
- package/dist/src/BaseEvent/Transaction.js +244 -0
- package/dist/src/BaseEvent/Transaction.js.map +1 -0
- package/dist/src/Config/Configuration.d.ts +131 -0
- package/dist/src/Config/Configuration.js +153 -0
- package/dist/src/Config/Configuration.js.map +1 -0
- package/dist/src/Config/EnvironmentVar.d.ts +101 -0
- package/dist/src/Config/EnvironmentVar.js +213 -0
- package/dist/src/Config/EnvironmentVar.js.map +1 -0
- package/dist/src/Crypto/Crypto.d.ts +57 -0
- package/dist/src/Crypto/Crypto.js +126 -0
- package/dist/src/Crypto/Crypto.js.map +1 -0
- package/dist/src/Crypto/JWT.d.ts +64 -0
- package/dist/src/Crypto/JWT.js +74 -0
- package/dist/src/Crypto/JWT.js.map +1 -0
- package/dist/src/Globals.d.ts +161 -0
- package/dist/src/Globals.js +173 -0
- package/dist/src/Globals.js.map +1 -0
- package/dist/src/Logger/Logger.d.ts +180 -0
- package/dist/src/Logger/Logger.js +412 -0
- package/dist/src/Logger/Logger.js.map +1 -0
- package/dist/src/Mailer/Mailer.d.ts +107 -0
- package/dist/src/Mailer/Mailer.js +313 -0
- package/dist/src/Mailer/Mailer.js.map +1 -0
- package/dist/src/Publisher/Publisher.d.ts +47 -0
- package/dist/src/Publisher/Publisher.js +141 -0
- package/dist/src/Publisher/Publisher.js.map +1 -0
- package/dist/src/Server/RouteResolver.d.ts +41 -0
- package/dist/src/Server/RouteResolver.js +135 -0
- package/dist/src/Server/RouteResolver.js.map +1 -0
- package/dist/src/Server/Router.d.ts +104 -0
- package/dist/src/Server/Router.js +45 -0
- package/dist/src/Server/Router.js.map +1 -0
- package/dist/src/Server/lib/ContainerServer.d.ts +58 -0
- package/dist/src/Server/lib/ContainerServer.js +143 -0
- package/dist/src/Server/lib/ContainerServer.js.map +1 -0
- package/dist/src/Server/lib/Server.d.ts +60 -0
- package/dist/src/Server/lib/Server.js +137 -0
- package/dist/src/Server/lib/Server.js.map +1 -0
- package/dist/src/Server/lib/container/GenericHandler.d.ts +4 -0
- package/dist/src/Server/lib/container/GenericHandler.js +138 -0
- package/dist/src/Server/lib/container/GenericHandler.js.map +1 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +67 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.js +189 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -0
- package/dist/src/Server/lib/container/HealthHandler.d.ts +3 -0
- package/dist/src/Server/lib/container/HealthHandler.js +45 -0
- package/dist/src/Server/lib/container/HealthHandler.js.map +1 -0
- package/dist/src/Server/lib/container/Proxy.d.ts +95 -0
- package/dist/src/Server/lib/container/Proxy.js +201 -0
- package/dist/src/Server/lib/container/Proxy.js.map +1 -0
- package/dist/src/Server/lib/container/Utils.d.ts +18 -0
- package/dist/src/Server/lib/container/Utils.js +84 -0
- package/dist/src/Server/lib/container/Utils.js.map +1 -0
- package/dist/src/Validation/Validator.d.ts +21 -0
- package/dist/src/Validation/Validator.js +48 -0
- package/dist/src/Validation/Validator.js.map +1 -0
- package/index.ts +12 -10
- package/jest.config.ts +14 -21
- package/package.json +3 -3
- 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,36 +1,34 @@
|
|
|
1
|
-
import { expect as j_expect } from
|
|
2
|
-
import { expect } from
|
|
1
|
+
import { expect as j_expect } from '@jest/globals'
|
|
2
|
+
import { expect } from 'chai'
|
|
3
3
|
|
|
4
|
-
import Response from
|
|
5
|
-
import EventProcessor from
|
|
6
|
-
import Globals from
|
|
7
|
-
import { emptyQueueEvent, observableContext } from
|
|
4
|
+
import Response from '../../src/API/Response'
|
|
5
|
+
import EventProcessor from '../../src/BaseEvent/EventProcessor'
|
|
6
|
+
import Globals from '../../src/Globals'
|
|
7
|
+
import { emptyQueueEvent, observableContext } from '../Test.utils'
|
|
8
8
|
|
|
9
|
-
describe(
|
|
10
|
-
test(
|
|
11
|
-
const b = { name:
|
|
9
|
+
describe('EventProcessor success invocation path', () => {
|
|
10
|
+
test('Simple success', async () => {
|
|
11
|
+
const b = { name: '123' }
|
|
12
12
|
const context = observableContext()
|
|
13
13
|
const transaction = new EventProcessor(
|
|
14
14
|
emptyQueueEvent({
|
|
15
15
|
Records: [{ body: JSON.stringify(b) }, { body: JSON.stringify(b) }],
|
|
16
16
|
}),
|
|
17
17
|
context,
|
|
18
|
-
{}
|
|
18
|
+
{}
|
|
19
19
|
)
|
|
20
20
|
let count = 0
|
|
21
|
-
const handlerResp = await transaction.processEvent(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
},
|
|
27
|
-
)
|
|
21
|
+
const handlerResp = await transaction.processEvent(async (transaction, eventRecord) => {
|
|
22
|
+
expect(eventRecord).to.be.deep.equal(b)
|
|
23
|
+
count++
|
|
24
|
+
return Response.SuccessResponse(null)
|
|
25
|
+
})
|
|
28
26
|
// check resp
|
|
29
27
|
expect(count).to.be.equals(2)
|
|
30
28
|
expect(handlerResp).to.be.an.instanceof(Response)
|
|
31
29
|
if (handlerResp instanceof Response) {
|
|
32
30
|
expect(handlerResp?.getBody()).to.be.deep.equal({
|
|
33
|
-
transactionID:
|
|
31
|
+
transactionID: 'unknown',
|
|
34
32
|
})
|
|
35
33
|
expect(handlerResp.getCode()).to.be.equal(200)
|
|
36
34
|
}
|
|
@@ -40,31 +38,28 @@ describe("EventProcessor success invocation path", () => {
|
|
|
40
38
|
j_expect(context.succeed).not.toBeCalled()
|
|
41
39
|
})
|
|
42
40
|
|
|
43
|
-
test(
|
|
44
|
-
const b = { name:
|
|
41
|
+
test('Simple success - do not decode', async () => {
|
|
42
|
+
const b = { name: '123' }
|
|
45
43
|
const context = observableContext()
|
|
46
44
|
const transaction = new EventProcessor(
|
|
47
45
|
emptyQueueEvent({
|
|
48
46
|
Records: [{ body: JSON.stringify(b) }, { body: JSON.stringify(b) }],
|
|
49
47
|
}),
|
|
50
48
|
context,
|
|
51
|
-
{}
|
|
49
|
+
{}
|
|
52
50
|
)
|
|
53
51
|
let count = 0
|
|
54
|
-
const handlerResp = await transaction.processEvent(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
},
|
|
60
|
-
true,
|
|
61
|
-
)
|
|
52
|
+
const handlerResp = await transaction.processEvent(async (transaction, eventRecord) => {
|
|
53
|
+
expect(eventRecord).to.be.deep.equal(JSON.stringify(b))
|
|
54
|
+
count++
|
|
55
|
+
return Response.SuccessResponse(null)
|
|
56
|
+
}, true)
|
|
62
57
|
// check resp
|
|
63
58
|
expect(count).to.be.equals(2)
|
|
64
59
|
expect(handlerResp).to.be.an.instanceof(Response)
|
|
65
60
|
if (handlerResp instanceof Response) {
|
|
66
61
|
expect(handlerResp?.getBody()).to.be.deep.equal({
|
|
67
|
-
transactionID:
|
|
62
|
+
transactionID: 'unknown',
|
|
68
63
|
})
|
|
69
64
|
expect(handlerResp.getCode()).to.be.equal(200)
|
|
70
65
|
}
|
|
@@ -75,34 +70,30 @@ describe("EventProcessor success invocation path", () => {
|
|
|
75
70
|
})
|
|
76
71
|
})
|
|
77
72
|
|
|
78
|
-
describe(
|
|
79
|
-
test(
|
|
80
|
-
const b = { name:
|
|
73
|
+
describe('EventProcessor failure invocation path', () => {
|
|
74
|
+
test('Simple failure', async () => {
|
|
75
|
+
const b = { name: '123' }
|
|
81
76
|
const context = observableContext()
|
|
82
77
|
const transaction = new EventProcessor(
|
|
83
78
|
emptyQueueEvent({
|
|
84
79
|
Records: [
|
|
85
80
|
{ body: JSON.stringify(b) },
|
|
86
|
-
{ messageId:
|
|
81
|
+
{ messageId: '123', body: JSON.stringify(b) },
|
|
87
82
|
{ body: JSON.stringify(b) },
|
|
88
83
|
],
|
|
89
84
|
}),
|
|
90
85
|
context,
|
|
91
|
-
{}
|
|
86
|
+
{}
|
|
92
87
|
)
|
|
93
88
|
let count = 0
|
|
94
89
|
let handlerResp: any = null,
|
|
95
90
|
err: any = null
|
|
96
91
|
try {
|
|
97
|
-
handlerResp = await transaction.processEvent(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
? Response.SuccessResponse(null)
|
|
103
|
-
: Response.BadRequestResponse("Failed!")
|
|
104
|
-
},
|
|
105
|
-
)
|
|
92
|
+
handlerResp = await transaction.processEvent(async (transaction, eventRecord) => {
|
|
93
|
+
expect(eventRecord).to.be.deep.equal(b)
|
|
94
|
+
count++
|
|
95
|
+
return count == 1 ? Response.SuccessResponse(null) : Response.BadRequestResponse('Failed!')
|
|
96
|
+
})
|
|
106
97
|
} catch (e) {
|
|
107
98
|
err = e
|
|
108
99
|
}
|
|
@@ -112,10 +103,10 @@ describe("EventProcessor failure invocation path", () => {
|
|
|
112
103
|
expect(err).to.be.deep.equal(
|
|
113
104
|
new Error(
|
|
114
105
|
JSON.stringify({
|
|
115
|
-
err:
|
|
116
|
-
transactionID:
|
|
117
|
-
})
|
|
118
|
-
)
|
|
106
|
+
err: 'Failed!',
|
|
107
|
+
transactionID: 'unknown',
|
|
108
|
+
})
|
|
109
|
+
)
|
|
119
110
|
)
|
|
120
111
|
// ctx
|
|
121
112
|
j_expect(context.fail).not.toBeCalled()
|
|
@@ -123,19 +114,19 @@ describe("EventProcessor failure invocation path", () => {
|
|
|
123
114
|
j_expect(context.succeed).not.toBeCalled()
|
|
124
115
|
})
|
|
125
116
|
|
|
126
|
-
test(
|
|
127
|
-
const b = { name:
|
|
117
|
+
test('Simple failure w/ null', async () => {
|
|
118
|
+
const b = { name: '123' }
|
|
128
119
|
const context = observableContext()
|
|
129
120
|
const transaction = new EventProcessor(
|
|
130
121
|
emptyQueueEvent({
|
|
131
122
|
Records: [
|
|
132
123
|
{ body: JSON.stringify(b) },
|
|
133
|
-
{ messageId:
|
|
124
|
+
{ messageId: '123', body: JSON.stringify(b) },
|
|
134
125
|
{ body: JSON.stringify(b) },
|
|
135
126
|
],
|
|
136
127
|
}),
|
|
137
128
|
context,
|
|
138
|
-
{}
|
|
129
|
+
{}
|
|
139
130
|
)
|
|
140
131
|
let count = 0
|
|
141
132
|
let handlerResp: any = null,
|
|
@@ -147,7 +138,7 @@ describe("EventProcessor failure invocation path", () => {
|
|
|
147
138
|
expect(eventRecord).to.be.deep.equal(b)
|
|
148
139
|
count++
|
|
149
140
|
return null
|
|
150
|
-
}
|
|
141
|
+
}
|
|
151
142
|
)
|
|
152
143
|
} catch (e) {
|
|
153
144
|
err = e
|
|
@@ -161,9 +152,9 @@ describe("EventProcessor failure invocation path", () => {
|
|
|
161
152
|
err: Globals.ErrorResponseInvalidServerResponse,
|
|
162
153
|
rollback: true,
|
|
163
154
|
errCode: Globals.ErrorCode_APIError,
|
|
164
|
-
transactionID:
|
|
165
|
-
})
|
|
166
|
-
)
|
|
155
|
+
transactionID: 'unknown',
|
|
156
|
+
})
|
|
157
|
+
)
|
|
167
158
|
)
|
|
168
159
|
// ctx
|
|
169
160
|
j_expect(context.fail).not.toBeCalled()
|
|
@@ -171,34 +162,27 @@ describe("EventProcessor failure invocation path", () => {
|
|
|
171
162
|
j_expect(context.succeed).not.toBeCalled()
|
|
172
163
|
})
|
|
173
164
|
|
|
174
|
-
test(
|
|
175
|
-
const b = { name:
|
|
165
|
+
test('Simple failure - allow failures', async () => {
|
|
166
|
+
const b = { name: '123' }
|
|
176
167
|
const context = observableContext()
|
|
177
168
|
const transaction = new EventProcessor(
|
|
178
169
|
emptyQueueEvent({
|
|
179
|
-
Records: [
|
|
180
|
-
{ body: JSON.stringify(b) },
|
|
181
|
-
{ messageId: "123", body: JSON.stringify(b) },
|
|
182
|
-
],
|
|
170
|
+
Records: [{ body: JSON.stringify(b) }, { messageId: '123', body: JSON.stringify(b) }],
|
|
183
171
|
}),
|
|
184
172
|
context,
|
|
185
173
|
{},
|
|
186
|
-
true
|
|
174
|
+
true
|
|
187
175
|
)
|
|
188
176
|
let count = 0
|
|
189
|
-
const handlerResp = await transaction.processEvent(
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
? Response.SuccessResponse(null)
|
|
195
|
-
: Response.BadRequestResponse("Failed!")
|
|
196
|
-
},
|
|
197
|
-
)
|
|
177
|
+
const handlerResp = await transaction.processEvent(async (transaction, eventRecord) => {
|
|
178
|
+
expect(eventRecord).to.be.deep.equal(b)
|
|
179
|
+
count++
|
|
180
|
+
return count == 1 ? Response.SuccessResponse(null) : Response.BadRequestResponse('Failed!')
|
|
181
|
+
})
|
|
198
182
|
// check resp
|
|
199
183
|
expect(count).to.be.equals(2)
|
|
200
184
|
expect(handlerResp).to.be.deep.equal({
|
|
201
|
-
batchItemFailures: [{ itemIdentifier:
|
|
185
|
+
batchItemFailures: [{ itemIdentifier: '123' }],
|
|
202
186
|
})
|
|
203
187
|
// ctx
|
|
204
188
|
j_expect(context.fail).not.toBeCalled()
|
|
@@ -206,19 +190,19 @@ describe("EventProcessor failure invocation path", () => {
|
|
|
206
190
|
j_expect(context.succeed).not.toBeCalled()
|
|
207
191
|
})
|
|
208
192
|
|
|
209
|
-
test(
|
|
210
|
-
const b = { name:
|
|
193
|
+
test('Simple failure w/ null response - allow failures', async () => {
|
|
194
|
+
const b = { name: '123' }
|
|
211
195
|
const context = observableContext()
|
|
212
196
|
const transaction = new EventProcessor(
|
|
213
197
|
emptyQueueEvent({
|
|
214
198
|
Records: [
|
|
215
|
-
{ messageId:
|
|
216
|
-
{ messageId:
|
|
199
|
+
{ messageId: '456', body: JSON.stringify(b) },
|
|
200
|
+
{ messageId: '123', body: JSON.stringify(b) },
|
|
217
201
|
],
|
|
218
202
|
}),
|
|
219
203
|
context,
|
|
220
204
|
{},
|
|
221
|
-
true
|
|
205
|
+
true
|
|
222
206
|
)
|
|
223
207
|
let count = 0
|
|
224
208
|
const handlerResp = await transaction.processEvent(
|
|
@@ -227,12 +211,12 @@ describe("EventProcessor failure invocation path", () => {
|
|
|
227
211
|
expect(eventRecord).to.be.deep.equal(b)
|
|
228
212
|
count++
|
|
229
213
|
return null
|
|
230
|
-
}
|
|
214
|
+
}
|
|
231
215
|
)
|
|
232
216
|
// check resp
|
|
233
217
|
expect(count).to.be.equals(2)
|
|
234
218
|
expect(handlerResp).to.be.deep.equal({
|
|
235
|
-
batchItemFailures: [{ itemIdentifier:
|
|
219
|
+
batchItemFailures: [{ itemIdentifier: '456' }, { itemIdentifier: '123' }],
|
|
236
220
|
})
|
|
237
221
|
// ctx
|
|
238
222
|
j_expect(context.fail).not.toBeCalled()
|
|
@@ -240,7 +224,7 @@ describe("EventProcessor failure invocation path", () => {
|
|
|
240
224
|
j_expect(context.succeed).not.toBeCalled()
|
|
241
225
|
})
|
|
242
226
|
|
|
243
|
-
test(
|
|
227
|
+
test('Simple failure no records', async () => {
|
|
244
228
|
const context = observableContext()
|
|
245
229
|
const transaction = new EventProcessor(emptyQueueEvent(), context, {})
|
|
246
230
|
let count = 0
|
|
@@ -252,7 +236,7 @@ describe("EventProcessor failure invocation path", () => {
|
|
|
252
236
|
async () => {
|
|
253
237
|
count++
|
|
254
238
|
return null
|
|
255
|
-
}
|
|
239
|
+
}
|
|
256
240
|
)
|
|
257
241
|
} catch (e) {
|
|
258
242
|
err = e
|
|
@@ -265,8 +249,8 @@ describe("EventProcessor failure invocation path", () => {
|
|
|
265
249
|
JSON.stringify({
|
|
266
250
|
err: Globals.ErrorResponseNoRecords,
|
|
267
251
|
errCode: Globals.ErrorCode_NoRecords,
|
|
268
|
-
})
|
|
269
|
-
)
|
|
252
|
+
})
|
|
253
|
+
)
|
|
270
254
|
)
|
|
271
255
|
// ctx
|
|
272
256
|
j_expect(context.fail).not.toBeCalled()
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { expect } from
|
|
1
|
+
import { expect } from 'chai'
|
|
2
2
|
|
|
3
|
-
import Response from
|
|
4
|
-
import Process from
|
|
3
|
+
import Response from '../../src/API/Response'
|
|
4
|
+
import Process from '../../src/BaseEvent/Process'
|
|
5
5
|
|
|
6
|
-
describe(
|
|
7
|
-
test(
|
|
8
|
-
const b = { name:
|
|
6
|
+
describe('Process success invocation path', () => {
|
|
7
|
+
test('Simple success', async () => {
|
|
8
|
+
const b = { name: '123' }
|
|
9
9
|
const proc = new Process({}, 100)
|
|
10
10
|
let count = 0
|
|
11
11
|
const handlerResp = await proc.execute(async () => {
|
|
@@ -15,7 +15,7 @@ describe("Process success invocation path", () => {
|
|
|
15
15
|
// check resp
|
|
16
16
|
expect(handlerResp).to.be.undefined
|
|
17
17
|
// check iterations
|
|
18
|
-
return new Promise(
|
|
18
|
+
return new Promise(resolve => {
|
|
19
19
|
setTimeout(() => {
|
|
20
20
|
expect(count).to.be.equals(2)
|
|
21
21
|
clearInterval(proc.interval)
|
|
@@ -25,18 +25,18 @@ describe("Process success invocation path", () => {
|
|
|
25
25
|
})
|
|
26
26
|
})
|
|
27
27
|
|
|
28
|
-
describe(
|
|
29
|
-
test(
|
|
28
|
+
describe('Process failure invocation path', () => {
|
|
29
|
+
test('Simple failure', async () => {
|
|
30
30
|
const proc = new Process({}, 100)
|
|
31
31
|
let count = 0
|
|
32
32
|
const handlerResp = await proc.execute(async () => {
|
|
33
33
|
count++
|
|
34
|
-
throw new Error(
|
|
34
|
+
throw new Error('Failed!')
|
|
35
35
|
})
|
|
36
36
|
// check resp
|
|
37
37
|
expect(handlerResp).to.be.undefined
|
|
38
38
|
// check iterations
|
|
39
|
-
return new Promise(
|
|
39
|
+
return new Promise(resolve => {
|
|
40
40
|
setTimeout(() => {
|
|
41
41
|
expect(count).to.be.equals(2)
|
|
42
42
|
clearInterval(proc.interval)
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { expect as j_expect } from
|
|
2
|
-
import { expect } from
|
|
1
|
+
import { expect as j_expect } from '@jest/globals'
|
|
2
|
+
import { expect } from 'chai'
|
|
3
3
|
|
|
4
|
-
import Response from
|
|
5
|
-
import Transaction from
|
|
6
|
-
import Globals from
|
|
7
|
-
import { defaultHeaders, emptyEvent, observableContext } from
|
|
4
|
+
import Response from '../../src/API/Response'
|
|
5
|
+
import Transaction from '../../src/BaseEvent/Transaction'
|
|
6
|
+
import Globals from '../../src/Globals'
|
|
7
|
+
import { defaultHeaders, emptyEvent, observableContext } from '../Test.utils'
|
|
8
8
|
|
|
9
|
-
describe(
|
|
10
|
-
test(
|
|
11
|
-
const b = { name:
|
|
9
|
+
describe('Transaction success invocation path', () => {
|
|
10
|
+
test('Simple success', async () => {
|
|
11
|
+
const b = { name: '123' }
|
|
12
12
|
const context = observableContext()
|
|
13
13
|
const transaction = new Transaction<null, typeof b>(emptyEvent(), context)
|
|
14
14
|
const handlerResp = await transaction.execute(async () => {
|
|
@@ -26,8 +26,8 @@ describe("Transaction success invocation path", () => {
|
|
|
26
26
|
})
|
|
27
27
|
})
|
|
28
28
|
|
|
29
|
-
test(
|
|
30
|
-
const b = { name:
|
|
29
|
+
test('Simple success - sync return', async () => {
|
|
30
|
+
const b = { name: '123' }
|
|
31
31
|
const context = observableContext()
|
|
32
32
|
const transaction = new Transaction<null, typeof b>(emptyEvent(), context, {
|
|
33
33
|
syncReturn: true,
|
|
@@ -46,15 +46,15 @@ describe("Transaction success invocation path", () => {
|
|
|
46
46
|
})
|
|
47
47
|
})
|
|
48
48
|
|
|
49
|
-
describe(
|
|
50
|
-
test(
|
|
49
|
+
describe('Transaction error invocation path without response', () => {
|
|
50
|
+
test('Not valid response returned success', async () => {
|
|
51
51
|
const b = {
|
|
52
52
|
err: Globals.ErrorResponseInvalidServerResponse,
|
|
53
53
|
rollback: true,
|
|
54
54
|
errCode: Globals.ErrorCode_APIError,
|
|
55
|
-
transactionID:
|
|
55
|
+
transactionID: '123',
|
|
56
56
|
}
|
|
57
|
-
const context = observableContext({ awsRequestId:
|
|
57
|
+
const context = observableContext({ awsRequestId: '123' })
|
|
58
58
|
const transaction = new Transaction<null, typeof b>(emptyEvent(), context)
|
|
59
59
|
const handlerResp = await transaction.execute(async () => {
|
|
60
60
|
return null
|
|
@@ -71,22 +71,22 @@ describe("Transaction error invocation path without response", () => {
|
|
|
71
71
|
})
|
|
72
72
|
})
|
|
73
73
|
|
|
74
|
-
test(
|
|
74
|
+
test('Not valid response returned success - sync return', async () => {
|
|
75
75
|
const b = {
|
|
76
76
|
err: Globals.ErrorResponseInvalidServerResponse,
|
|
77
77
|
rollback: true,
|
|
78
78
|
errCode: Globals.ErrorCode_APIError,
|
|
79
|
-
transactionID:
|
|
79
|
+
transactionID: '123',
|
|
80
80
|
}
|
|
81
81
|
const context = observableContext()
|
|
82
82
|
const transaction = new Transaction<null, typeof b>(
|
|
83
83
|
emptyEvent({
|
|
84
|
-
requestContext: { requestId:
|
|
84
|
+
requestContext: { requestId: '123' },
|
|
85
85
|
}),
|
|
86
86
|
context,
|
|
87
87
|
{
|
|
88
88
|
syncReturn: true,
|
|
89
|
-
}
|
|
89
|
+
}
|
|
90
90
|
)
|
|
91
91
|
const handlerResp = await transaction.execute(async () => {
|
|
92
92
|
return null
|
|
@@ -102,20 +102,17 @@ describe("Transaction error invocation path without response", () => {
|
|
|
102
102
|
})
|
|
103
103
|
})
|
|
104
104
|
|
|
105
|
-
describe(
|
|
106
|
-
test(
|
|
105
|
+
describe('Transaction error invocation path with non-Response class response', () => {
|
|
106
|
+
test('Not a response-class response returned success', async () => {
|
|
107
107
|
const b = {
|
|
108
108
|
err: Globals.ErrorResponseInvalidServerResponse,
|
|
109
109
|
rollback: true,
|
|
110
110
|
errCode: Globals.ErrorCode_APIError,
|
|
111
|
-
transactionID:
|
|
111
|
+
transactionID: 'unknown',
|
|
112
112
|
}
|
|
113
|
-
const b2 = { name:
|
|
113
|
+
const b2 = { name: 'abc' }
|
|
114
114
|
const context = observableContext()
|
|
115
|
-
const transaction = new Transaction<null, null, typeof b2>(
|
|
116
|
-
emptyEvent(),
|
|
117
|
-
context,
|
|
118
|
-
)
|
|
115
|
+
const transaction = new Transaction<null, null, typeof b2>(emptyEvent(), context)
|
|
119
116
|
const handlerResp = await transaction.execute(async () => {
|
|
120
117
|
return b2
|
|
121
118
|
})
|
|
@@ -131,14 +128,12 @@ describe("Transaction error invocation path with non-Response class response", (
|
|
|
131
128
|
})
|
|
132
129
|
})
|
|
133
130
|
|
|
134
|
-
test(
|
|
135
|
-
const b2 = { name:
|
|
131
|
+
test('Not a response-class response returned success - sync return', async () => {
|
|
132
|
+
const b2 = { name: 'abc' }
|
|
136
133
|
const context = observableContext()
|
|
137
|
-
const transaction = new Transaction<null, null, typeof b2>(
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
{ syncReturn: true },
|
|
141
|
-
)
|
|
134
|
+
const transaction = new Transaction<null, null, typeof b2>(emptyEvent(), context, {
|
|
135
|
+
syncReturn: true,
|
|
136
|
+
})
|
|
142
137
|
const handlerResp = await transaction.execute(async () => {
|
|
143
138
|
return b2
|
|
144
139
|
})
|
|
@@ -151,18 +146,18 @@ describe("Transaction error invocation path with non-Response class response", (
|
|
|
151
146
|
})
|
|
152
147
|
})
|
|
153
148
|
|
|
154
|
-
describe(
|
|
155
|
-
test(
|
|
149
|
+
describe('Transaction error invocation path with exception', () => {
|
|
150
|
+
test('Transaction exception', async () => {
|
|
156
151
|
const b = {
|
|
157
152
|
err: Globals.ErrorResponseUnhandledError,
|
|
158
153
|
rollback: true,
|
|
159
154
|
errCode: Globals.ErrorCode_APIError,
|
|
160
|
-
transactionID:
|
|
155
|
+
transactionID: 'unknown',
|
|
161
156
|
}
|
|
162
157
|
const context = observableContext()
|
|
163
158
|
const transaction = new Transaction<null, null, null>(emptyEvent(), context)
|
|
164
159
|
const handlerResp = await transaction.execute(async () => {
|
|
165
|
-
throw new Error(
|
|
160
|
+
throw new Error('Failed!')
|
|
166
161
|
})
|
|
167
162
|
// check resp
|
|
168
163
|
expect(handlerResp).to.be.null
|
|
@@ -176,21 +171,19 @@ describe("Transaction error invocation path with exception", () => {
|
|
|
176
171
|
})
|
|
177
172
|
})
|
|
178
173
|
|
|
179
|
-
test(
|
|
174
|
+
test('Transaction exception - sync return', async () => {
|
|
180
175
|
const b = {
|
|
181
176
|
err: Globals.ErrorResponseUnhandledError,
|
|
182
177
|
rollback: true,
|
|
183
178
|
errCode: Globals.ErrorCode_APIError,
|
|
184
|
-
transactionID:
|
|
179
|
+
transactionID: 'unknown',
|
|
185
180
|
}
|
|
186
181
|
const context = observableContext()
|
|
187
|
-
const transaction = new Transaction<null, null, null>(
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
{ syncReturn: true },
|
|
191
|
-
)
|
|
182
|
+
const transaction = new Transaction<null, null, null>(emptyEvent(), context, {
|
|
183
|
+
syncReturn: true,
|
|
184
|
+
})
|
|
192
185
|
const handlerResp = await transaction.execute(async () => {
|
|
193
|
-
throw new Error(
|
|
186
|
+
throw new Error('Failed!')
|
|
194
187
|
})
|
|
195
188
|
// check resp
|
|
196
189
|
expect(handlerResp?.getBody()).to.be.deep.equals(b)
|
|
@@ -201,14 +194,12 @@ describe("Transaction error invocation path with exception", () => {
|
|
|
201
194
|
j_expect(context.succeed).not.toBeCalled()
|
|
202
195
|
})
|
|
203
196
|
|
|
204
|
-
test(
|
|
197
|
+
test('Transaction exception - sync return', async () => {
|
|
205
198
|
const context = observableContext()
|
|
206
|
-
const transaction = new Transaction<null, null, null>(
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
)
|
|
211
|
-
const error = new Error("Failed!")
|
|
199
|
+
const transaction = new Transaction<null, null, null>(emptyEvent(), context, {
|
|
200
|
+
throwOnErrors: true,
|
|
201
|
+
})
|
|
202
|
+
const error = new Error('Failed!')
|
|
212
203
|
let handlerResp: any = null,
|
|
213
204
|
err: any = null
|
|
214
205
|
try {
|