@creator.co/wapi 1.7.1-alpha1 → 1.7.1-alpha3
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/coverage/clover.xml +1088 -0
- package/coverage/coverage/coverage.txt +40 -0
- package/coverage/coverage-final.json +37 -0
- package/coverage/coverage-summary.json +38 -0
- package/coverage/coverage.txt +59 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +371 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov-report/src/API/Request.ts.html +727 -0
- package/coverage/lcov-report/src/API/Response.ts.html +1189 -0
- package/coverage/lcov-report/src/API/Utils.ts.html +313 -0
- package/coverage/lcov-report/src/API/index.html +131 -0
- package/coverage/lcov-report/src/BaseEvent/EventProcessor.ts.html +496 -0
- package/coverage/lcov-report/src/BaseEvent/Process.ts.html +346 -0
- package/coverage/lcov-report/src/BaseEvent/Transaction.ts.html +1015 -0
- package/coverage/lcov-report/src/BaseEvent/index.html +146 -0
- package/coverage/lcov-report/src/Cache/Redis.ts.html +367 -0
- package/coverage/lcov-report/src/Cache/index.html +116 -0
- package/coverage/lcov-report/src/Config/Configuration.ts.html +700 -0
- package/coverage/lcov-report/src/Config/EnvironmentVar.ts.html +526 -0
- package/coverage/lcov-report/src/Config/index.html +131 -0
- package/coverage/lcov-report/src/Crypto/Crypto.ts.html +352 -0
- package/coverage/lcov-report/src/Crypto/JWT.ts.html +337 -0
- package/coverage/lcov-report/src/Crypto/index.html +131 -0
- package/coverage/lcov-report/src/Database/Database.ts.html +151 -0
- package/coverage/lcov-report/src/Database/DatabaseManager.ts.html +289 -0
- package/coverage/lcov-report/src/Database/DatabaseTransaction.ts.html +595 -0
- package/coverage/lcov-report/src/Database/index.html +161 -0
- package/coverage/lcov-report/src/Database/index.ts.html +169 -0
- package/coverage/lcov-report/src/Database/integrations/knex/KnexDatabase.ts.html +283 -0
- package/coverage/lcov-report/src/Database/integrations/knex/KnexTransaction.ts.html +337 -0
- package/coverage/lcov-report/src/Database/integrations/knex/index.html +131 -0
- package/coverage/lcov-report/src/Database/integrations/kysely/KyselyDatabase.ts.html +376 -0
- package/coverage/lcov-report/src/Database/integrations/kysely/KyselyTransaction.ts.html +601 -0
- package/coverage/lcov-report/src/Database/integrations/kysely/index.html +131 -0
- package/coverage/lcov-report/src/Database/integrations/pgsql/PostgresDatabase.ts.html +250 -0
- package/coverage/lcov-report/src/Database/integrations/pgsql/PostgresTransaction.ts.html +346 -0
- package/coverage/lcov-report/src/Database/integrations/pgsql/index.html +131 -0
- package/coverage/lcov-report/src/Database/types.d.ts.html +232 -0
- package/coverage/lcov-report/src/Globals.ts.html +394 -0
- package/coverage/lcov-report/src/Logger/Logger.ts.html +1138 -0
- package/coverage/lcov-report/src/Logger/index.html +116 -0
- package/coverage/lcov-report/src/Mailer/Mailer.ts.html +754 -0
- package/coverage/lcov-report/src/Mailer/index.html +116 -0
- package/coverage/lcov-report/src/Publisher/Publisher.ts.html +460 -0
- package/coverage/lcov-report/src/Publisher/index.html +116 -0
- package/coverage/lcov-report/src/Server/RouteResolver.ts.html +442 -0
- package/coverage/lcov-report/src/Server/Router.ts.html +616 -0
- package/coverage/lcov-report/src/Server/index.html +131 -0
- package/coverage/lcov-report/src/Server/lib/ContainerServer.ts.html +280 -0
- package/coverage/lcov-report/src/Server/lib/Server.ts.html +403 -0
- package/coverage/lcov-report/src/Server/lib/container/GenericHandler.ts.html +331 -0
- package/coverage/lcov-report/src/Server/lib/container/GenericHandlerEvent.ts.html +547 -0
- package/coverage/lcov-report/src/Server/lib/container/HealthHandler.ts.html +118 -0
- package/coverage/lcov-report/src/Server/lib/container/Proxy.ts.html +619 -0
- package/coverage/lcov-report/src/Server/lib/container/Utils.ts.html +184 -0
- package/coverage/lcov-report/src/Server/lib/container/index.html +176 -0
- package/coverage/lcov-report/src/Server/lib/index.html +131 -0
- package/coverage/lcov-report/src/Util/AsyncSingleton.ts.html +343 -0
- package/coverage/lcov-report/src/Util/Utils.ts.html +313 -0
- package/coverage/lcov-report/src/Util/index.html +131 -0
- package/coverage/lcov-report/src/Validation/Validator.ts.html +217 -0
- package/coverage/lcov-report/src/Validation/index.html +116 -0
- package/coverage/lcov-report/src/index.html +116 -0
- package/coverage/lcov.info +2326 -0
- package/dist/package-lock.json +2 -2
- package/dist/package.json +1 -1
- package/package.json +1 -1
- package/.eslintignore +0 -3
- package/.eslintrc.cjs +0 -60
- package/.github/workflows/npmpublish.yml +0 -11
- package/.github/workflows/prs.yml +0 -13
- package/jest.config.ts +0 -33
- package/jest.smoke.config.ts +0 -35
- package/tests/API/Request.test.ts +0 -273
- package/tests/API/Response.test.ts +0 -367
- package/tests/API/Utils.test.ts +0 -167
- package/tests/BaseEvent/EventProcessor.test.ts +0 -261
- package/tests/BaseEvent/Process.test.ts +0 -49
- package/tests/BaseEvent/Transaction.test.ts +0 -408
- package/tests/Cache/Redis-client.test.ts +0 -90
- package/tests/Cache/Redis-cluster.test.ts +0 -100
- package/tests/Config/Config.test.ts +0 -205
- package/tests/Config/EnvironmentVar.test.ts +0 -250
- package/tests/Crypto/Crypto.test.ts +0 -88
- package/tests/Crypto/JWT.test.ts +0 -92
- package/tests/Database/DatabaseManager.test.ts +0 -71
- package/tests/Database/integrations/knex/KnexDatabase.test.ts +0 -76
- package/tests/Database/integrations/knex/KnexTransaction.test.ts +0 -149
- package/tests/Database/integrations/kysely/KyselyDatabase.test.ts +0 -113
- package/tests/Database/integrations/kysely/KyselyTransaction.test.ts +0 -119
- package/tests/Database/integrations/pg/PostgresDatabase.test.ts +0 -76
- package/tests/Database/integrations/pg/PostgresTransaction.test.ts +0 -118
- package/tests/Logger/Logger.test.ts +0 -219
- package/tests/Mailer/Mailer.test.ts +0 -59
- package/tests/Publisher/Publisher.test.ts +0 -94
- package/tests/Server/RouteResolver.test.ts +0 -102
- package/tests/Server/Router.test.ts +0 -39
- package/tests/Server/lib/ContainerServer.test.ts +0 -531
- package/tests/Server/lib/Server.test.ts +0 -12
- package/tests/Server/lib/container/GenericHandler.test.ts +0 -131
- package/tests/Server/lib/container/GenericHandlerEvent.test.ts +0 -103
- package/tests/Server/lib/container/HealthHandler.test.ts +0 -30
- package/tests/Server/lib/container/Proxy.test.ts +0 -268
- package/tests/Server/lib/container/Utils.test.ts +0 -47
- package/tests/Test.utils.ts +0 -74
- package/tests/Validation/Validator.test.ts +0 -76
- package/tsconfig.json +0 -26
- package/tsconfig.smoke.json +0 -26
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { jest } from '@jest/globals'
|
|
2
|
-
import { APIGatewayProxyEvent, Context } from 'aws-lambda'
|
|
3
|
-
import { expect as c_expect } from 'chai'
|
|
4
|
-
import { Request, Response } from 'express'
|
|
5
|
-
|
|
6
|
-
import Globals from '../../../../src/Globals'
|
|
7
|
-
import GenericHandler from '../../../../src/Server/lib/container/GenericHandler'
|
|
8
|
-
|
|
9
|
-
function observableResponse(): Response {
|
|
10
|
-
const resp = <Response>(<unknown>{
|
|
11
|
-
send: jest.fn(() => resp),
|
|
12
|
-
json: jest.fn(() => resp),
|
|
13
|
-
status: jest.fn(() => resp),
|
|
14
|
-
header: jest.fn(() => resp),
|
|
15
|
-
})
|
|
16
|
-
return resp
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
describe('GenericHandler success invocation path', () => {
|
|
20
|
-
test('Simple success', async () => {
|
|
21
|
-
const v = {
|
|
22
|
-
statusCode: 200,
|
|
23
|
-
body: JSON.stringify({ id: 123 }),
|
|
24
|
-
}
|
|
25
|
-
const handler = GenericHandler(async (event: APIGatewayProxyEvent, context: Context) => {
|
|
26
|
-
context.succeed(v)
|
|
27
|
-
})
|
|
28
|
-
const resp = observableResponse()
|
|
29
|
-
const handlerResp = await handler(<Request>(<unknown>{}), resp)
|
|
30
|
-
//
|
|
31
|
-
c_expect(handlerResp).to.be.undefined
|
|
32
|
-
expect(resp.send).not.toBeCalled()
|
|
33
|
-
expect(resp.json).toBeCalledWith(JSON.parse(v.body))
|
|
34
|
-
expect(resp.status).toBeCalledWith(v.statusCode)
|
|
35
|
-
expect(resp.header).not.toBeCalled()
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
test('Simple success w/ headers', async () => {
|
|
39
|
-
const v = {
|
|
40
|
-
statusCode: 200,
|
|
41
|
-
body: JSON.stringify({ id: 123 }),
|
|
42
|
-
headers: { Authorization: 123 },
|
|
43
|
-
}
|
|
44
|
-
const handler = GenericHandler(async (event: APIGatewayProxyEvent, context: Context) => {
|
|
45
|
-
context.succeed(v)
|
|
46
|
-
})
|
|
47
|
-
const resp = observableResponse()
|
|
48
|
-
const handlerResp = await handler(<Request>(<unknown>{}), resp)
|
|
49
|
-
//
|
|
50
|
-
c_expect(handlerResp).to.be.undefined
|
|
51
|
-
expect(resp.send).not.toBeCalled()
|
|
52
|
-
expect(resp.json).toBeCalledWith(JSON.parse(v.body))
|
|
53
|
-
expect(resp.status).toBeCalledWith(v.statusCode)
|
|
54
|
-
expect(resp.header).toBeCalledTimes(Object.keys(v.headers).length)
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
test('Simple success w/ null body', async () => {
|
|
58
|
-
const v = {
|
|
59
|
-
statusCode: 200,
|
|
60
|
-
headers: { Authorization: 123 },
|
|
61
|
-
}
|
|
62
|
-
const handler = GenericHandler(async (event: APIGatewayProxyEvent, context: Context) => {
|
|
63
|
-
context.succeed(v)
|
|
64
|
-
})
|
|
65
|
-
const resp = observableResponse()
|
|
66
|
-
const handlerResp = await handler(<Request>(<unknown>{}), resp)
|
|
67
|
-
//
|
|
68
|
-
c_expect(handlerResp).to.be.undefined
|
|
69
|
-
expect(resp.send).not.toBeCalled()
|
|
70
|
-
expect(resp.json).toBeCalledWith({})
|
|
71
|
-
expect(resp.status).toBeCalledWith(v.statusCode)
|
|
72
|
-
expect(resp.header).toBeCalledTimes(Object.keys(v.headers).length)
|
|
73
|
-
})
|
|
74
|
-
})
|
|
75
|
-
|
|
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
|
-
})
|
|
81
|
-
const resp = observableResponse()
|
|
82
|
-
const handlerResp = await handler(<Request>(<unknown>{}), resp)
|
|
83
|
-
//
|
|
84
|
-
c_expect(handlerResp).to.be.undefined
|
|
85
|
-
expect(resp.send).not.toBeCalled()
|
|
86
|
-
expect(resp.header).not.toBeCalled()
|
|
87
|
-
expect(resp.json).toBeCalledWith({
|
|
88
|
-
err: Globals.Resp_MSG_INVALIDRESP,
|
|
89
|
-
errCode: Globals.Resp_CODE_INVALIDRESP,
|
|
90
|
-
})
|
|
91
|
-
expect(resp.status).toBeCalledWith(Globals.Resp_STATUSCODE_INVALIDRESP)
|
|
92
|
-
})
|
|
93
|
-
|
|
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
|
-
})
|
|
99
|
-
const resp = observableResponse()
|
|
100
|
-
const handlerResp = await handler(<Request>(<unknown>{}), resp)
|
|
101
|
-
//
|
|
102
|
-
c_expect(handlerResp).to.be.undefined
|
|
103
|
-
expect(resp.send).not.toBeCalled()
|
|
104
|
-
expect(resp.header).not.toBeCalled()
|
|
105
|
-
expect(resp.json).toBeCalledWith({
|
|
106
|
-
err,
|
|
107
|
-
})
|
|
108
|
-
expect(resp.status).toBeCalledWith(400)
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
test('Exception response', async () => {
|
|
112
|
-
const err = new Error('Failed!')
|
|
113
|
-
const handler = GenericHandler(async () => {
|
|
114
|
-
throw err
|
|
115
|
-
})
|
|
116
|
-
const resp = observableResponse()
|
|
117
|
-
const handlerResp = await handler(<Request>(<unknown>{}), resp)
|
|
118
|
-
//
|
|
119
|
-
c_expect(handlerResp).to.be.undefined
|
|
120
|
-
expect(resp.send).not.toBeCalled()
|
|
121
|
-
expect(resp.header).not.toBeCalled()
|
|
122
|
-
expect(resp.json).toBeCalledWith({
|
|
123
|
-
...err,
|
|
124
|
-
err: Globals.Resp_MSG_EXCEPTION,
|
|
125
|
-
errCode: Globals.Resp_CODE_EXCEPTION,
|
|
126
|
-
})
|
|
127
|
-
expect(resp.status).toBeCalledWith(Globals.Resp_STATUSCODE_EXCEPTION)
|
|
128
|
-
})
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
export {}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { APIGatewayProxyEvent, Context } from 'aws-lambda'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
import { Request } from 'express'
|
|
4
|
-
|
|
5
|
-
import { HttpMethod } from '../../../../src/API/Request'
|
|
6
|
-
import GenericHandlerEvent from '../../../../src/Server/lib/container/GenericHandlerEvent'
|
|
7
|
-
|
|
8
|
-
describe('GenericHandlerEvent invocation paths', () => {
|
|
9
|
-
test('Simple success', async () => {
|
|
10
|
-
const event = new GenericHandlerEvent(
|
|
11
|
-
<Request>(<unknown>{
|
|
12
|
-
socket: { remoteAddress: '127.0.0.1' },
|
|
13
|
-
}),
|
|
14
|
-
async (event: APIGatewayProxyEvent, context: Context) => {
|
|
15
|
-
expect(context.getRemainingTimeInMillis()).to.not.be.null
|
|
16
|
-
context.succeed('Success')
|
|
17
|
-
}
|
|
18
|
-
)
|
|
19
|
-
const resp = await event.invoke()
|
|
20
|
-
expect(resp).to.not.be.null
|
|
21
|
-
expect(resp.err).to.be.undefined
|
|
22
|
-
expect(resp.data).to.be.equals('Success')
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
test('Simple failure', async () => {
|
|
26
|
-
const event = new GenericHandlerEvent(
|
|
27
|
-
<Request>(<unknown>{}),
|
|
28
|
-
async (event: APIGatewayProxyEvent, context: Context) => {
|
|
29
|
-
context.fail('Error!')
|
|
30
|
-
}
|
|
31
|
-
)
|
|
32
|
-
const resp = await event.invoke()
|
|
33
|
-
expect(resp).to.not.be.null
|
|
34
|
-
expect(resp.data).to.be.undefined
|
|
35
|
-
expect(resp.err).to.be.equals('Error!')
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
test('Simple done (errored)', async () => {
|
|
39
|
-
const event = new GenericHandlerEvent(
|
|
40
|
-
<Request>(<unknown>{}),
|
|
41
|
-
async (event: APIGatewayProxyEvent, context: Context) => {
|
|
42
|
-
context.done(new Error('Error!'))
|
|
43
|
-
}
|
|
44
|
-
)
|
|
45
|
-
const resp = await event.invoke()
|
|
46
|
-
expect(resp).to.not.be.null
|
|
47
|
-
expect(resp.data).to.be.undefined
|
|
48
|
-
expect(resp.err).to.be.an('Error')
|
|
49
|
-
if (resp.err instanceof Error) expect(resp.err?.message).to.be.equals('Error!')
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
test('Simple done (success)', async () => {
|
|
53
|
-
const event = new GenericHandlerEvent(
|
|
54
|
-
<Request>(<unknown>{}),
|
|
55
|
-
async (event: APIGatewayProxyEvent, context: Context) => {
|
|
56
|
-
context.done(undefined, 'Success!')
|
|
57
|
-
}
|
|
58
|
-
)
|
|
59
|
-
const resp = await event.invoke()
|
|
60
|
-
expect(resp).to.not.be.null
|
|
61
|
-
expect(resp.err).to.be.undefined
|
|
62
|
-
expect(resp.data).to.be.equals('Success!')
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
test('Exception on execution', async () => {
|
|
66
|
-
const event = new GenericHandlerEvent(<Request>(<unknown>{}), async () => {
|
|
67
|
-
throw new Error('Failed!')
|
|
68
|
-
})
|
|
69
|
-
let err: any = null,
|
|
70
|
-
resp: any = null
|
|
71
|
-
try {
|
|
72
|
-
resp = await event.invoke()
|
|
73
|
-
} catch (e) {
|
|
74
|
-
err = e
|
|
75
|
-
}
|
|
76
|
-
expect(resp).to.be.null
|
|
77
|
-
expect(err).to.not.be.null
|
|
78
|
-
expect(err).to.be.an('Error')
|
|
79
|
-
expect(err.message).to.be.equals('Failed!')
|
|
80
|
-
})
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
describe('GenericHandlerEvent event test', () => {
|
|
84
|
-
test('Simple event test', async () => {
|
|
85
|
-
const event = new GenericHandlerEvent(
|
|
86
|
-
<Request>(<unknown>{
|
|
87
|
-
headers: { Authorization: '123', 'x-forwarded-for': '127.0.0.1' },
|
|
88
|
-
method: HttpMethod.GET,
|
|
89
|
-
query: '/status?name=ryan',
|
|
90
|
-
}),
|
|
91
|
-
async (event: APIGatewayProxyEvent, context: Context) => {
|
|
92
|
-
expect(context.getRemainingTimeInMillis()).to.not.be.null
|
|
93
|
-
context.succeed('Success')
|
|
94
|
-
}
|
|
95
|
-
)
|
|
96
|
-
const resp = await event.invoke()
|
|
97
|
-
expect(resp).to.not.be.null
|
|
98
|
-
expect(resp.err).to.be.undefined
|
|
99
|
-
expect(resp.data).to.be.equals('Success')
|
|
100
|
-
})
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
export {}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { jest } from '@jest/globals'
|
|
2
|
-
import { expect as c_expect } from 'chai'
|
|
3
|
-
import { Request, Response } from 'express'
|
|
4
|
-
|
|
5
|
-
import HealthHandler from '../../../../src/Server/lib/container/HealthHandler'
|
|
6
|
-
|
|
7
|
-
function observableResponse(): Response {
|
|
8
|
-
const resp = <Response>(<unknown>{
|
|
9
|
-
send: jest.fn(() => resp),
|
|
10
|
-
json: jest.fn(() => resp),
|
|
11
|
-
status: jest.fn(() => resp),
|
|
12
|
-
header: jest.fn(() => resp),
|
|
13
|
-
})
|
|
14
|
-
return resp
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
describe('HealthHandler invocation path', () => {
|
|
18
|
-
test('Simple', async () => {
|
|
19
|
-
const resp = observableResponse()
|
|
20
|
-
const handlerResp = await HealthHandler(<Request>(<unknown>{}), resp)
|
|
21
|
-
//
|
|
22
|
-
c_expect(handlerResp).to.be.undefined
|
|
23
|
-
expect(resp.send).toBeCalledWith('Healthy!')
|
|
24
|
-
expect(resp.json).not.toBeCalled()
|
|
25
|
-
expect(resp.status).not.toBeCalled()
|
|
26
|
-
expect(resp.header).not.toBeCalled()
|
|
27
|
-
})
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
export {}
|
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
import { jest } from '@jest/globals'
|
|
2
|
-
import { APIGatewayProxyEvent, Context } from 'aws-lambda'
|
|
3
|
-
import { expect as c_expect } from 'chai'
|
|
4
|
-
import request from 'supertest'
|
|
5
|
-
|
|
6
|
-
import Globals from '../../../../src/Globals'
|
|
7
|
-
import Proxy from '../../../../src/Server/lib/container/Proxy'
|
|
8
|
-
import { defaultUrl } from '../../../Test.utils'
|
|
9
|
-
|
|
10
|
-
describe('Proxy configs', () => {
|
|
11
|
-
// @ts-ignore
|
|
12
|
-
let mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {})
|
|
13
|
-
beforeAll(() => {
|
|
14
|
-
// @ts-ignore
|
|
15
|
-
mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {})
|
|
16
|
-
})
|
|
17
|
-
afterAll(() => {
|
|
18
|
-
mockExit.mockRestore()
|
|
19
|
-
})
|
|
20
|
-
beforeEach(() => {
|
|
21
|
-
mockExit.mockReset()
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
test('Empty config url & unload with error', async () => {
|
|
25
|
-
const proxy = new Proxy({ routes: [] }, async () => {})
|
|
26
|
-
await proxy.load()
|
|
27
|
-
await proxy.unload('Error')
|
|
28
|
-
expect(mockExit).toBeCalledWith(1)
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
test('Simple port config', async () => {
|
|
32
|
-
const proxy = new Proxy({ routes: [], port: 56562 }, async () => {})
|
|
33
|
-
await proxy.load()
|
|
34
|
-
await proxy.unload()
|
|
35
|
-
expect(mockExit).toBeCalledWith(0)
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
test('Simple timeout config', async () => {
|
|
39
|
-
const proxy = new Proxy({ routes: [], timeout: 1000 }, async () => {})
|
|
40
|
-
await proxy.load()
|
|
41
|
-
await proxy.unload()
|
|
42
|
-
expect(mockExit).toBeCalledWith(0)
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
test('Simple cors config', async () => {
|
|
46
|
-
const proxy = new Proxy(
|
|
47
|
-
{
|
|
48
|
-
routes: [],
|
|
49
|
-
cors: {
|
|
50
|
-
origin: '*',
|
|
51
|
-
headers: ['Authorization'],
|
|
52
|
-
allowCredentials: true,
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
async () => {}
|
|
56
|
-
)
|
|
57
|
-
await proxy.load()
|
|
58
|
-
await proxy.unload()
|
|
59
|
-
expect(mockExit).toBeCalledWith(0)
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
test('Empty cors config', async () => {
|
|
63
|
-
const proxy = new Proxy(
|
|
64
|
-
{
|
|
65
|
-
routes: [],
|
|
66
|
-
cors: {},
|
|
67
|
-
},
|
|
68
|
-
async () => {}
|
|
69
|
-
)
|
|
70
|
-
await proxy.load()
|
|
71
|
-
await proxy.unload()
|
|
72
|
-
expect(mockExit).toBeCalledWith(0)
|
|
73
|
-
})
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
describe('Proxy behaviour', () => {
|
|
77
|
-
// @ts-ignore
|
|
78
|
-
let mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {})
|
|
79
|
-
beforeAll(() => {
|
|
80
|
-
// @ts-ignore
|
|
81
|
-
mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {})
|
|
82
|
-
})
|
|
83
|
-
afterAll(() => {
|
|
84
|
-
mockExit.mockRestore()
|
|
85
|
-
})
|
|
86
|
-
beforeEach(() => {
|
|
87
|
-
mockExit.mockReset()
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
test('Stop twice', async () => {
|
|
91
|
-
const proxy = new Proxy({ routes: [] }, async () => {})
|
|
92
|
-
await proxy.load()
|
|
93
|
-
await Promise.all([proxy.unload('Error'), proxy.unload('Error')])
|
|
94
|
-
expect(mockExit).toHaveBeenCalledTimes(1)
|
|
95
|
-
expect(mockExit).toBeCalledWith(1)
|
|
96
|
-
})
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
describe('Proxy routing', () => {
|
|
100
|
-
// @ts-ignore
|
|
101
|
-
let mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {})
|
|
102
|
-
beforeAll(() => {
|
|
103
|
-
// @ts-ignore
|
|
104
|
-
mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {})
|
|
105
|
-
})
|
|
106
|
-
afterAll(() => {
|
|
107
|
-
mockExit.mockRestore()
|
|
108
|
-
})
|
|
109
|
-
beforeEach(() => {
|
|
110
|
-
mockExit.mockReset()
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
test('Health & Default handler', async () => {
|
|
114
|
-
let count = 0
|
|
115
|
-
const proxy = new Proxy(
|
|
116
|
-
{ routes: [] },
|
|
117
|
-
async (event: APIGatewayProxyEvent, context: Context) => {
|
|
118
|
-
count++
|
|
119
|
-
context.succeed({
|
|
120
|
-
body: JSON.stringify({ name: '123' }),
|
|
121
|
-
statusCode: 200,
|
|
122
|
-
})
|
|
123
|
-
}
|
|
124
|
-
)
|
|
125
|
-
await proxy.load()
|
|
126
|
-
// Health check
|
|
127
|
-
const res = await request(defaultUrl)
|
|
128
|
-
.get(Globals.Listener_HTTP_DefaultHealthCheckRoute)
|
|
129
|
-
.expect('Content-Type', 'text/html; charset=utf-8')
|
|
130
|
-
.expect(200)
|
|
131
|
-
c_expect(res.text).to.be.equals('Healthy!')
|
|
132
|
-
// Generic handler
|
|
133
|
-
const resG = await request(defaultUrl)
|
|
134
|
-
.get(`/abc`)
|
|
135
|
-
.expect('Content-Type', 'application/json; charset=utf-8')
|
|
136
|
-
.expect(200)
|
|
137
|
-
c_expect(resG.body).to.be.deep.equals({ name: '123' })
|
|
138
|
-
// Expected count
|
|
139
|
-
c_expect(count).to.be.equals(1)
|
|
140
|
-
// Unload
|
|
141
|
-
await proxy.unload('Error')
|
|
142
|
-
expect(mockExit).toHaveBeenCalledTimes(1)
|
|
143
|
-
expect(mockExit).toBeCalledWith(1)
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
test('Proxy on custom port', async () => {
|
|
147
|
-
let count = 0
|
|
148
|
-
const port = 56542
|
|
149
|
-
const url = defaultUrl.replace(String(Globals.Listener_HTTP_DefaultPort), String(port))
|
|
150
|
-
const proxy = new Proxy(
|
|
151
|
-
{ routes: [], port },
|
|
152
|
-
async (event: APIGatewayProxyEvent, context: Context) => {
|
|
153
|
-
count++
|
|
154
|
-
context.succeed({
|
|
155
|
-
body: JSON.stringify({ name: '123' }),
|
|
156
|
-
statusCode: 200,
|
|
157
|
-
})
|
|
158
|
-
}
|
|
159
|
-
)
|
|
160
|
-
await proxy.load()
|
|
161
|
-
// Health check
|
|
162
|
-
const res = await request(url)
|
|
163
|
-
.get(Globals.Listener_HTTP_DefaultHealthCheckRoute)
|
|
164
|
-
.expect('Content-Type', 'text/html; charset=utf-8')
|
|
165
|
-
.expect(200)
|
|
166
|
-
c_expect(res.text).to.be.equals('Healthy!')
|
|
167
|
-
// Generic handler
|
|
168
|
-
const resG = await request(url)
|
|
169
|
-
.get(`/abc`)
|
|
170
|
-
.expect('Content-Type', 'application/json; charset=utf-8')
|
|
171
|
-
.expect(200)
|
|
172
|
-
c_expect(resG.body).to.be.deep.equals({ name: '123' })
|
|
173
|
-
// Expected count
|
|
174
|
-
c_expect(count).to.be.equals(1)
|
|
175
|
-
// Unload
|
|
176
|
-
await proxy.unload()
|
|
177
|
-
expect(mockExit).toHaveBeenCalledTimes(1)
|
|
178
|
-
expect(mockExit).toBeCalledWith(0)
|
|
179
|
-
})
|
|
180
|
-
|
|
181
|
-
test('Proxy does timeout', async () => {
|
|
182
|
-
let count = 0
|
|
183
|
-
const timeout = 1000
|
|
184
|
-
const proxy = new Proxy(
|
|
185
|
-
{ routes: [], timeout },
|
|
186
|
-
async (event: APIGatewayProxyEvent, context: Context) => {
|
|
187
|
-
count++
|
|
188
|
-
setTimeout(() => {
|
|
189
|
-
context.succeed({
|
|
190
|
-
body: JSON.stringify({ name: '123' }),
|
|
191
|
-
statusCode: 200,
|
|
192
|
-
})
|
|
193
|
-
}, timeout * 2)
|
|
194
|
-
}
|
|
195
|
-
)
|
|
196
|
-
await proxy.load()
|
|
197
|
-
// Health check
|
|
198
|
-
const res = await request(defaultUrl)
|
|
199
|
-
.get(Globals.Listener_HTTP_DefaultHealthCheckRoute)
|
|
200
|
-
.expect('Content-Type', 'text/html; charset=utf-8')
|
|
201
|
-
.expect(200)
|
|
202
|
-
c_expect(res.text).to.be.equals('Healthy!')
|
|
203
|
-
// Generic handler
|
|
204
|
-
let err: any = null
|
|
205
|
-
try {
|
|
206
|
-
await request(defaultUrl)
|
|
207
|
-
.get(`/abc`)
|
|
208
|
-
.expect('Content-Type', 'application/json; charset=utf-8')
|
|
209
|
-
.expect(200)
|
|
210
|
-
} catch (e) {
|
|
211
|
-
err = e
|
|
212
|
-
}
|
|
213
|
-
c_expect(err?.message).to.be.equals('socket hang up')
|
|
214
|
-
// Expected count
|
|
215
|
-
c_expect(count).to.be.equals(1)
|
|
216
|
-
// Unload
|
|
217
|
-
await proxy.unload('Error')
|
|
218
|
-
expect(mockExit).toHaveBeenCalledTimes(1)
|
|
219
|
-
expect(mockExit).toBeCalledWith(1)
|
|
220
|
-
//
|
|
221
|
-
return new Promise(resolve => {
|
|
222
|
-
setTimeout(resolve, timeout * 2)
|
|
223
|
-
})
|
|
224
|
-
})
|
|
225
|
-
|
|
226
|
-
test('Proxy respects cors', async () => {
|
|
227
|
-
let count = 0
|
|
228
|
-
const proxy = new Proxy(
|
|
229
|
-
{
|
|
230
|
-
routes: [],
|
|
231
|
-
cors: {
|
|
232
|
-
origin: '*',
|
|
233
|
-
headers: ['Authorization'],
|
|
234
|
-
allowCredentials: true,
|
|
235
|
-
},
|
|
236
|
-
},
|
|
237
|
-
async (event: APIGatewayProxyEvent, context: Context) => {
|
|
238
|
-
count++
|
|
239
|
-
context.succeed({
|
|
240
|
-
body: JSON.stringify({ name: '123' }),
|
|
241
|
-
statusCode: 200,
|
|
242
|
-
})
|
|
243
|
-
}
|
|
244
|
-
)
|
|
245
|
-
await proxy.load()
|
|
246
|
-
// White-listed header is allowed
|
|
247
|
-
const resWH = await request(defaultUrl).options(`/abc`).set('Authorization', '123').expect(204)
|
|
248
|
-
c_expect(resWH.header['access-control-allow-origin']).to.equal('*')
|
|
249
|
-
c_expect(resWH.header['access-control-allow-credentials']).to.equal('true')
|
|
250
|
-
c_expect(resWH.header['access-control-allow-headers']).to.equal('Authorization')
|
|
251
|
-
// Non white-listed header is allowed
|
|
252
|
-
const resNWH = await request(defaultUrl)
|
|
253
|
-
.options(`/abc`)
|
|
254
|
-
.set('2Authorization2', '123')
|
|
255
|
-
.expect(204)
|
|
256
|
-
c_expect(resNWH.header['access-control-allow-origin']).to.equal('*')
|
|
257
|
-
c_expect(resNWH.header['access-control-allow-credentials']).to.equal('true')
|
|
258
|
-
c_expect(resNWH.header['access-control-allow-headers']).to.equal('Authorization')
|
|
259
|
-
// Expected count
|
|
260
|
-
c_expect(count).to.be.equals(0)
|
|
261
|
-
// Unload
|
|
262
|
-
await proxy.unload()
|
|
263
|
-
expect(mockExit).toHaveBeenCalledTimes(1)
|
|
264
|
-
expect(mockExit).toBeCalledWith(0)
|
|
265
|
-
})
|
|
266
|
-
})
|
|
267
|
-
|
|
268
|
-
export {}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { expect } from 'chai'
|
|
2
|
-
|
|
3
|
-
import * as Utils from '../../../../src/Server/lib/container/Utils'
|
|
4
|
-
|
|
5
|
-
describe('parseQueryStringParameters', () => {
|
|
6
|
-
test('Null url', () => {
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
const validationResult = Utils.parseQueryStringParameters(null)
|
|
9
|
-
expect(validationResult).to.be.deep.equals({})
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
test('Empty url', () => {
|
|
13
|
-
const validationResult = Utils.parseQueryStringParameters('')
|
|
14
|
-
expect(validationResult).to.be.deep.equals({})
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
test('Simple param', () => {
|
|
18
|
-
const validationResult = Utils.parseQueryStringParameters('/status?name=ryan')
|
|
19
|
-
expect(validationResult).to.be.deep.equals({
|
|
20
|
-
name: 'ryan',
|
|
21
|
-
})
|
|
22
|
-
})
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
describe('parseMultiValueQueryStringParameters', () => {
|
|
26
|
-
test('Null url', () => {
|
|
27
|
-
// @ts-ignore
|
|
28
|
-
const validationResult = Utils.parseMultiValueQueryStringParameters()
|
|
29
|
-
expect(validationResult).to.be.deep.equals({})
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
test('Empty url', () => {
|
|
33
|
-
const validationResult = Utils.parseMultiValueQueryStringParameters('')
|
|
34
|
-
expect(validationResult).to.be.deep.equals({})
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
test('Simple multivalue param', () => {
|
|
38
|
-
const validationResult = Utils.parseMultiValueQueryStringParameters(
|
|
39
|
-
'/status?name=ryan&name=ryan2'
|
|
40
|
-
)
|
|
41
|
-
expect(validationResult).to.be.deep.equals({
|
|
42
|
-
name: ['ryan', 'ryan2'],
|
|
43
|
-
})
|
|
44
|
-
})
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
export {}
|
package/tests/Test.utils.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { jest } from '@jest/globals'
|
|
2
|
-
import { APIGatewayEvent, Context, SQSEvent } from 'aws-lambda'
|
|
3
|
-
import { z } from 'zod'
|
|
4
|
-
|
|
5
|
-
import Transaction from '../src/BaseEvent/Transaction'
|
|
6
|
-
import Globals from '../src/Globals'
|
|
7
|
-
|
|
8
|
-
export const defaultHeaders = {
|
|
9
|
-
'Access-Control-Allow-Credentials': true,
|
|
10
|
-
'Access-Control-Allow-Origin': '*',
|
|
11
|
-
'Content-Type': 'application/json',
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const defaultUrl = `localhost:${Globals.Listener_HTTP_DefaultPort}`
|
|
15
|
-
|
|
16
|
-
export const SampleConfig = {
|
|
17
|
-
PATH: {
|
|
18
|
-
isLocal: true,
|
|
19
|
-
required: true,
|
|
20
|
-
},
|
|
21
|
-
PATH_FALSY: {
|
|
22
|
-
isLocal: true,
|
|
23
|
-
required: true,
|
|
24
|
-
},
|
|
25
|
-
PATH123: {
|
|
26
|
-
isLocal: true,
|
|
27
|
-
required: false,
|
|
28
|
-
},
|
|
29
|
-
TOKEN_SECRET: {
|
|
30
|
-
isRemote: true,
|
|
31
|
-
required: true,
|
|
32
|
-
},
|
|
33
|
-
TOKEN_SECRET_FALSY: {
|
|
34
|
-
isRemote: true,
|
|
35
|
-
required: false,
|
|
36
|
-
},
|
|
37
|
-
} as const
|
|
38
|
-
|
|
39
|
-
export function observableContext(data?: any) {
|
|
40
|
-
return <Context>(<unknown>{
|
|
41
|
-
done: jest.fn(),
|
|
42
|
-
fail: jest.fn(),
|
|
43
|
-
succeed: jest.fn(),
|
|
44
|
-
...(data || {}),
|
|
45
|
-
})
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export const privateKey = 'tMHOuszBQmF6XtwgrUpvqpk07rh3RATX'
|
|
49
|
-
|
|
50
|
-
export const foreignToken =
|
|
51
|
-
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'
|
|
52
|
-
|
|
53
|
-
export const ViewSchema = z.object({
|
|
54
|
-
id: z.string(),
|
|
55
|
-
content: z.string(),
|
|
56
|
-
createdAt: z.date(),
|
|
57
|
-
updatedAt: z.date(),
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
export type View = z.infer<typeof ViewSchema>
|
|
61
|
-
|
|
62
|
-
export function emptyEvent(data?: any) {
|
|
63
|
-
return <APIGatewayEvent>(<unknown>data || {})
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function emptyQueueEvent(data?: any) {
|
|
67
|
-
return <SQSEvent>(<unknown>data || {})
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function observableTransaction() {
|
|
71
|
-
const t = new Transaction(emptyEvent(), observableContext())
|
|
72
|
-
t.responseProxy = jest.fn() as any
|
|
73
|
-
return t
|
|
74
|
-
}
|