@creator.co/wapi 1.2.4 → 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/.github/workflows/npmpublish.yml +1 -1
- package/README.md +216 -5
- package/dist/index.d.ts +15 -0
- package/dist/index.js.map +1 -1
- package/dist/jest.config.js +1 -1
- package/dist/jest.config.js.map +1 -1
- package/dist/package.json +13 -2
- 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 +104 -2
- package/dist/src/BaseEvent/Transaction.js +196 -41
- 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/Database/Database.d.ts +18 -0
- package/dist/src/Database/Database.js +18 -0
- package/dist/src/Database/Database.js.map +1 -0
- package/dist/src/Database/DatabaseManager.d.ts +32 -0
- package/dist/src/Database/DatabaseManager.js +50 -0
- package/dist/src/Database/DatabaseManager.js.map +1 -0
- package/dist/src/Database/DatabaseTransaction.d.ts +65 -0
- package/dist/src/Database/DatabaseTransaction.js +183 -0
- package/dist/src/Database/DatabaseTransaction.js.map +1 -0
- package/dist/src/Database/integrations/knex/KnexDatabase.d.ts +22 -0
- package/dist/src/Database/integrations/knex/KnexDatabase.js +108 -0
- package/dist/src/Database/integrations/knex/KnexDatabase.js.map +1 -0
- package/dist/src/Database/integrations/knex/KnexTransaction.d.ts +37 -0
- package/dist/src/Database/integrations/knex/KnexTransaction.js +60 -0
- package/dist/src/Database/integrations/knex/KnexTransaction.js.map +1 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +30 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +108 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +37 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +60 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -0
- 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 +52 -52
- 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/jest.config.ts +1 -1
- package/package.json +13 -2
- 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 +147 -27
- 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/Database/Database.ts +19 -0
- package/src/Database/DatabaseManager.ts +51 -0
- package/src/Database/DatabaseTransaction.ts +118 -0
- package/src/Database/integrations/knex/KnexDatabase.ts +47 -0
- package/src/Database/integrations/knex/KnexTransaction.ts +51 -0
- package/src/Database/integrations/pgsql/PostgresDatabase.ts +49 -0
- package/src/Database/integrations/pgsql/PostgresTransaction.ts +54 -0
- package/src/Database/types.d.ts +49 -0
- 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 +39 -58
- 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 +102 -44
- package/tests/Config/Config.test.ts +27 -27
- package/tests/Config/EnvironmentVar.test.ts +54 -18
- package/tests/Database/DatabaseManager.test.ts +55 -0
- package/tests/Database/integrations/knex/KnexDatabase.test.ts +53 -0
- package/tests/Database/integrations/knex/KnexTransaction.test.ts +133 -0
- package/tests/Database/integrations/pg/PostgresDatabase.test.ts +50 -0
- package/tests/Database/integrations/pg/PostgresTransaction.test.ts +51 -0
- 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 +6 -1
|
@@ -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,8 +1,8 @@
|
|
|
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'
|
|
5
|
+
import type { DbConfig } from '../../src/Database/types'
|
|
6
6
|
import Globals from '../../src/Globals'
|
|
7
7
|
import { defaultHeaders, emptyEvent, observableContext } from '../Test.utils'
|
|
8
8
|
|
|
@@ -15,11 +15,11 @@ describe('Transaction success invocation path', () => {
|
|
|
15
15
|
return Response.SuccessResponse(b)
|
|
16
16
|
})
|
|
17
17
|
// check resp
|
|
18
|
-
|
|
18
|
+
c_expect(handlerResp).to.be.null
|
|
19
19
|
// ctx
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
expect(context.fail).not.toBeCalled()
|
|
21
|
+
expect(context.done).not.toBeCalled()
|
|
22
|
+
expect(context.succeed).toBeCalledWith({
|
|
23
23
|
statusCode: 200,
|
|
24
24
|
body: JSON.stringify(b),
|
|
25
25
|
headers: defaultHeaders,
|
|
@@ -36,13 +36,13 @@ describe('Transaction success invocation path', () => {
|
|
|
36
36
|
return Response.SuccessResponse(b)
|
|
37
37
|
})
|
|
38
38
|
// check resp
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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)
|
|
42
42
|
// ctx
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
expect(context.fail).not.toBeCalled()
|
|
44
|
+
expect(context.done).not.toBeCalled()
|
|
45
|
+
expect(context.succeed).not.toBeCalled()
|
|
46
46
|
})
|
|
47
47
|
})
|
|
48
48
|
|
|
@@ -60,11 +60,11 @@ describe('Transaction error invocation path without response', () => {
|
|
|
60
60
|
return null
|
|
61
61
|
})
|
|
62
62
|
// check resp
|
|
63
|
-
|
|
63
|
+
c_expect(handlerResp).to.be.null
|
|
64
64
|
// ctx
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
expect(context.fail).not.toBeCalled()
|
|
66
|
+
expect(context.done).not.toBeCalled()
|
|
67
|
+
expect(context.succeed).toBeCalledWith({
|
|
68
68
|
statusCode: 400,
|
|
69
69
|
body: JSON.stringify(b),
|
|
70
70
|
headers: defaultHeaders,
|
|
@@ -92,13 +92,13 @@ describe('Transaction error invocation path without response', () => {
|
|
|
92
92
|
return null
|
|
93
93
|
})
|
|
94
94
|
// check resp
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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)
|
|
98
98
|
// ctx
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
expect(context.fail).not.toBeCalled()
|
|
100
|
+
expect(context.done).not.toBeCalled()
|
|
101
|
+
expect(context.succeed).not.toBeCalled()
|
|
102
102
|
})
|
|
103
103
|
})
|
|
104
104
|
|
|
@@ -117,11 +117,11 @@ describe('Transaction error invocation path with non-Response class response', (
|
|
|
117
117
|
return b2
|
|
118
118
|
})
|
|
119
119
|
// check resp
|
|
120
|
-
|
|
120
|
+
c_expect(handlerResp).to.be.null
|
|
121
121
|
// ctx
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
expect(context.fail).not.toBeCalled()
|
|
123
|
+
expect(context.done).not.toBeCalled()
|
|
124
|
+
expect(context.succeed).toBeCalledWith({
|
|
125
125
|
statusCode: 400,
|
|
126
126
|
body: JSON.stringify(b),
|
|
127
127
|
headers: defaultHeaders,
|
|
@@ -138,11 +138,11 @@ describe('Transaction error invocation path with non-Response class response', (
|
|
|
138
138
|
return b2
|
|
139
139
|
})
|
|
140
140
|
// check resp
|
|
141
|
-
|
|
141
|
+
c_expect(handlerResp).to.be.deep.equals(b2)
|
|
142
142
|
// ctx
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
143
|
+
expect(context.fail).not.toBeCalled()
|
|
144
|
+
expect(context.done).not.toBeCalled()
|
|
145
|
+
expect(context.succeed).not.toBeCalled()
|
|
146
146
|
})
|
|
147
147
|
})
|
|
148
148
|
|
|
@@ -160,11 +160,11 @@ describe('Transaction error invocation path with exception', () => {
|
|
|
160
160
|
throw new Error('Failed!')
|
|
161
161
|
})
|
|
162
162
|
// check resp
|
|
163
|
-
|
|
163
|
+
c_expect(handlerResp).to.be.null
|
|
164
164
|
// ctx
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
165
|
+
expect(context.fail).not.toBeCalled()
|
|
166
|
+
expect(context.done).not.toBeCalled()
|
|
167
|
+
expect(context.succeed).toBeCalledWith({
|
|
168
168
|
statusCode: 400,
|
|
169
169
|
body: JSON.stringify(b),
|
|
170
170
|
headers: defaultHeaders,
|
|
@@ -186,12 +186,12 @@ describe('Transaction error invocation path with exception', () => {
|
|
|
186
186
|
throw new Error('Failed!')
|
|
187
187
|
})
|
|
188
188
|
// check resp
|
|
189
|
-
|
|
190
|
-
|
|
189
|
+
c_expect(handlerResp?.getBody()).to.be.deep.equals(b)
|
|
190
|
+
c_expect(handlerResp?.getCode()).to.be.equals(400)
|
|
191
191
|
// ctx
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
192
|
+
expect(context.fail).not.toBeCalled()
|
|
193
|
+
expect(context.done).not.toBeCalled()
|
|
194
|
+
expect(context.succeed).not.toBeCalled()
|
|
195
195
|
})
|
|
196
196
|
|
|
197
197
|
test('Transaction exception - sync return', async () => {
|
|
@@ -210,12 +210,70 @@ describe('Transaction error invocation path with exception', () => {
|
|
|
210
210
|
err = e
|
|
211
211
|
}
|
|
212
212
|
// check resp
|
|
213
|
-
|
|
214
|
-
|
|
213
|
+
c_expect(handlerResp).to.be.null
|
|
214
|
+
c_expect(err).to.be.deep.equals(error)
|
|
215
215
|
// ctx
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
216
|
+
expect(context.fail).not.toBeCalled()
|
|
217
|
+
expect(context.done).not.toBeCalled()
|
|
218
|
+
expect(context.succeed).not.toBeCalled()
|
|
219
|
+
})
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
describe('Transaction - db integration', () => {
|
|
223
|
+
const testResources = () => {
|
|
224
|
+
const mockTrans = {
|
|
225
|
+
select: jest.fn(),
|
|
226
|
+
closeSuccess: jest.fn(),
|
|
227
|
+
closeFailure: jest.fn(),
|
|
228
|
+
}
|
|
229
|
+
const mockCreate = jest.fn(
|
|
230
|
+
() => ({ transaction: () => new Promise(resolve => resolve(mockTrans)) }) as any
|
|
231
|
+
)
|
|
232
|
+
|
|
233
|
+
const transaction = new Transaction(emptyEvent(), observableContext())
|
|
234
|
+
transaction['databaseManager'] = {
|
|
235
|
+
create: mockCreate,
|
|
236
|
+
} as any
|
|
237
|
+
|
|
238
|
+
return {
|
|
239
|
+
transaction,
|
|
240
|
+
mockCreate,
|
|
241
|
+
mockTrans,
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const config = { username: 'test' } as DbConfig<'knex'>
|
|
246
|
+
|
|
247
|
+
test('Transaction provides dbTransaction and calls closeSuccess', async () => {
|
|
248
|
+
const { mockCreate, mockTrans, transaction } = testResources()
|
|
249
|
+
|
|
250
|
+
await transaction.execute(async () => {
|
|
251
|
+
const knexTransaction = await transaction.getDbTransaction(config)
|
|
252
|
+
|
|
253
|
+
knexTransaction.select('name')
|
|
254
|
+
|
|
255
|
+
return Response.SuccessResponse(null)
|
|
256
|
+
})
|
|
257
|
+
expect(mockCreate).toBeCalledWith(config)
|
|
258
|
+
expect(mockTrans.select).toBeCalledWith('name')
|
|
259
|
+
expect(mockTrans.closeSuccess).toBeCalled()
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
test('Errored transaction calls closeFailure', async () => {
|
|
263
|
+
const { mockCreate, transaction, mockTrans } = testResources()
|
|
264
|
+
|
|
265
|
+
const ss = await transaction.execute(async () => {
|
|
266
|
+
const _ii = await transaction.getDbTransaction(config)
|
|
267
|
+
console.log('ii', _ii)
|
|
268
|
+
throw new Error('Something went wrong!')
|
|
269
|
+
|
|
270
|
+
return Response.SuccessResponse(null)
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
console.log(ss)
|
|
274
|
+
|
|
275
|
+
expect(mockCreate).toBeCalledWith(config)
|
|
276
|
+
expect(mockTrans.closeFailure).toBeCalled()
|
|
219
277
|
})
|
|
220
278
|
})
|
|
221
279
|
|
|
@@ -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
|
|