@ikonintegration/ikapi 4.0.1 → 5.0.0
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/.eslintignore +3 -0
- package/.eslintrc.cjs +81 -0
- package/.github/workflows/npmpublish.yml +8 -19
- package/.github/workflows/prs.yml +12 -0
- package/README.md +89 -99
- package/dist/index.d.ts +16 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/package-lock.json +11881 -0
- package/dist/package.json +81 -0
- package/dist/src/API/Request.d.ts +125 -0
- package/dist/src/API/Request.js +185 -0
- package/dist/src/API/Request.js.map +1 -0
- package/dist/src/API/Response.d.ts +188 -0
- package/dist/src/API/Response.js +270 -0
- package/dist/src/API/Response.js.map +1 -0
- package/dist/src/BaseEvent/DynamoTransaction.d.ts +70 -0
- package/dist/src/BaseEvent/DynamoTransaction.js +104 -0
- package/dist/src/BaseEvent/DynamoTransaction.js.map +1 -0
- package/dist/src/BaseEvent/EventProcessor.d.ts +58 -0
- package/dist/src/BaseEvent/EventProcessor.js +101 -0
- package/dist/src/BaseEvent/EventProcessor.js.map +1 -0
- package/dist/src/BaseEvent/Process.d.ts +50 -0
- package/dist/src/BaseEvent/Process.js +64 -0
- package/dist/src/BaseEvent/Process.js.map +1 -0
- package/dist/src/BaseEvent/StepTransaction.d.ts +23 -0
- package/dist/src/BaseEvent/StepTransaction.js +27 -0
- package/dist/src/BaseEvent/StepTransaction.js.map +1 -0
- package/dist/src/BaseEvent/Transaction.d.ts +149 -0
- package/dist/src/BaseEvent/Transaction.js +224 -0
- package/dist/src/BaseEvent/Transaction.js.map +1 -0
- package/dist/src/Cache/Redis.d.ts +29 -0
- package/dist/src/Cache/Redis.js +80 -0
- package/dist/src/Cache/Redis.js.map +1 -0
- package/dist/src/Cache/types.d.ts +31 -0
- package/dist/src/Cache/types.js +2 -0
- package/dist/src/Cache/types.js.map +1 -0
- package/dist/src/Config/Configuration.d.ts +123 -0
- package/dist/src/Config/Configuration.js +109 -0
- package/dist/src/Config/Configuration.js.map +1 -0
- package/dist/src/Config/EnvironmentVar.d.ts +74 -0
- package/dist/src/Config/EnvironmentVar.js +138 -0
- package/dist/src/Config/EnvironmentVar.js.map +1 -0
- package/dist/src/Crypto/Crypto.d.ts +45 -0
- package/dist/src/Crypto/Crypto.js +72 -0
- package/dist/src/Crypto/Crypto.js.map +1 -0
- package/dist/src/Database/Database.d.ts +21 -0
- package/dist/src/Database/Database.js +15 -0
- package/dist/src/Database/Database.js.map +1 -0
- package/dist/src/Database/DatabaseManager.d.ts +47 -0
- package/dist/src/Database/DatabaseManager.js +60 -0
- package/dist/src/Database/DatabaseManager.js.map +1 -0
- package/dist/src/Database/DatabaseTransaction.d.ts +101 -0
- package/dist/src/Database/DatabaseTransaction.js +126 -0
- package/dist/src/Database/DatabaseTransaction.js.map +1 -0
- package/dist/src/Database/index.d.ts +10 -0
- package/dist/src/Database/index.js +15 -0
- package/dist/src/Database/index.js.map +1 -0
- package/dist/src/Database/integrations/dynamo/DynamoDatabase.d.ts +35 -0
- package/dist/src/Database/integrations/dynamo/DynamoDatabase.js +59 -0
- package/dist/src/Database/integrations/dynamo/DynamoDatabase.js.map +1 -0
- package/dist/src/Database/integrations/kysely/KyselyDatabase.d.ts +66 -0
- package/dist/src/Database/integrations/kysely/KyselyDatabase.js +86 -0
- package/dist/src/Database/integrations/kysely/KyselyDatabase.js.map +1 -0
- package/dist/src/Database/integrations/kysely/KyselyTransaction.d.ts +70 -0
- package/dist/src/Database/integrations/kysely/KyselyTransaction.js +118 -0
- package/dist/src/Database/integrations/kysely/KyselyTransaction.js.map +1 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +36 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +54 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +63 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +61 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -0
- package/dist/src/Database/types.d.ts +76 -0
- package/dist/src/Database/types.js +2 -0
- package/dist/src/Database/types.js.map +1 -0
- package/dist/src/Globals.d.ts +93 -0
- package/dist/src/Globals.js +99 -0
- package/dist/src/Globals.js.map +1 -0
- package/dist/src/Logger/Logger.d.ts +161 -0
- package/dist/src/Logger/Logger.js +299 -0
- package/dist/src/Logger/Logger.js.map +1 -0
- package/dist/src/Mailer/Mailer.d.ts +78 -0
- package/dist/src/Mailer/Mailer.js +182 -0
- package/dist/src/Mailer/Mailer.js.map +1 -0
- package/dist/src/Publisher/Publisher.d.ts +39 -0
- package/dist/src/Publisher/Publisher.js +77 -0
- package/dist/src/Publisher/Publisher.js.map +1 -0
- package/dist/src/Server/RouteResolver.d.ts +33 -0
- package/dist/src/Server/RouteResolver.js +100 -0
- package/dist/src/Server/RouteResolver.js.map +1 -0
- package/dist/src/Server/Router.d.ts +157 -0
- package/dist/src/Server/Router.js +32 -0
- package/dist/src/Server/Router.js.map +1 -0
- package/dist/src/Server/lib/ContainerServer.d.ts +42 -0
- package/dist/src/Server/lib/ContainerServer.js +66 -0
- package/dist/src/Server/lib/ContainerServer.js.map +1 -0
- package/dist/src/Server/lib/Server.d.ts +45 -0
- package/dist/src/Server/lib/Server.js +93 -0
- package/dist/src/Server/lib/Server.js.map +1 -0
- package/dist/src/Server/lib/container/GenericHandler.d.ts +9 -0
- package/dist/src/Server/lib/container/GenericHandler.js +82 -0
- package/dist/src/Server/lib/container/GenericHandler.js.map +1 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +52 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.js +132 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -0
- package/dist/src/Server/lib/container/HealthHandler.d.ts +9 -0
- package/dist/src/Server/lib/container/HealthHandler.js +19 -0
- package/dist/src/Server/lib/container/HealthHandler.js.map +1 -0
- package/dist/src/Server/lib/container/Proxy.d.ts +67 -0
- package/dist/src/Server/lib/container/Proxy.js +143 -0
- package/dist/src/Server/lib/container/Proxy.js.map +1 -0
- package/dist/src/Server/lib/container/Utils.d.ts +14 -0
- package/dist/src/Server/lib/container/Utils.js +37 -0
- package/dist/src/Server/lib/container/Utils.js.map +1 -0
- package/dist/src/Util/AsyncSingleton.d.ts +31 -0
- package/dist/src/Util/AsyncSingleton.js +83 -0
- package/dist/src/Util/AsyncSingleton.js.map +1 -0
- package/dist/src/Util/Utils.d.ts +61 -0
- package/dist/src/Util/Utils.js +147 -0
- package/dist/src/Util/Utils.js.map +1 -0
- package/dist/src/Validation/Validator.d.ts +17 -0
- package/dist/src/Validation/Validator.js +39 -0
- package/dist/src/Validation/Validator.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/index.ts +41 -0
- package/jest.config.ts +37 -0
- package/jest.smoke.config.ts +34 -0
- package/package.json +66 -22
- package/src/API/Request.ts +214 -0
- package/src/API/Response.ts +370 -0
- package/src/BaseEvent/DynamoTransaction.ts +175 -0
- package/src/BaseEvent/EventProcessor.ts +140 -0
- package/src/BaseEvent/Process.ts +78 -0
- package/src/BaseEvent/StepTransaction.ts +35 -0
- package/src/BaseEvent/Transaction.ts +323 -0
- package/src/Cache/Redis.ts +89 -0
- package/src/Cache/types.ts +33 -0
- package/src/Config/Configuration.ts +199 -0
- package/src/Config/EnvironmentVar.ts +142 -0
- package/src/Crypto/Crypto.ts +89 -0
- package/src/Database/Database.ts +22 -0
- package/src/Database/DatabaseManager.ts +67 -0
- package/src/Database/DatabaseTransaction.ts +170 -0
- package/src/Database/index.ts +27 -0
- package/src/Database/integrations/dynamo/DynamoDatabase.ts +58 -0
- package/src/Database/integrations/kysely/KyselyDatabase.ts +99 -0
- package/src/Database/integrations/kysely/KyselyTransaction.ts +172 -0
- package/src/Database/integrations/pgsql/PostgresDatabase.ts +56 -0
- package/src/Database/integrations/pgsql/PostgresTransaction.ts +87 -0
- package/src/Database/types.ts +85 -0
- package/src/Globals.ts +103 -0
- package/src/Logger/Logger.ts +363 -0
- package/src/Mailer/Mailer.ts +217 -0
- package/src/Publisher/Publisher.ts +96 -0
- package/src/Server/RouteResolver.ts +124 -0
- package/src/Server/Router.ts +200 -0
- package/src/Server/lib/ContainerServer.ts +65 -0
- package/src/Server/lib/Server.ts +109 -0
- package/src/Server/lib/container/GenericHandler.ts +76 -0
- package/src/Server/lib/container/GenericHandlerEvent.ts +154 -0
- package/src/Server/lib/container/HealthHandler.ts +11 -0
- package/src/Server/lib/container/Proxy.ts +172 -0
- package/src/Server/lib/container/Utils.ts +33 -0
- package/src/Util/AsyncSingleton.ts +86 -0
- package/src/Util/Utils.ts +131 -0
- package/src/Validation/Validator.ts +45 -0
- package/tests/API/Request.test.ts +273 -0
- package/tests/API/Response.test.ts +367 -0
- package/tests/BaseEvent/DynamoTransaction.test.ts +272 -0
- package/tests/BaseEvent/EventProcessor.test.ts +263 -0
- package/tests/BaseEvent/Process.test.ts +47 -0
- package/tests/BaseEvent/StepTransaction.test.ts +44 -0
- package/tests/BaseEvent/Transaction.test.ts +402 -0
- package/tests/Cache/Redis-client.test.ts +90 -0
- package/tests/Cache/Redis-cluster.test.ts +100 -0
- package/tests/Config/Config.test.ts +205 -0
- package/tests/Config/EnvironmentVar.test.ts +251 -0
- package/tests/Crypto/Crypto.test.ts +88 -0
- package/tests/Database/DatabaseManager.test.ts +79 -0
- package/tests/Database/integrations/dynamo/DynamoDatabase.test.ts +44 -0
- package/tests/Database/integrations/kysely/KyselyDatabase.test.ts +113 -0
- package/tests/Database/integrations/kysely/KyselyTransaction.test.ts +119 -0
- package/tests/Database/integrations/pg/PostgresDatabase.test.ts +76 -0
- package/tests/Database/integrations/pg/PostgresTransaction.test.ts +118 -0
- package/tests/Logger/Logger.test.ts +215 -0
- package/tests/Mailer/Mailer.test.ts +59 -0
- package/tests/Publisher/Publisher.test.ts +60 -0
- package/tests/Server/RouteResolver.test.ts +116 -0
- package/tests/Server/Router.test.ts +39 -0
- package/tests/Server/lib/ContainerServer.test.ts +531 -0
- package/tests/Server/lib/Server.test.ts +12 -0
- package/tests/Server/lib/container/GenericHandler.test.ts +131 -0
- package/tests/Server/lib/container/GenericHandlerEvent.test.ts +103 -0
- package/tests/Server/lib/container/HealthHandler.test.ts +30 -0
- package/tests/Server/lib/container/Proxy.test.ts +268 -0
- package/tests/Server/lib/container/Utils.test.ts +47 -0
- package/tests/Test.utils.ts +78 -0
- package/tests/Utils/Utils.test.ts +229 -0
- package/tests/Validation/Validator.test.ts +82 -0
- package/tsconfig.json +26 -0
- package/tsconfig.smoke.json +26 -0
- package/index.js +0 -88
- package/src/API/IKRequest.js +0 -52
- package/src/API/IKResponse.js +0 -119
- package/src/API/IKUtils.js +0 -51
- package/src/BaseEvent/IKProcess.js +0 -77
- package/src/BaseEvent/IKTransaction.js +0 -139
- package/src/Cache/Prototype/IKCache.js +0 -17
- package/src/Cache/Redis/IKRedis.js +0 -148
- package/src/Database/DDB/IKDB.js +0 -56
- package/src/Database/DDB/IKDBBaseExpression.js +0 -130
- package/src/Database/DDB/IKDBBaseQuery.js +0 -151
- package/src/Database/DDB/IKDBQueryBatchGet.js +0 -37
- package/src/Database/DDB/IKDBQueryBatchWrite.js +0 -64
- package/src/Database/DDB/IKDBQueryDelete.js +0 -34
- package/src/Database/DDB/IKDBQueryGet.js +0 -48
- package/src/Database/DDB/IKDBQueryPut.js +0 -87
- package/src/Database/DDB/IKDBQueryScan.js +0 -45
- package/src/Database/DDB/IKDBQueryTransactionalWrite.js +0 -69
- package/src/Database/DDB/IKDBQueryUpdate.js +0 -221
- package/src/Database/DDB/_IKDBQueryTransactionalRead.js +0 -46
- package/src/Database/PSQL/IKDB.js +0 -41
- package/src/Database/PSQL/IKDBBaseQuery.js +0 -26
- package/src/Database/Prototype/IKDB.js +0 -21
- package/src/Database/Prototype/IKDBBaseQuery.js +0 -14
- package/src/IKDynamoStream.js +0 -42
- package/src/IKEventProcessor.js +0 -42
- package/src/IKGlobals.js +0 -24
- package/src/IKRouter.js +0 -47
- package/src/IKStepTransaction.js +0 -14
- package/src/Logger/IKLogger.js +0 -136
- package/src/Mailer/IKMailer.js +0 -69
- package/src/Publisher/IKPublisher.js +0 -44
- package/src/Tracker/IKExecutionTracker.js +0 -79
- package/src/Validation/IKValidation.js +0 -76
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { SNSClient, PublishCommand } from '@aws-sdk/client-sns'
|
|
2
|
+
import { mockClient } from 'aws-sdk-client-mock'
|
|
3
|
+
import { expect } from 'chai'
|
|
4
|
+
|
|
5
|
+
import Publisher from '../../src/Publisher/Publisher.js'
|
|
6
|
+
|
|
7
|
+
const SNSMock = mockClient(SNSClient)
|
|
8
|
+
|
|
9
|
+
describe('SNS Pub-Sub', () => {
|
|
10
|
+
// reset mock
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
SNSMock.reset()
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
const provider = new Publisher({
|
|
16
|
+
region: 'ca-central-1',
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
test('Publishes with success', async () => {
|
|
20
|
+
const msg = { text: '123' }
|
|
21
|
+
const topic = '123'
|
|
22
|
+
const messageId = 'id-123'
|
|
23
|
+
SNSMock.on(PublishCommand, {
|
|
24
|
+
Message: JSON.stringify(msg),
|
|
25
|
+
TopicArn: topic,
|
|
26
|
+
}).resolves({
|
|
27
|
+
MessageId: messageId,
|
|
28
|
+
})
|
|
29
|
+
const res = await provider.publishOnTopic(msg, topic)
|
|
30
|
+
expect(res).is.not.null
|
|
31
|
+
expect(res?.MessageId).to.be.equals(messageId)
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
test('Publishes with success (additional props)', async () => {
|
|
35
|
+
const msg = { text: '123' }
|
|
36
|
+
const topic = '123'
|
|
37
|
+
const messageId = 'id-123'
|
|
38
|
+
SNSMock.on(PublishCommand, {
|
|
39
|
+
Message: JSON.stringify(msg),
|
|
40
|
+
TopicArn: topic,
|
|
41
|
+
}).resolves({
|
|
42
|
+
MessageId: messageId,
|
|
43
|
+
})
|
|
44
|
+
const res = await provider.publishOnTopic(msg, topic, {
|
|
45
|
+
FifoGroup: 123,
|
|
46
|
+
})
|
|
47
|
+
expect(res).is.not.null
|
|
48
|
+
expect(res?.MessageId).to.be.equals(messageId)
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
test('Publish failure', async () => {
|
|
52
|
+
const msg = { text: '123' }
|
|
53
|
+
const topic = '123'
|
|
54
|
+
SNSMock.on(PublishCommand).rejects(new Error('failed!'))
|
|
55
|
+
const res = await provider.publishOnTopic(msg, topic)
|
|
56
|
+
expect(res).is.undefined
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
export {}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { HttpMethod } from '../../src/API/Request.js'
|
|
2
|
+
import { Route } from '../../src/Server/Router.js'
|
|
3
|
+
import RouteResolver from '../../src/Server/RouteResolver.js'
|
|
4
|
+
|
|
5
|
+
const mockRoute = (method: HttpMethod, path: string | string[]) =>
|
|
6
|
+
({
|
|
7
|
+
method: method,
|
|
8
|
+
path: path,
|
|
9
|
+
}) as any as Route
|
|
10
|
+
|
|
11
|
+
describe('RouteResolver', () => {
|
|
12
|
+
test('no routes configured', () => {
|
|
13
|
+
parameterizedTest({}, () => [
|
|
14
|
+
[HttpMethod.GET, '/', undefined],
|
|
15
|
+
[HttpMethod.GET, '', undefined],
|
|
16
|
+
[HttpMethod.GET, 'hjdah', undefined],
|
|
17
|
+
])
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
test('one route', () => {
|
|
21
|
+
parameterizedTest(
|
|
22
|
+
{
|
|
23
|
+
route: mockRoute(HttpMethod.GET, '/'),
|
|
24
|
+
},
|
|
25
|
+
routes => [
|
|
26
|
+
[HttpMethod.GET, '/', routes.route],
|
|
27
|
+
[HttpMethod.GET, '', routes.route],
|
|
28
|
+
[HttpMethod.GET, 'hjdah', undefined],
|
|
29
|
+
[HttpMethod.POST, '/', undefined],
|
|
30
|
+
[HttpMethod.DELETE, '/', undefined],
|
|
31
|
+
]
|
|
32
|
+
)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
test('basic matching', () => {
|
|
36
|
+
parameterizedTest(
|
|
37
|
+
{
|
|
38
|
+
getBase: mockRoute(HttpMethod.GET, '/'),
|
|
39
|
+
getA: mockRoute(HttpMethod.GET, '/a'),
|
|
40
|
+
getB: mockRoute(HttpMethod.GET, '/b'),
|
|
41
|
+
postBase: mockRoute(HttpMethod.POST, '/'),
|
|
42
|
+
postA: mockRoute(HttpMethod.POST, '/a'),
|
|
43
|
+
variable: mockRoute(HttpMethod.GET, '/:a'),
|
|
44
|
+
getAb: mockRoute(HttpMethod.GET, '/a/b'),
|
|
45
|
+
},
|
|
46
|
+
routes => [
|
|
47
|
+
[HttpMethod.GET, '/', routes.getBase],
|
|
48
|
+
[HttpMethod.GET, '/a', routes.getA],
|
|
49
|
+
[HttpMethod.GET, '/b', routes.getB],
|
|
50
|
+
[HttpMethod.POST, '/', routes.postBase],
|
|
51
|
+
[HttpMethod.POST, '/a', routes.postA],
|
|
52
|
+
[HttpMethod.GET, '/c', routes.variable],
|
|
53
|
+
[HttpMethod.GET, '/a/b', routes.getAb],
|
|
54
|
+
]
|
|
55
|
+
)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
test('multi matching', () => {
|
|
59
|
+
parameterizedTest(
|
|
60
|
+
{
|
|
61
|
+
getA: mockRoute(HttpMethod.GET, ['/a', '/b']),
|
|
62
|
+
variable: mockRoute(HttpMethod.GET, '/:a'),
|
|
63
|
+
},
|
|
64
|
+
routes => [
|
|
65
|
+
[HttpMethod.GET, '/a', routes.getA],
|
|
66
|
+
[HttpMethod.GET, '/b', routes.getA],
|
|
67
|
+
[HttpMethod.GET, '/c', routes.variable],
|
|
68
|
+
]
|
|
69
|
+
)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
test('path variables', () => {
|
|
73
|
+
parameterizedTest(
|
|
74
|
+
{
|
|
75
|
+
path_vars: mockRoute(HttpMethod.GET, '/base/:a/:b/:c'),
|
|
76
|
+
abc: mockRoute(HttpMethod.GET, '/base/a/b/c'),
|
|
77
|
+
abcd: mockRoute(HttpMethod.GET, '/base/a/b/c/d'),
|
|
78
|
+
abc_path: mockRoute(HttpMethod.GET, '/base/a/b/c/:d'),
|
|
79
|
+
},
|
|
80
|
+
routes => [
|
|
81
|
+
[HttpMethod.GET, '/base/1/2/3', routes.path_vars],
|
|
82
|
+
[HttpMethod.GET, '/base/a/b/c', routes.abc],
|
|
83
|
+
[HttpMethod.GET, '/base/a/b/c/d', routes.abcd],
|
|
84
|
+
[HttpMethod.GET, '/base/a/b/c/u', routes.abc_path],
|
|
85
|
+
[HttpMethod.GET, '/base/a/b', undefined],
|
|
86
|
+
[HttpMethod.GET, '/base/a/b/c/d/e', undefined],
|
|
87
|
+
[HttpMethod.GET, '/base/a/b/c/d/e/f', undefined],
|
|
88
|
+
]
|
|
89
|
+
)
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
test('fails to construct with duplicate routes', () => {
|
|
93
|
+
expect(
|
|
94
|
+
() =>
|
|
95
|
+
new RouteResolver({
|
|
96
|
+
routes: [
|
|
97
|
+
mockRoute(HttpMethod.GET, '/a/b/c/:d/:e/b') as any,
|
|
98
|
+
mockRoute(HttpMethod.GET, '/a/b/c/:jshj/:e/b') as any,
|
|
99
|
+
],
|
|
100
|
+
})
|
|
101
|
+
).toThrowError('Duplicate route: GET: /a/b/c/:jshj/:e/b')
|
|
102
|
+
})
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
const parameterizedTest = <T extends { [k: string]: Route }>(
|
|
106
|
+
routes: T,
|
|
107
|
+
tests: (routes: T) => [HttpMethod, string, Route?][]
|
|
108
|
+
) => {
|
|
109
|
+
const underTest = new RouteResolver({
|
|
110
|
+
routes: Object.values(routes) as any,
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
tests(routes).forEach(([method, path, expected]) =>
|
|
114
|
+
expect(underTest.resolveRoute(method, path)).toBe(expected)
|
|
115
|
+
)
|
|
116
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jest } from '@jest/globals'
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
|
|
4
|
+
import ContainerServer from '../../src/Server/lib/ContainerServer.js'
|
|
5
|
+
import Server from '../../src/Server/lib/Server.js'
|
|
6
|
+
import Router from '../../src/Server/Router.js'
|
|
7
|
+
|
|
8
|
+
describe('Router basics', () => {
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
let mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {})
|
|
11
|
+
beforeAll(() => {
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {})
|
|
14
|
+
})
|
|
15
|
+
afterAll(() => {
|
|
16
|
+
mockExit.mockRestore()
|
|
17
|
+
})
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
mockExit.mockReset()
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
test('Serverless server', async () => {
|
|
23
|
+
process.env['HYBRIDLESS_RUNTIME'] = undefined
|
|
24
|
+
const router = new Router({ routes: [] })
|
|
25
|
+
expect(router.getExport()).to.not.be.undefined
|
|
26
|
+
expect(router['server']).to.be.an.instanceof(Server)
|
|
27
|
+
expect(router['server']).to.not.be.an.instanceof(ContainerServer)
|
|
28
|
+
})
|
|
29
|
+
test('Container server', async () => {
|
|
30
|
+
process.env['HYBRIDLESS_RUNTIME'] = 'true'
|
|
31
|
+
const router = new Router({ routes: [] })
|
|
32
|
+
expect(router.getExport()).to.not.be.undefined
|
|
33
|
+
expect(router['server']).to.be.an.instanceof(Server)
|
|
34
|
+
expect(router['server']).to.be.an.instanceof(ContainerServer)
|
|
35
|
+
await router['server']['stop']()
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
export {}
|