@creator.co/wapi 1.7.1-alpha4 → 1.7.1
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 +60 -0
- package/.github/workflows/npmpublish.yml +11 -0
- package/.github/workflows/prs.yml +13 -0
- package/dist/package-lock.json +2 -2
- package/dist/package.json +1 -1
- package/jest.config.ts +33 -0
- package/jest.smoke.config.ts +35 -0
- package/package.json +1 -1
- package/tests/API/Request.test.ts +273 -0
- package/tests/API/Response.test.ts +367 -0
- package/tests/API/Utils.test.ts +167 -0
- package/tests/BaseEvent/EventProcessor.test.ts +261 -0
- package/tests/BaseEvent/Process.test.ts +49 -0
- package/tests/BaseEvent/Transaction.test.ts +408 -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 +250 -0
- package/tests/Crypto/Crypto.test.ts +88 -0
- package/tests/Crypto/JWT.test.ts +92 -0
- package/tests/Database/DatabaseManager.test.ts +71 -0
- package/tests/Database/integrations/knex/KnexDatabase.test.ts +76 -0
- package/tests/Database/integrations/knex/KnexTransaction.test.ts +149 -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 +219 -0
- package/tests/Mailer/Mailer.test.ts +59 -0
- package/tests/Publisher/Publisher.test.ts +94 -0
- package/tests/Server/RouteResolver.test.ts +102 -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 +74 -0
- package/tests/Validation/Validator.test.ts +76 -0
- package/tsconfig.json +26 -0
- package/tsconfig.smoke.json +26 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { expect } from 'chai'
|
|
2
|
+
|
|
3
|
+
import Response from '../../src/API/Response'
|
|
4
|
+
import Globals from '../../src/Globals'
|
|
5
|
+
import Validator from '../../src/Validation/Validator'
|
|
6
|
+
import { ViewSchema } from '../Test.utils'
|
|
7
|
+
|
|
8
|
+
function expectFullFailure(validationResult, c = 4) {
|
|
9
|
+
expect(validationResult).to.be.an.instanceof(Response)
|
|
10
|
+
if (validationResult instanceof Response) {
|
|
11
|
+
expect(validationResult.getBody()).is.not.null
|
|
12
|
+
expect(validationResult.getBody()).to.have.property('err', Globals.ErrorResponseValidationFail)
|
|
13
|
+
expect(validationResult.getBody()).to.have.property('errCode', Globals.ErrorCode_InvalidInput)
|
|
14
|
+
expect(validationResult.getBody()).to.have.property('validationFailure')
|
|
15
|
+
expect(validationResult.getBody()['validationFailure']).to.have.lengthOf(c)
|
|
16
|
+
expect(validationResult.getCode()).is.equals(400)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe('Validates unsuccessfully', () => {
|
|
21
|
+
test('Fails to validate async', () => {
|
|
22
|
+
const validationResult = Validator.validateSchema(async () => {}, ViewSchema)
|
|
23
|
+
expectFullFailure(validationResult, 1)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test('Fails to validate null', () => {
|
|
27
|
+
const validationResult = Validator.validateSchema(null, ViewSchema)
|
|
28
|
+
expectFullFailure(validationResult, 1)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
test('Fails to validate empty string', () => {
|
|
32
|
+
const validationResult = Validator.validateSchema('', ViewSchema)
|
|
33
|
+
expectFullFailure(validationResult, 1)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
test('Fails to validate empty object', () => {
|
|
37
|
+
const validationResult = Validator.validateSchema({}, ViewSchema)
|
|
38
|
+
expectFullFailure(validationResult)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
test('Fails to validate object with wrong keys', () => {
|
|
42
|
+
const validationResult = Validator.validateSchema({ name: 'Joe' }, ViewSchema)
|
|
43
|
+
expectFullFailure(validationResult)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('Fails to validate object with wrong key types', () => {
|
|
47
|
+
const validationResult = Validator.validateSchema({ id: 123 }, ViewSchema)
|
|
48
|
+
expectFullFailure(validationResult)
|
|
49
|
+
if (validationResult instanceof Response) {
|
|
50
|
+
console.log(validationResult.getBody()['validationFailure'])
|
|
51
|
+
expect(
|
|
52
|
+
validationResult.getBody()['validationFailure'].filter(f => {
|
|
53
|
+
return f.message == 'Expected string, received number'
|
|
54
|
+
})
|
|
55
|
+
).to.have.lengthOf(1)
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
describe('Validates successfully', () => {
|
|
61
|
+
test('Succeeds to validate', () => {
|
|
62
|
+
const validationResult = Validator.validateSchema(
|
|
63
|
+
{
|
|
64
|
+
id: '123',
|
|
65
|
+
content: '123',
|
|
66
|
+
createdAt: new Date(),
|
|
67
|
+
updatedAt: new Date(),
|
|
68
|
+
},
|
|
69
|
+
ViewSchema
|
|
70
|
+
)
|
|
71
|
+
expect(validationResult).to.not.be.an.instanceof(Response)
|
|
72
|
+
expect(validationResult).to.be.true
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
export {}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"exclude": ["**/*.test.*", "**/__mocks__/*", "**/__tests__/*", "**/tests/*", "./dist/**/*", "./smoke-tests/**/*", "./jest*", "./node_modules"],
|
|
3
|
+
"include": ["./**/*", "./package.json", "./package-lock.json"],
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"lib": [
|
|
6
|
+
"es5",
|
|
7
|
+
"es6",
|
|
8
|
+
"dom"
|
|
9
|
+
],
|
|
10
|
+
"module": "esnext",
|
|
11
|
+
"target": "es6",
|
|
12
|
+
"moduleResolution": "node",
|
|
13
|
+
"esModuleInterop": true,
|
|
14
|
+
"noImplicitAny": false,
|
|
15
|
+
"noEmitOnError": true,
|
|
16
|
+
"removeComments": false,
|
|
17
|
+
"downlevelIteration": true,
|
|
18
|
+
"resolveJsonModule": true,
|
|
19
|
+
"sourceMap": true,
|
|
20
|
+
"outDir": "dist",
|
|
21
|
+
"declaration": true,
|
|
22
|
+
"skipLibCheck": true,
|
|
23
|
+
"strictNullChecks": true,
|
|
24
|
+
"noErrorTruncation": true
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"exclude": ["./dist/**/*", "./smoke-tests/**/*", "./node_modules", "./**/Logger.test.*"],
|
|
3
|
+
"include": ["./**/*", "./package.json", "./package-lock.json"],
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"lib": [
|
|
6
|
+
"es5",
|
|
7
|
+
"es6",
|
|
8
|
+
"dom"
|
|
9
|
+
],
|
|
10
|
+
"module": "esnext",
|
|
11
|
+
"target": "es6",
|
|
12
|
+
"moduleResolution": "node",
|
|
13
|
+
"noImplicitAny": false,
|
|
14
|
+
"noEmitOnError": true,
|
|
15
|
+
"removeComments": false,
|
|
16
|
+
"downlevelIteration": true,
|
|
17
|
+
"resolveJsonModule": true,
|
|
18
|
+
"sourceMap": true,
|
|
19
|
+
"esModuleInterop": true,
|
|
20
|
+
"outDir": "smoke-tests",
|
|
21
|
+
"declaration": true,
|
|
22
|
+
"skipLibCheck": true,
|
|
23
|
+
"strictNullChecks": true,
|
|
24
|
+
"noErrorTruncation": true
|
|
25
|
+
}
|
|
26
|
+
}
|