@gala-chain/launchpad 1.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/.dev-env +7 -0
- package/.dockerignore +9 -0
- package/.eslintignore +4 -0
- package/.eslintrc.json +37 -0
- package/.github/workflows/publish-on-tag.yml +72 -0
- package/.github/workflows/test-on-push.yml +32 -0
- package/.nvmrc +1 -0
- package/.prettierignore +4 -0
- package/.prettierrc +12 -0
- package/Dockerfile +31 -0
- package/LICENSE +201 -0
- package/README.md +2 -0
- package/api-config.json +16 -0
- package/e2e/__snapshots__/api.spec.ts.snap +2482 -0
- package/e2e/api-config.json +17 -0
- package/e2e/api.spec.ts +48 -0
- package/e2e/jest.config.js +42 -0
- package/e2e/tsconfig.json +10 -0
- package/jest.config.ts +27 -0
- package/lib/jest.config.d.ts +13 -0
- package/lib/jest.config.d.ts.map +1 -0
- package/lib/jest.config.js +28 -0
- package/lib/jest.config.js.map +1 -0
- package/lib/package.json +54 -0
- package/lib/src/api/index.d.ts +4 -0
- package/lib/src/api/index.d.ts.map +1 -0
- package/lib/src/api/index.js +21 -0
- package/lib/src/api/index.js.map +1 -0
- package/lib/src/api/types/LaunchpadDtos.d.ts +102 -0
- package/lib/src/api/types/LaunchpadDtos.d.ts.map +1 -0
- package/lib/src/api/types/LaunchpadDtos.js +410 -0
- package/lib/src/api/types/LaunchpadDtos.js.map +1 -0
- package/lib/src/api/types/LaunchpadFeeConfig.d.ts +9 -0
- package/lib/src/api/types/LaunchpadFeeConfig.d.ts.map +1 -0
- package/lib/src/api/types/LaunchpadFeeConfig.js +56 -0
- package/lib/src/api/types/LaunchpadFeeConfig.js.map +1 -0
- package/lib/src/api/types/LaunchpadFinalizeAllocation.d.ts +10 -0
- package/lib/src/api/types/LaunchpadFinalizeAllocation.d.ts.map +1 -0
- package/lib/src/api/types/LaunchpadFinalizeAllocation.js +70 -0
- package/lib/src/api/types/LaunchpadFinalizeAllocation.js.map +1 -0
- package/lib/src/api/types/LaunchpadSale.d.ts +35 -0
- package/lib/src/api/types/LaunchpadSale.d.ts.map +1 -0
- package/lib/src/api/types/LaunchpadSale.js +195 -0
- package/lib/src/api/types/LaunchpadSale.js.map +1 -0
- package/lib/src/api/types/index.d.ts +5 -0
- package/lib/src/api/types/index.d.ts.map +1 -0
- package/lib/src/api/types/index.js +22 -0
- package/lib/src/api/types/index.js.map +1 -0
- package/lib/src/api/utils/error.d.ts +20 -0
- package/lib/src/api/utils/error.d.ts.map +1 -0
- package/lib/src/api/utils/error.js +35 -0
- package/lib/src/api/utils/error.js.map +1 -0
- package/lib/src/api/utils/index.d.ts +2 -0
- package/lib/src/api/utils/index.d.ts.map +1 -0
- package/lib/src/api/utils/index.js +19 -0
- package/lib/src/api/utils/index.js.map +1 -0
- package/lib/src/api/validators/decorators.d.ts +19 -0
- package/lib/src/api/validators/decorators.d.ts.map +1 -0
- package/lib/src/api/validators/decorators.js +391 -0
- package/lib/src/api/validators/decorators.js.map +1 -0
- package/lib/src/api/validators/index.d.ts +2 -0
- package/lib/src/api/validators/index.d.ts.map +1 -0
- package/lib/src/api/validators/index.js +19 -0
- package/lib/src/api/validators/index.js.map +1 -0
- package/lib/src/chaincode/LaunchpadContract.d.ts +20 -0
- package/lib/src/chaincode/LaunchpadContract.d.ts.map +1 -0
- package/lib/src/chaincode/LaunchpadContract.js +217 -0
- package/lib/src/chaincode/LaunchpadContract.js.map +1 -0
- package/lib/src/chaincode/dexLaunchpadFeeGate.d.ts +14 -0
- package/lib/src/chaincode/dexLaunchpadFeeGate.d.ts.map +1 -0
- package/lib/src/chaincode/dexLaunchpadFeeGate.js +47 -0
- package/lib/src/chaincode/dexLaunchpadFeeGate.js.map +1 -0
- package/lib/src/chaincode/index.d.ts +2 -0
- package/lib/src/chaincode/index.d.ts.map +1 -0
- package/lib/src/chaincode/index.js +19 -0
- package/lib/src/chaincode/index.js.map +1 -0
- package/lib/src/chaincode/launchpad/buyExactToken.d.ts +20 -0
- package/lib/src/chaincode/launchpad/buyExactToken.d.ts.map +1 -0
- package/lib/src/chaincode/launchpad/buyExactToken.js +113 -0
- package/lib/src/chaincode/launchpad/buyExactToken.js.map +1 -0
- package/lib/src/chaincode/launchpad/buyWithNative.d.ts +22 -0
- package/lib/src/chaincode/launchpad/buyWithNative.d.ts.map +1 -0
- package/lib/src/chaincode/launchpad/buyWithNative.js +106 -0
- package/lib/src/chaincode/launchpad/buyWithNative.js.map +1 -0
- package/lib/src/chaincode/launchpad/callMemeTokenIn.d.ts +27 -0
- package/lib/src/chaincode/launchpad/callMemeTokenIn.d.ts.map +1 -0
- package/lib/src/chaincode/launchpad/callMemeTokenIn.js +76 -0
- package/lib/src/chaincode/launchpad/callMemeTokenIn.js.map +1 -0
- package/lib/src/chaincode/launchpad/callMemeTokenOut.d.ts +25 -0
- package/lib/src/chaincode/launchpad/callMemeTokenOut.d.ts.map +1 -0
- package/lib/src/chaincode/launchpad/callMemeTokenOut.js +56 -0
- package/lib/src/chaincode/launchpad/callMemeTokenOut.js.map +1 -0
- package/lib/src/chaincode/launchpad/callNativeTokenIn.d.ts +25 -0
- package/lib/src/chaincode/launchpad/callNativeTokenIn.d.ts.map +1 -0
- package/lib/src/chaincode/launchpad/callNativeTokenIn.js +51 -0
- package/lib/src/chaincode/launchpad/callNativeTokenIn.js.map +1 -0
- package/lib/src/chaincode/launchpad/callNativeTokenOut.d.ts +26 -0
- package/lib/src/chaincode/launchpad/callNativeTokenOut.d.ts.map +1 -0
- package/lib/src/chaincode/launchpad/callNativeTokenOut.js +60 -0
- package/lib/src/chaincode/launchpad/callNativeTokenOut.js.map +1 -0
- package/lib/src/chaincode/launchpad/configureLaunchpadFeeConfig.d.ts +4 -0
- package/lib/src/chaincode/launchpad/configureLaunchpadFeeConfig.d.ts.map +1 -0
- package/lib/src/chaincode/launchpad/configureLaunchpadFeeConfig.js +58 -0
- package/lib/src/chaincode/launchpad/configureLaunchpadFeeConfig.js.map +1 -0
- package/lib/src/chaincode/launchpad/createSale.d.ts +26 -0
- package/lib/src/chaincode/launchpad/createSale.d.ts.map +1 -0
- package/lib/src/chaincode/launchpad/createSale.js +129 -0
- package/lib/src/chaincode/launchpad/createSale.js.map +1 -0
- package/lib/src/chaincode/launchpad/fees.d.ts +6 -0
- package/lib/src/chaincode/launchpad/fees.d.ts.map +1 -0
- package/lib/src/chaincode/launchpad/fees.js +85 -0
- package/lib/src/chaincode/launchpad/fees.js.map +1 -0
- package/lib/src/chaincode/launchpad/fetchLaunchpadAdressConfig.d.ts +4 -0
- package/lib/src/chaincode/launchpad/fetchLaunchpadAdressConfig.d.ts.map +1 -0
- package/lib/src/chaincode/launchpad/fetchLaunchpadAdressConfig.js +36 -0
- package/lib/src/chaincode/launchpad/fetchLaunchpadAdressConfig.js.map +1 -0
- package/lib/src/chaincode/launchpad/fetchSaleDetails.d.ts +19 -0
- package/lib/src/chaincode/launchpad/fetchSaleDetails.d.ts.map +1 -0
- package/lib/src/chaincode/launchpad/fetchSaleDetails.js +49 -0
- package/lib/src/chaincode/launchpad/fetchSaleDetails.js.map +1 -0
- package/lib/src/chaincode/launchpad/finaliseSale.d.ts +4 -0
- package/lib/src/chaincode/launchpad/finaliseSale.d.ts.map +1 -0
- package/lib/src/chaincode/launchpad/finaliseSale.js +144 -0
- package/lib/src/chaincode/launchpad/finaliseSale.js.map +1 -0
- package/lib/src/chaincode/launchpad/finalizeTokenAllocation.d.ts +4 -0
- package/lib/src/chaincode/launchpad/finalizeTokenAllocation.d.ts.map +1 -0
- package/lib/src/chaincode/launchpad/finalizeTokenAllocation.js +43 -0
- package/lib/src/chaincode/launchpad/finalizeTokenAllocation.js.map +1 -0
- package/lib/src/chaincode/launchpad/index.d.ts +15 -0
- package/lib/src/chaincode/launchpad/index.d.ts.map +1 -0
- package/lib/src/chaincode/launchpad/index.js +32 -0
- package/lib/src/chaincode/launchpad/index.js.map +1 -0
- package/lib/src/chaincode/launchpad/preMintCalculation.d.ts +17 -0
- package/lib/src/chaincode/launchpad/preMintCalculation.d.ts.map +1 -0
- package/lib/src/chaincode/launchpad/preMintCalculation.js +56 -0
- package/lib/src/chaincode/launchpad/preMintCalculation.js.map +1 -0
- package/lib/src/chaincode/launchpad/sellExactToken.d.ts +22 -0
- package/lib/src/chaincode/launchpad/sellExactToken.d.ts.map +1 -0
- package/lib/src/chaincode/launchpad/sellExactToken.js +102 -0
- package/lib/src/chaincode/launchpad/sellExactToken.js.map +1 -0
- package/lib/src/chaincode/launchpad/sellWithNative.d.ts +23 -0
- package/lib/src/chaincode/launchpad/sellWithNative.d.ts.map +1 -0
- package/lib/src/chaincode/launchpad/sellWithNative.js +97 -0
- package/lib/src/chaincode/launchpad/sellWithNative.js.map +1 -0
- package/lib/src/chaincode/utils/index.d.ts +2 -0
- package/lib/src/chaincode/utils/index.d.ts.map +1 -0
- package/lib/src/chaincode/utils/index.js +19 -0
- package/lib/src/chaincode/utils/index.js.map +1 -0
- package/lib/src/chaincode/utils/launchpadSaleUtils.d.ts +11 -0
- package/lib/src/chaincode/utils/launchpadSaleUtils.d.ts.map +1 -0
- package/lib/src/chaincode/utils/launchpadSaleUtils.js +65 -0
- package/lib/src/chaincode/utils/launchpadSaleUtils.js.map +1 -0
- package/lib/src/cli.d.ts +3 -0
- package/lib/src/cli.d.ts.map +1 -0
- package/lib/src/cli.js +41 -0
- package/lib/src/cli.js.map +1 -0
- package/lib/src/index.d.ts +14 -0
- package/lib/src/index.d.ts.map +1 -0
- package/lib/src/index.js +32 -0
- package/lib/src/index.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/package.json +54 -0
- package/src/api/index.ts +18 -0
- package/src/api/types/LaunchpadDtos.ts +362 -0
- package/src/api/types/LaunchpadFeeConfig.ts +45 -0
- package/src/api/types/LaunchpadFinalizeAllocation.ts +65 -0
- package/src/api/types/LaunchpadSale.ts +200 -0
- package/src/api/types/index.ts +19 -0
- package/src/api/utils/error.ts +32 -0
- package/src/api/utils/index.ts +16 -0
- package/src/api/validators/decorators.spec.ts +277 -0
- package/src/api/validators/decorators.ts +401 -0
- package/src/api/validators/index.ts +16 -0
- package/src/chaincode/LaunchpadContract.ts +211 -0
- package/src/chaincode/dexLaunchpadFeeGate.ts +43 -0
- package/src/chaincode/index.ts +16 -0
- package/src/chaincode/launchpad/buyExactToken.ts +128 -0
- package/src/chaincode/launchpad/buyWithNative.ts +120 -0
- package/src/chaincode/launchpad/callMemeTokenIn.ts +82 -0
- package/src/chaincode/launchpad/callMemeTokenOut.ts +80 -0
- package/src/chaincode/launchpad/callNativeTokenIn.ts +71 -0
- package/src/chaincode/launchpad/callNativeTokenOut.ts +81 -0
- package/src/chaincode/launchpad/configureLaunchpadFeeConfig.ts +69 -0
- package/src/chaincode/launchpad/createSale.ts +157 -0
- package/src/chaincode/launchpad/fees.ts +105 -0
- package/src/chaincode/launchpad/fetchLaunchpadAdressConfig.ts +38 -0
- package/src/chaincode/launchpad/fetchSaleDetails.ts +53 -0
- package/src/chaincode/launchpad/finaliseSale.ts +217 -0
- package/src/chaincode/launchpad/finalizeTokenAllocation.ts +47 -0
- package/src/chaincode/launchpad/index.ts +28 -0
- package/src/chaincode/launchpad/preMintCalculation.ts +61 -0
- package/src/chaincode/launchpad/sellExactToken.ts +122 -0
- package/src/chaincode/launchpad/sellWithNative.ts +112 -0
- package/src/chaincode/utils/index.ts +15 -0
- package/src/chaincode/utils/launchpadSaleUtils.ts +68 -0
- package/src/cli.ts +63 -0
- package/src/index.ts +32 -0
- package/tsconfig.base.json +29 -0
- package/tsconfig.json +19 -0
- package/tsconfig.spec.json +11 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Gala Games Inc. All rights reserved.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
import { ErrorCode as BaseErrorCode, ChainError } from "@gala-chain/api";
|
|
16
|
+
|
|
17
|
+
export const ErrorCode = {
|
|
18
|
+
...BaseErrorCode,
|
|
19
|
+
PRECONDITION_FAILED: 412
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export class SlippageToleranceExceededError extends ChainError {
|
|
23
|
+
constructor(message: string) {
|
|
24
|
+
super(message, 412);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class PreConditionFailedError extends ChainError {
|
|
29
|
+
constructor(message: string) {
|
|
30
|
+
super(message, 412);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Gala Games Inc. All rights reserved.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export * from "./error";
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Gala Games Inc. All rights reserved.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
import { ArrayUniqueObjects, ChainCallDTO } from "@gala-chain/api";
|
|
16
|
+
import BigNumber from "bignumber.js";
|
|
17
|
+
import { ArrayNotEmpty, validate } from "class-validator";
|
|
18
|
+
|
|
19
|
+
import { BigNumberIsNegative, IsStringArrayRecord, IsStringRecord } from "./decorators";
|
|
20
|
+
|
|
21
|
+
describe("ArrayUniqueObject", () => {
|
|
22
|
+
it("validation should give errors when two users have the same id", async () => {
|
|
23
|
+
// Given
|
|
24
|
+
class MockDto extends ChainCallDTO {
|
|
25
|
+
@ArrayNotEmpty()
|
|
26
|
+
@ArrayUniqueObjects("id")
|
|
27
|
+
users: unknown[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const NewFake = new MockDto();
|
|
31
|
+
NewFake.users = [{ id: 1 }, { id: 1 }, { id: 3 }];
|
|
32
|
+
|
|
33
|
+
// When
|
|
34
|
+
const output = await NewFake.validate();
|
|
35
|
+
|
|
36
|
+
// Then
|
|
37
|
+
expect(output).toEqual([
|
|
38
|
+
expect.objectContaining({
|
|
39
|
+
constraints: expect.objectContaining({
|
|
40
|
+
ArrayUniqueObjects: "users must not contains duplicate entry for id"
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
]);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("validation should give errors when two users have the same id", async () => {
|
|
47
|
+
// Given
|
|
48
|
+
class MockDto extends ChainCallDTO {
|
|
49
|
+
@ArrayNotEmpty()
|
|
50
|
+
@ArrayUniqueObjects("id")
|
|
51
|
+
users: unknown[];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const NewFake = new MockDto();
|
|
55
|
+
NewFake.users = [
|
|
56
|
+
{ id: 1, other: "yee" },
|
|
57
|
+
{ id: 1, other: "wee" },
|
|
58
|
+
{ id: 3, other: "hee" }
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
// When
|
|
62
|
+
const output = await NewFake.validate();
|
|
63
|
+
|
|
64
|
+
// Then
|
|
65
|
+
expect(output).toEqual([
|
|
66
|
+
expect.objectContaining({
|
|
67
|
+
constraints: expect.objectContaining({
|
|
68
|
+
ArrayUniqueObjects: "users must not contains duplicate entry for id"
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
]);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("validation should pass when all users have different ids", async () => {
|
|
75
|
+
// Given
|
|
76
|
+
class MockDto extends ChainCallDTO {
|
|
77
|
+
@ArrayNotEmpty()
|
|
78
|
+
@ArrayUniqueObjects("id")
|
|
79
|
+
users: unknown[];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const NewFake = new MockDto();
|
|
83
|
+
NewFake.users = [{ id: 1 }, { id: 2 }, { id: 3 }];
|
|
84
|
+
|
|
85
|
+
// When
|
|
86
|
+
const output = await NewFake.validate();
|
|
87
|
+
|
|
88
|
+
// Then
|
|
89
|
+
expect(output.length).toEqual(0);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe("BigNumberIsNegative", () => {
|
|
94
|
+
it("should return error if BigNumber is positive", async () => {
|
|
95
|
+
// Given
|
|
96
|
+
class MockDto extends ChainCallDTO {
|
|
97
|
+
@BigNumberIsNegative()
|
|
98
|
+
amount: BigNumber;
|
|
99
|
+
}
|
|
100
|
+
const dto = new MockDto();
|
|
101
|
+
dto.amount = new BigNumber(5);
|
|
102
|
+
|
|
103
|
+
// When
|
|
104
|
+
const result = await validate(dto);
|
|
105
|
+
|
|
106
|
+
// Then
|
|
107
|
+
expect(result).toEqual([
|
|
108
|
+
expect.objectContaining({
|
|
109
|
+
constraints: expect.objectContaining({
|
|
110
|
+
BigNumberIsNegative: "amount must be negative but is 5"
|
|
111
|
+
})
|
|
112
|
+
})
|
|
113
|
+
]);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("should pass validation for negative BigNumber", async () => {
|
|
117
|
+
// Given
|
|
118
|
+
class MockDto extends ChainCallDTO {
|
|
119
|
+
@BigNumberIsNegative()
|
|
120
|
+
amount: BigNumber;
|
|
121
|
+
}
|
|
122
|
+
const dto = new MockDto();
|
|
123
|
+
dto.amount = new BigNumber(-10);
|
|
124
|
+
|
|
125
|
+
// When
|
|
126
|
+
const result = await validate(dto);
|
|
127
|
+
|
|
128
|
+
// then
|
|
129
|
+
expect(result.length).toBe(0);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe("IsStringArrayRecord validator", () => {
|
|
134
|
+
class MockDto {
|
|
135
|
+
@IsStringArrayRecord()
|
|
136
|
+
data!: unknown;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
it("should pass for a valid non-empty Record<string, string[]>", async () => {
|
|
140
|
+
// Given
|
|
141
|
+
const dto = new MockDto();
|
|
142
|
+
dto.data = {
|
|
143
|
+
key1: ["value1", "value2"],
|
|
144
|
+
key2: ["value3"]
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// When
|
|
148
|
+
const errors = await validate(dto);
|
|
149
|
+
|
|
150
|
+
// Then
|
|
151
|
+
expect(errors.length).toBe(0);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("should pass for an empty object", async () => {
|
|
155
|
+
// Given
|
|
156
|
+
const dto = new MockDto();
|
|
157
|
+
dto.data = {};
|
|
158
|
+
|
|
159
|
+
// When
|
|
160
|
+
const errors = await validate(dto);
|
|
161
|
+
|
|
162
|
+
// Then
|
|
163
|
+
expect(errors.length).toBe(0);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("should fail if any value is not a string", async () => {
|
|
167
|
+
// Given
|
|
168
|
+
const dto = new MockDto();
|
|
169
|
+
dto.data = {
|
|
170
|
+
key1: "value1",
|
|
171
|
+
key2: 123
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// When
|
|
175
|
+
const errors = await validate(dto);
|
|
176
|
+
|
|
177
|
+
// Then
|
|
178
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it("should fail if input is null", async () => {
|
|
182
|
+
// Given
|
|
183
|
+
const dto = new MockDto();
|
|
184
|
+
dto.data = null;
|
|
185
|
+
|
|
186
|
+
// When
|
|
187
|
+
const errors = await validate(dto);
|
|
188
|
+
|
|
189
|
+
// Then
|
|
190
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it("should fail if input is an array", async () => {
|
|
194
|
+
// Given
|
|
195
|
+
const dto = new MockDto();
|
|
196
|
+
dto.data = ["a", "b"];
|
|
197
|
+
|
|
198
|
+
// When
|
|
199
|
+
const errors = await validate(dto);
|
|
200
|
+
|
|
201
|
+
// Then
|
|
202
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
describe("IsStringRecord validator", () => {
|
|
207
|
+
class MockDto {
|
|
208
|
+
@IsStringRecord()
|
|
209
|
+
data!: unknown;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
it("should pass for a valid non-empty Record<string, string>", async () => {
|
|
213
|
+
// Given
|
|
214
|
+
const dto = new MockDto();
|
|
215
|
+
dto.data = {
|
|
216
|
+
key1: "value1",
|
|
217
|
+
key2: "value2"
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
// When
|
|
221
|
+
const errors = await validate(dto);
|
|
222
|
+
|
|
223
|
+
// Then
|
|
224
|
+
expect(errors.length).toBe(0);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it("should pass for an empty object", async () => {
|
|
228
|
+
// Given
|
|
229
|
+
const dto = new MockDto();
|
|
230
|
+
dto.data = {};
|
|
231
|
+
|
|
232
|
+
// When
|
|
233
|
+
const errors = await validate(dto);
|
|
234
|
+
|
|
235
|
+
// Then
|
|
236
|
+
expect(errors.length).toBe(0);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it("should fail if any value is not a string", async () => {
|
|
240
|
+
// Given
|
|
241
|
+
const dto = new MockDto();
|
|
242
|
+
dto.data = {
|
|
243
|
+
key1: "value1",
|
|
244
|
+
key2: 123
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
// When
|
|
248
|
+
const errors = await validate(dto);
|
|
249
|
+
|
|
250
|
+
// Then
|
|
251
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it("should fail if input is null", async () => {
|
|
255
|
+
// Given
|
|
256
|
+
const dto = new MockDto();
|
|
257
|
+
dto.data = null;
|
|
258
|
+
|
|
259
|
+
// When
|
|
260
|
+
const errors = await validate(dto);
|
|
261
|
+
|
|
262
|
+
// Then
|
|
263
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it("should fail if input is an array", async () => {
|
|
267
|
+
// Given
|
|
268
|
+
const dto = new MockDto();
|
|
269
|
+
dto.data = ["a", "b"];
|
|
270
|
+
|
|
271
|
+
// When
|
|
272
|
+
const errors = await validate(dto);
|
|
273
|
+
|
|
274
|
+
// Then
|
|
275
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
276
|
+
});
|
|
277
|
+
});
|