@creator.co/wapi 1.2.2 → 1.2.3
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 +1 -1
- package/.github/workflows/prs.yml +1 -1
- package/index.ts +12 -10
- package/jest.config.ts +19 -19
- package/package.json +1 -1
- 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,84 +1,72 @@
|
|
|
1
|
-
import { expect } from
|
|
1
|
+
import { expect } from 'chai'
|
|
2
2
|
|
|
3
|
-
import Response from
|
|
4
|
-
import Globals from
|
|
5
|
-
import Validator from
|
|
6
|
-
import { ViewSchema } from
|
|
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
7
|
|
|
8
8
|
function expectFullFailure(validationResult, c = 4) {
|
|
9
9
|
expect(validationResult).to.be.an.instanceof(Response)
|
|
10
10
|
if (validationResult instanceof Response) {
|
|
11
11
|
expect(validationResult.getBody()).is.not.null
|
|
12
|
-
expect(validationResult.getBody()).to.have.property(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
)
|
|
16
|
-
expect(validationResult.getBody()).to.have.property(
|
|
17
|
-
"errCode",
|
|
18
|
-
Globals.ErrorCode_InvalidInput,
|
|
19
|
-
)
|
|
20
|
-
expect(validationResult.getBody()).to.have.property("validationFailure")
|
|
21
|
-
expect(validationResult.getBody()["validationFailure"]).to.have.lengthOf(c)
|
|
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)
|
|
22
16
|
expect(validationResult.getCode()).is.equals(400)
|
|
23
17
|
}
|
|
24
18
|
}
|
|
25
19
|
|
|
26
|
-
describe(
|
|
27
|
-
test(
|
|
28
|
-
const validationResult = Validator.validateSchema(
|
|
29
|
-
async () => {},
|
|
30
|
-
ViewSchema,
|
|
31
|
-
)
|
|
20
|
+
describe('Validates unsuccessfully', () => {
|
|
21
|
+
test('Fails to validate async', () => {
|
|
22
|
+
const validationResult = Validator.validateSchema(async () => {}, ViewSchema)
|
|
32
23
|
expectFullFailure(validationResult, 1)
|
|
33
24
|
})
|
|
34
25
|
|
|
35
|
-
test(
|
|
26
|
+
test('Fails to validate null', () => {
|
|
36
27
|
const validationResult = Validator.validateSchema(null, ViewSchema)
|
|
37
28
|
expectFullFailure(validationResult, 1)
|
|
38
29
|
})
|
|
39
30
|
|
|
40
|
-
test(
|
|
41
|
-
const validationResult = Validator.validateSchema(
|
|
31
|
+
test('Fails to validate empty string', () => {
|
|
32
|
+
const validationResult = Validator.validateSchema('', ViewSchema)
|
|
42
33
|
expectFullFailure(validationResult, 1)
|
|
43
34
|
})
|
|
44
35
|
|
|
45
|
-
test(
|
|
36
|
+
test('Fails to validate empty object', () => {
|
|
46
37
|
const validationResult = Validator.validateSchema({}, ViewSchema)
|
|
47
38
|
expectFullFailure(validationResult)
|
|
48
39
|
})
|
|
49
40
|
|
|
50
|
-
test(
|
|
51
|
-
const validationResult = Validator.validateSchema(
|
|
52
|
-
{ name: "Joe" },
|
|
53
|
-
ViewSchema,
|
|
54
|
-
)
|
|
41
|
+
test('Fails to validate object with wrong keys', () => {
|
|
42
|
+
const validationResult = Validator.validateSchema({ name: 'Joe' }, ViewSchema)
|
|
55
43
|
expectFullFailure(validationResult)
|
|
56
44
|
})
|
|
57
45
|
|
|
58
|
-
test(
|
|
46
|
+
test('Fails to validate object with wrong key types', () => {
|
|
59
47
|
const validationResult = Validator.validateSchema({ id: 123 }, ViewSchema)
|
|
60
48
|
expectFullFailure(validationResult)
|
|
61
49
|
if (validationResult instanceof Response) {
|
|
62
|
-
console.log(validationResult.getBody()[
|
|
50
|
+
console.log(validationResult.getBody()['validationFailure'])
|
|
63
51
|
expect(
|
|
64
|
-
validationResult.getBody()[
|
|
65
|
-
return f.message ==
|
|
66
|
-
})
|
|
52
|
+
validationResult.getBody()['validationFailure'].filter(f => {
|
|
53
|
+
return f.message == 'Expected string, received number'
|
|
54
|
+
})
|
|
67
55
|
).to.have.lengthOf(1)
|
|
68
56
|
}
|
|
69
57
|
})
|
|
70
58
|
})
|
|
71
59
|
|
|
72
|
-
describe(
|
|
73
|
-
test(
|
|
60
|
+
describe('Validates successfully', () => {
|
|
61
|
+
test('Succeeds to validate', () => {
|
|
74
62
|
const validationResult = Validator.validateSchema(
|
|
75
63
|
{
|
|
76
|
-
id:
|
|
77
|
-
content:
|
|
64
|
+
id: '123',
|
|
65
|
+
content: '123',
|
|
78
66
|
createdAt: new Date(),
|
|
79
67
|
updatedAt: new Date(),
|
|
80
68
|
},
|
|
81
|
-
ViewSchema
|
|
69
|
+
ViewSchema
|
|
82
70
|
)
|
|
83
71
|
expect(validationResult).to.not.be.an.instanceof(Response)
|
|
84
72
|
expect(validationResult).to.be.true
|
package/tests/main.test.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
// import type * as Silly from "../silly"
|
|
5
5
|
// const { sillyFunction } = jest.requireActual<typeof Silly>("../silly")
|
|
6
6
|
|
|
7
|
-
describe(
|
|
8
|
-
test(
|
|
7
|
+
describe('silly function', () => {
|
|
8
|
+
test('guaranteed random', () => {
|
|
9
9
|
expect(4).toBe(4)
|
|
10
10
|
})
|
|
11
11
|
})
|