itrm-tools 1.3.5-beta.1 → 1.3.5-beta.2
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/README.md +2 -2
- package/dist/api/APIService.js +8 -2
- package/dist/api/APIService.js.map +1 -1
- package/dist/api/express/ExpressStandardConfiguration.d.ts +1 -1
- package/dist/api/express/ExpressStandardConfiguration.js +9 -1
- package/dist/api/express/ExpressStandardConfiguration.js.map +1 -1
- package/dist/api/external/ExternalApiConnection.d.ts +13 -0
- package/dist/api/external/ExternalApiConnection.js +24 -0
- package/dist/api/external/ExternalApiConnection.js.map +1 -0
- package/dist/api/external/cetus/CetusStrategyApiManager.d.ts +4 -3
- package/dist/api/external/cetus/CetusStrategyApiManager.js +4 -4
- package/dist/api/external/cetus/CetusStrategyApiManager.js.map +1 -1
- package/dist/api/request/RequestAxiosCall.d.ts +4 -4
- package/dist/api/request/RequestAxiosCall.js.map +1 -1
- package/dist/api/request/crud/CrudManager.d.ts +2 -2
- package/dist/api/request/crud/CrudServiceManager.d.ts +5 -5
- package/dist/api/request/crud/CrudServiceManager.js.map +1 -1
- package/dist/api/request/crud/common/ActivityHistoryManager.d.ts +40 -0
- package/dist/api/request/crud/common/ActivityHistoryManager.js +69 -0
- package/dist/api/request/crud/common/ActivityHistoryManager.js.map +1 -0
- package/dist/api/request/crud/common/ApplicationManager.d.ts +39 -0
- package/dist/api/request/crud/common/ApplicationManager.js +57 -0
- package/dist/api/request/crud/common/ApplicationManager.js.map +1 -0
- package/dist/api/request/crud/common/AvailablePlatformManager.d.ts +39 -0
- package/dist/api/request/crud/common/AvailablePlatformManager.js +69 -0
- package/dist/api/request/crud/common/AvailablePlatformManager.js.map +1 -0
- package/dist/api/request/crud/common/ComponentManager.d.ts +56 -0
- package/dist/api/request/crud/common/ComponentManager.js +63 -0
- package/dist/api/request/crud/common/ComponentManager.js.map +1 -0
- package/dist/api/request/crud/common/KeyManager.d.ts +42 -0
- package/dist/api/request/crud/common/KeyManager.js +70 -0
- package/dist/api/request/crud/common/KeyManager.js.map +1 -0
- package/dist/api/request/crud/common/PlatformManager.d.ts +44 -0
- package/dist/api/request/crud/common/PlatformManager.js +60 -0
- package/dist/api/request/crud/common/PlatformManager.js.map +1 -0
- package/dist/api/request/crud/common/RoleManager.d.ts +51 -0
- package/dist/api/request/crud/common/RoleManager.js +57 -0
- package/dist/api/request/crud/common/RoleManager.js.map +1 -0
- package/dist/api/request/crud/common/StatusManager.d.ts +34 -0
- package/dist/api/request/crud/common/StatusManager.js +57 -0
- package/dist/api/request/crud/common/StatusManager.js.map +1 -0
- package/dist/api/request/crud/common/TypeManager.d.ts +33 -0
- package/dist/api/request/crud/common/TypeManager.js +57 -0
- package/dist/api/request/crud/common/TypeManager.js.map +1 -0
- package/dist/api/request/crud/common/UserCredentialsManager.d.ts +39 -0
- package/dist/api/request/crud/common/UserCredentialsManager.js +67 -0
- package/dist/api/request/crud/common/UserCredentialsManager.js.map +1 -0
- package/dist/api/request/crud/common/UserManager.d.ts +35 -0
- package/dist/api/request/crud/common/UserManager.js +63 -0
- package/dist/api/request/crud/common/UserManager.js.map +1 -0
- package/dist/api/request/docs/DocumentationModels.d.ts +4 -4
- package/dist/api/request/docs/DocumentationModels.js.map +1 -1
- package/dist/cryptography/CipheringAlgorithm.d.ts +4 -0
- package/dist/cryptography/CipheringAlgorithm.js +3 -0
- package/dist/cryptography/CipheringAlgorithm.js.map +1 -0
- package/dist/cryptography/EncryptionAlgorithm.js.map +1 -0
- package/dist/cryptography/KeyGenerator.d.ts +3 -0
- package/dist/cryptography/KeyGenerator.js +3 -0
- package/dist/cryptography/KeyGenerator.js.map +1 -0
- package/dist/cryptography/Signer.d.ts +4 -0
- package/dist/cryptography/Signer.js +3 -0
- package/dist/cryptography/Signer.js.map +1 -0
- package/dist/cryptography/algorithm/AesCipheringAlgorithm.d.ts +6 -0
- package/dist/cryptography/algorithm/AesCipheringAlgorithm.js +28 -0
- package/dist/cryptography/algorithm/AesCipheringAlgorithm.js.map +1 -0
- package/dist/cryptography/generate/StandardApiKeyGenerator.d.ts +9 -0
- package/dist/cryptography/generate/StandardApiKeyGenerator.js +18 -0
- package/dist/cryptography/generate/StandardApiKeyGenerator.js.map +1 -0
- package/dist/cryptography/sign/ApiKeySigner.d.ts +14 -0
- package/dist/cryptography/sign/ApiKeySigner.js +35 -0
- package/dist/cryptography/sign/ApiKeySigner.js.map +1 -0
- package/dist/database/mongoose/MongooseModelManager.d.ts +40 -8
- package/dist/index.d.ts +17 -2
- package/dist/index.js +32 -3
- package/dist/index.js.map +1 -1
- package/package.json +75 -68
- package/.github/workflows/node.js.yml +0 -30
- package/dist/algorithm/encryption/EncryptionAlgorithm.js.map +0 -1
- package/dist/api/external/ExternalApiSigner.d.ts +0 -15
- package/dist/api/external/ExternalApiSigner.js +0 -25
- package/dist/api/external/ExternalApiSigner.js.map +0 -1
- package/jest.config.js +0 -7
- package/sequelize.sqlite +0 -0
- package/src/algorithm/encryption/EncryptionAlgorithm.ts +0 -4
- package/src/api/APIRequest.ts +0 -176
- package/src/api/APIRequestBuilder.ts +0 -28
- package/src/api/APIRouter.ts +0 -26
- package/src/api/APIService.ts +0 -117
- package/src/api/ExpressConfiguration.ts +0 -5
- package/src/api/HttpsAPIService.ts +0 -35
- package/src/api/alegra/AlegraConnectionManager.ts +0 -54
- package/src/api/alegra/AlegraTypes.ts +0 -150
- package/src/api/builder/StandardGetRequestBuilder.ts +0 -34
- package/src/api/channel/ServerSentEventsManager.ts +0 -28
- package/src/api/check/APIChecker.ts +0 -50
- package/src/api/check/CheckableAPIRequest.ts +0 -33
- package/src/api/check/CheckableAPIRouter.ts +0 -39
- package/src/api/check/request/CheckableDeleteRequest.ts +0 -17
- package/src/api/check/request/CheckableFileUploadingPostRequest.ts +0 -26
- package/src/api/check/request/CheckableGetRequest.ts +0 -17
- package/src/api/check/request/CheckablePostRequest.ts +0 -17
- package/src/api/check/request/CheckablePutRequest.ts +0 -17
- package/src/api/check/route/CorsCheckApiRouter.ts +0 -22
- package/src/api/check/route/SimpleCheckableAPIRouter.ts +0 -14
- package/src/api/express/ExpressFileUploadingConfiguration.ts +0 -22
- package/src/api/express/ExpressLogableConfig.ts +0 -11
- package/src/api/express/ExpressStandardConfiguration.ts +0 -25
- package/src/api/external/ExternalApiSigner.ts +0 -29
- package/src/api/external/cetus/CetusStrategyApiManager.ts +0 -48
- package/src/api/request/DeleteRequest.ts +0 -16
- package/src/api/request/GetRequest.ts +0 -16
- package/src/api/request/PostRequest.ts +0 -16
- package/src/api/request/PutRequest.ts +0 -16
- package/src/api/request/RequestAxiosCall.ts +0 -38
- package/src/api/request/crud/CrudManager.ts +0 -11
- package/src/api/request/crud/CrudServiceManager.ts +0 -117
- package/src/api/request/docs/DocumentationModels.ts +0 -121
- package/src/api/request/docs/DocumentationRequest.ts +0 -132
- package/src/api/route/SimpleAPIRouter.ts +0 -12
- package/src/database/mongoose/MongooseModelManager.ts +0 -65
- package/src/database/redis/RedisConnection.ts +0 -18
- package/src/database/redis/RedisModelManager.ts +0 -23
- package/src/database/sequelize/SequelizeConnection.ts +0 -45
- package/src/database/sequelize/SequelizeModelManager.ts +0 -71
- package/src/index.ts +0 -51
- package/src/log/Logger.ts +0 -27
- package/src/log/LoggerManager.ts +0 -50
- package/src/log/LoggerWebSocket.ts +0 -13
- package/src/math/Utils.ts +0 -4
- package/src/types/payments.ts +0 -811
- package/src/web3/Coin.ts +0 -18
- package/src/web3/coingecko/CoingeckoPriceFinder.ts +0 -75
- package/test/api/APIRouter.test.ts +0 -78
- package/test/api/APIService.test.ts +0 -50
- package/test/api/APITestDefinitions.ts +0 -7
- package/test/api/CORS.test.ts +0 -56
- package/test/api/alegra/AlegraConnectionManager.test.ts +0 -32
- package/test/api/check/CheckDefinitions.ts +0 -47
- package/test/api/check/CheckableAPIRouter.test.ts +0 -67
- package/test/api/check/CheckableDeleteRequest.test.ts +0 -92
- package/test/api/check/CheckableGetRequest.test.ts +0 -99
- package/test/api/check/CheckablePostRequest.test.ts +0 -108
- package/test/api/check/CheckablePutRequest.test.ts +0 -99
- package/test/api/docs/DocumentationRequest.test.ts +0 -192
- package/test/api/request/DeleteRequest.test.ts +0 -117
- package/test/api/request/GetRequest.test.ts +0 -140
- package/test/api/request/PostRequest.test.ts +0 -237
- package/test/api/request/PutRequest.test.ts +0 -166
- package/test/database/mongoose/MongooseModelManager.test.ts +0 -139
- package/test/database/redis/RedisConnection.test.ts +0 -7
- package/test/database/sequelize/SequealizeDefinitions.ts +0 -6
- package/test/database/sequelize/SequelizeConnection.test.ts +0 -30
- package/test/database/sequelize/SequelizeModelManager.test.ts +0 -206
- package/test/log/Logger.test.ts +0 -44
- package/test/web3/coingecko/CoingeckoPriceFinder.test.ts +0 -72
- package/tsconfig.json +0 -23
- /package/dist/{algorithm/encryption → cryptography}/EncryptionAlgorithm.d.ts +0 -0
- /package/dist/{algorithm/encryption → cryptography}/EncryptionAlgorithm.js +0 -0
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import { Request, Response } from "express";
|
|
2
|
-
import { RequestContext, PostRequest, APIService, RequestAxiosCall, RequestParameterType } from "../../../dist";
|
|
3
|
-
import { config } from "../APITestDefinitions";
|
|
4
|
-
|
|
5
|
-
const service = new APIService(config);
|
|
6
|
-
service.init();
|
|
7
|
-
|
|
8
|
-
class TestRequest extends PostRequest {
|
|
9
|
-
constructor() {
|
|
10
|
-
super({
|
|
11
|
-
path: '/test/:method/type',
|
|
12
|
-
params: [{
|
|
13
|
-
context: RequestContext.QUERY,
|
|
14
|
-
properties: [{ name: "value", type: RequestParameterType.STRING }]
|
|
15
|
-
}, {
|
|
16
|
-
context: RequestContext.QUERY,
|
|
17
|
-
properties: [{ name: "option", type: RequestParameterType.STRING }]
|
|
18
|
-
}, {
|
|
19
|
-
context: RequestContext.QUERY,
|
|
20
|
-
properties: [
|
|
21
|
-
{ name: "x", type: RequestParameterType.STRING },
|
|
22
|
-
{ name: "y", type: RequestParameterType.STRING }
|
|
23
|
-
]
|
|
24
|
-
}, {
|
|
25
|
-
context: RequestContext.PARAMS,
|
|
26
|
-
properties: [{ name: "method", type: RequestParameterType.STRING }]
|
|
27
|
-
}, {
|
|
28
|
-
context: RequestContext.BODY,
|
|
29
|
-
properties: [{ name: "date", type: RequestParameterType.STRING }]
|
|
30
|
-
}, {
|
|
31
|
-
context: RequestContext.BODY,
|
|
32
|
-
properties: [
|
|
33
|
-
{ name: "time", type: RequestParameterType.STRING },
|
|
34
|
-
{ name: "timestamp", type: RequestParameterType.NUMBER }
|
|
35
|
-
]
|
|
36
|
-
}]
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async apply(req: Request, res: Response): Promise<any> {
|
|
41
|
-
const { method } = req.params;
|
|
42
|
-
const { value, option, x, y } = req.query;
|
|
43
|
-
const { date, time, timestamp, values } = req.body;
|
|
44
|
-
return res.status(200).json({ message: "Success", method: method, type: value, option: option, date: date, time: time, x: x, y: y, timestamp: timestamp, values: values });
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
class UnexpectedErrorTestRequest extends PostRequest {
|
|
49
|
-
constructor() {
|
|
50
|
-
super({
|
|
51
|
-
path: '/test/error',
|
|
52
|
-
params: []
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async apply(req: Request, res: Response): Promise<any> {
|
|
57
|
-
throw 'Unexpected error';
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const testUrl = `http://localhost:${config.port}/test/testing/type?value=get`;
|
|
62
|
-
const testUrl2 = `http://localhost:${config.port}/test/testing/type?option=1`;
|
|
63
|
-
const testUrl3 = `http://localhost:${config.port}/test/testing/type?x=10&y=20`;
|
|
64
|
-
const testUrlMissingQuery = `http://localhost:${config.port}/test/testing/type`;
|
|
65
|
-
const testUrlUnexpectedError = `http://localhost:${config.port}/test/error`;
|
|
66
|
-
|
|
67
|
-
describe('testing POST Request', () => {
|
|
68
|
-
beforeAll(async () => {
|
|
69
|
-
await service.run(() => { });
|
|
70
|
-
});
|
|
71
|
-
afterAll(async () => {
|
|
72
|
-
await service.close(() => { })
|
|
73
|
-
});
|
|
74
|
-
test('Refuse request when API Request does not exist', async () => {
|
|
75
|
-
try {
|
|
76
|
-
await RequestAxiosCall.post(testUrl, { date: 'date' }, {
|
|
77
|
-
headers: { 'Content-Type': 'application/json', 'Origin': 'https://valid.com' }
|
|
78
|
-
});
|
|
79
|
-
} catch (err: any) {
|
|
80
|
-
//console.log("> Refuse request when API Request does not exist, error:", err);
|
|
81
|
-
expect(err.code).toMatch("ERR_BAD_REQUEST");
|
|
82
|
-
expect(err.response.status).toBe(404);
|
|
83
|
-
expect(err.response.statusText).toMatch("Not Found");
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
test('Request Query Ok parameter group 1', async () => {
|
|
87
|
-
try {
|
|
88
|
-
await service.addRequest(new TestRequest());
|
|
89
|
-
let response: any = await RequestAxiosCall.post(testUrl, { date: 'date' }, {
|
|
90
|
-
headers: { 'Content-Type': 'application/json', 'Origin': 'https://valid.com' }
|
|
91
|
-
});
|
|
92
|
-
expect(response.message).toMatch("Success");
|
|
93
|
-
expect(response.method).toMatch("testing");
|
|
94
|
-
expect(response.type).toMatch("get");
|
|
95
|
-
expect(response.option).toBeUndefined();
|
|
96
|
-
expect(response.x).toBeUndefined();
|
|
97
|
-
expect(response.y).toBeUndefined();
|
|
98
|
-
} catch (err: any) {
|
|
99
|
-
console.log("> Request Query Ok parameter group 1, error:", err);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
test('Request Query Ok parameter group 2', async () => {
|
|
103
|
-
try {
|
|
104
|
-
let response: any = await RequestAxiosCall.post(testUrl2, { date: 'date' });
|
|
105
|
-
expect(response.message).toMatch("Success");
|
|
106
|
-
expect(response.method).toMatch("testing");
|
|
107
|
-
expect(response.type).toBeUndefined();
|
|
108
|
-
expect(response.option).toMatch("1");
|
|
109
|
-
expect(response.x).toBeUndefined();
|
|
110
|
-
expect(response.y).toBeUndefined();
|
|
111
|
-
} catch (err: any) {
|
|
112
|
-
console.log("> Request Query Ok parameter group 2, error:", err);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
test('Request Query Ok parameter group 3', async () => {
|
|
116
|
-
try {
|
|
117
|
-
let response: any = await RequestAxiosCall.post(testUrl3, { date: 'date' });
|
|
118
|
-
expect(response.message).toMatch("Success");
|
|
119
|
-
expect(response.method).toMatch("testing");
|
|
120
|
-
expect(response.type).toBeUndefined();
|
|
121
|
-
expect(response.option).toBeUndefined();
|
|
122
|
-
expect(response.x).toMatch("10");
|
|
123
|
-
expect(response.y).toMatch("20");
|
|
124
|
-
} catch (err: any) {
|
|
125
|
-
console.log("> Request Query Ok parameter group 3, error:", err);
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
test('Request Query Ok parameter group 4', async () => {
|
|
129
|
-
try {
|
|
130
|
-
let response: any = await RequestAxiosCall.post(testUrl3, { date: 'date' })
|
|
131
|
-
expect(response.message).toMatch("Success");
|
|
132
|
-
expect(response.method).toMatch("testing");
|
|
133
|
-
expect(response.type).toBeUndefined();
|
|
134
|
-
expect(response.option).toBeUndefined();
|
|
135
|
-
expect(response.x).toMatch("10");
|
|
136
|
-
expect(response.y).toMatch("20");
|
|
137
|
-
expect(response.date).toMatch("date");
|
|
138
|
-
expect(response.time).toBeUndefined();
|
|
139
|
-
expect(response.timestamp).toBeUndefined();
|
|
140
|
-
} catch (err: any) {
|
|
141
|
-
console.log("> Request Query Ok parameter group 4, error:", err);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
test('Request Query Ok parameter group 5', async () => {
|
|
145
|
-
try {
|
|
146
|
-
let response: any = await RequestAxiosCall.post(testUrl3, { time: 'time', timestamp: 10000000 });
|
|
147
|
-
expect(response.message).toMatch("Success");
|
|
148
|
-
expect(response.method).toMatch("testing");
|
|
149
|
-
expect(response.type).toBeUndefined();
|
|
150
|
-
expect(response.option).toBeUndefined();
|
|
151
|
-
expect(response.x).toMatch("10");
|
|
152
|
-
expect(response.y).toMatch("20");
|
|
153
|
-
expect(response.date).toBeUndefined();
|
|
154
|
-
expect(response.time).toMatch("time");
|
|
155
|
-
expect(response.timestamp).toBe(10000000);
|
|
156
|
-
} catch (err: any) {
|
|
157
|
-
console.log("> Request Query Ok parameter group 5, error:", err);
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
test('Request Error: missing parameter in query', async () => {
|
|
161
|
-
try {
|
|
162
|
-
await RequestAxiosCall.post(testUrlMissingQuery, { date: 'date' });
|
|
163
|
-
} catch (err: any) {
|
|
164
|
-
//console.log("> Request Error: missing parameter in query, error:", err);
|
|
165
|
-
expect(err.code).toMatch("ERR_BAD_REQUEST");
|
|
166
|
-
expect(err.response.status).toBe(400);
|
|
167
|
-
expect(err.response.statusText).toMatch("Bad Request");
|
|
168
|
-
expect(err.response.data.status).toMatch("Error");
|
|
169
|
-
expect(err.response.data.message).toMatch("Parameters 'x', 'y' were not found in query");
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
test('Check values property', async () => {
|
|
173
|
-
try {
|
|
174
|
-
let response: any = await RequestAxiosCall.post(testUrl3, {
|
|
175
|
-
values: [{ date: 'date' }, { time: 'time', timestamp: 10000000 }]
|
|
176
|
-
});
|
|
177
|
-
expect(response.message).toMatch("Success");
|
|
178
|
-
expect(response.method).toMatch("testing");
|
|
179
|
-
expect(response.type).toBeUndefined();
|
|
180
|
-
expect(response.option).toBeUndefined();
|
|
181
|
-
expect(response.x).toMatch("10");
|
|
182
|
-
expect(response.y).toMatch("20");
|
|
183
|
-
expect(response.date).toBeUndefined();
|
|
184
|
-
expect(response.time).toBeUndefined();
|
|
185
|
-
expect(response.timestamp).toBeUndefined();
|
|
186
|
-
expect(response.values).toBeDefined();
|
|
187
|
-
expect(response.values.length).toBe(2);
|
|
188
|
-
expect(response.values[0].date).toMatch("date");
|
|
189
|
-
expect(response.values[1].time).toMatch("time");
|
|
190
|
-
expect(response.values[1].timestamp).toBe(10000000);
|
|
191
|
-
} catch (err: any) {
|
|
192
|
-
console.log("> Check values property, error:", err);
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
test('Check missing property in values', async () => {
|
|
196
|
-
try {
|
|
197
|
-
await RequestAxiosCall.post(testUrl3, {
|
|
198
|
-
values: [{ date: 'date' }, { time: 'time' }]
|
|
199
|
-
});
|
|
200
|
-
} catch (err: any) {
|
|
201
|
-
//console.log("> Check missing property in values, error:", err);
|
|
202
|
-
expect(err.code).toMatch("ERR_BAD_REQUEST");
|
|
203
|
-
expect(err.response.status).toBe(400);
|
|
204
|
-
expect(err.response.statusText).toMatch("Bad Request");
|
|
205
|
-
expect(err.response.data.status).toMatch("Error");
|
|
206
|
-
expect(err.response.data.message).toMatch("Parameters 'timestamp' were not found in body, item 2");
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
test('Check missing parameter and wrong type in values', async () => {
|
|
210
|
-
try {
|
|
211
|
-
await RequestAxiosCall.post(testUrl3, {
|
|
212
|
-
values: [{ date: 'date' }, { timestamp: 'time' }]
|
|
213
|
-
});
|
|
214
|
-
} catch (err: any) {
|
|
215
|
-
//console.log("> Check missing parameter and wrong type in values, error:", err);
|
|
216
|
-
expect(err.code).toMatch("ERR_BAD_REQUEST");
|
|
217
|
-
expect(err.response.status).toBe(400);
|
|
218
|
-
expect(err.response.statusText).toMatch("Bad Request");
|
|
219
|
-
expect(err.response.data.status).toMatch("Error");
|
|
220
|
-
expect(err.response.data.message).toMatch("Parameters 'time' were not found in body and 'timestamp' have invalid type , item 2");
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
test('Check wrong type in values', async () => {
|
|
224
|
-
try {
|
|
225
|
-
await RequestAxiosCall.post(testUrl3, {
|
|
226
|
-
values: [{ date: 'date' }, { time: 'time', timestamp: 'time' }]
|
|
227
|
-
});
|
|
228
|
-
} catch (err: any) {
|
|
229
|
-
//console.log("> Check wrong type in values, error:", err);
|
|
230
|
-
expect(err.code).toMatch("ERR_BAD_REQUEST");
|
|
231
|
-
expect(err.response.status).toBe(400);
|
|
232
|
-
expect(err.response.statusText).toMatch("Bad Request");
|
|
233
|
-
expect(err.response.data.status).toMatch("Error");
|
|
234
|
-
expect(err.response.data.message).toMatch("Parameters 'timestamp' have invalid type , item 2");
|
|
235
|
-
}
|
|
236
|
-
});
|
|
237
|
-
});
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { Request, Response } from "express";
|
|
2
|
-
import { RequestContext, PutRequest, APIService, RequestAxiosCall, RequestParameterType } from "../../../dist";
|
|
3
|
-
import { config } from "../APITestDefinitions";
|
|
4
|
-
|
|
5
|
-
const service = new APIService(config);
|
|
6
|
-
service.init();
|
|
7
|
-
|
|
8
|
-
class TestRequest extends PutRequest {
|
|
9
|
-
constructor() {
|
|
10
|
-
super({
|
|
11
|
-
path: '/test/:method/type',
|
|
12
|
-
params: [{
|
|
13
|
-
context: RequestContext.QUERY,
|
|
14
|
-
properties: [{ name: "value", type: RequestParameterType.STRING }]
|
|
15
|
-
}, {
|
|
16
|
-
context: RequestContext.QUERY,
|
|
17
|
-
properties: [{ name: "option", type: RequestParameterType.STRING }]
|
|
18
|
-
}, {
|
|
19
|
-
context: RequestContext.QUERY,
|
|
20
|
-
properties: [
|
|
21
|
-
{ name: "x", type: RequestParameterType.STRING },
|
|
22
|
-
{ name: "y", type: RequestParameterType.STRING }
|
|
23
|
-
]
|
|
24
|
-
}, {
|
|
25
|
-
context: RequestContext.PARAMS,
|
|
26
|
-
properties: [{ name: "method", type: RequestParameterType.STRING }]
|
|
27
|
-
}, {
|
|
28
|
-
context: RequestContext.BODY,
|
|
29
|
-
properties: [{ name: "date", type: RequestParameterType.STRING }]
|
|
30
|
-
}, {
|
|
31
|
-
context: RequestContext.BODY,
|
|
32
|
-
properties: [
|
|
33
|
-
{ name: "time", type: RequestParameterType.STRING },
|
|
34
|
-
{ name: "timestamp", type: RequestParameterType.STRING }
|
|
35
|
-
]
|
|
36
|
-
}]
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async apply(req: Request, res: Response): Promise<any> {
|
|
41
|
-
const { method } = req.params;
|
|
42
|
-
const { value, option, x, y } = req.query;
|
|
43
|
-
const { date, time, timestamp } = req.body;
|
|
44
|
-
return res.status(200).json({ message: "Success", method: method, type: value, option: option, date: date, time: time, x: x, y: y, timestamp: timestamp });
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
class UnexpectedErrorTestRequest extends PutRequest {
|
|
49
|
-
constructor() {
|
|
50
|
-
super({
|
|
51
|
-
path: '/test/error',
|
|
52
|
-
params: []
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async apply(req: Request, res: Response): Promise<any> {
|
|
57
|
-
throw 'Unexpected error';
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const testUrl = `http://localhost:${config.port}/test/testing/type?value=get`;
|
|
62
|
-
const testUrl2 = `http://localhost:${config.port}/test/testing/type?option=1`;
|
|
63
|
-
const testUrl3 = `http://localhost:${config.port}/test/testing/type?x=10&y=20`;
|
|
64
|
-
const testUrlMissingQuery = `http://localhost:${config.port}/test/testing/type`;
|
|
65
|
-
const testUrlUnexpectedError = `http://localhost:${config.port}/test/error`;
|
|
66
|
-
|
|
67
|
-
describe('testing PUT Request', () => {
|
|
68
|
-
beforeAll(async () => {
|
|
69
|
-
await service.run(() => { });
|
|
70
|
-
});
|
|
71
|
-
afterAll(async () => {
|
|
72
|
-
await service.close(() => { })
|
|
73
|
-
});
|
|
74
|
-
test('Refuse request when API Request does not exist', async () => {
|
|
75
|
-
expect.assertions(3);
|
|
76
|
-
return RequestAxiosCall.put(testUrl, { date: 'date' })
|
|
77
|
-
.catch(err => {
|
|
78
|
-
expect(err.code).toMatch("ERR_BAD_REQUEST");
|
|
79
|
-
expect(err.response.status).toBe(404);
|
|
80
|
-
expect(err.response.statusText).toMatch("Not Found");
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
test('Request Query Ok parameter group 1', async () => {
|
|
84
|
-
expect.assertions(6);
|
|
85
|
-
await service.addRequest(new TestRequest());
|
|
86
|
-
return RequestAxiosCall.put(testUrl, { date: 'date' })
|
|
87
|
-
.then(async (response: any) => {
|
|
88
|
-
expect(response.message).toMatch("Success");
|
|
89
|
-
expect(response.method).toMatch("testing");
|
|
90
|
-
expect(response.type).toMatch("get");
|
|
91
|
-
expect(response.option).toBeUndefined();
|
|
92
|
-
expect(response.x).toBeUndefined();
|
|
93
|
-
expect(response.y).toBeUndefined();
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
test('Request Query Ok parameter group 2', async () => {
|
|
97
|
-
expect.assertions(6);
|
|
98
|
-
await service.addRequest(new TestRequest());
|
|
99
|
-
return RequestAxiosCall.put(testUrl2, { date: 'date' })
|
|
100
|
-
.then(async (response: any) => {
|
|
101
|
-
expect(response.message).toMatch("Success");
|
|
102
|
-
expect(response.method).toMatch("testing");
|
|
103
|
-
expect(response.type).toBeUndefined();
|
|
104
|
-
expect(response.option).toMatch("1");
|
|
105
|
-
expect(response.x).toBeUndefined();
|
|
106
|
-
expect(response.y).toBeUndefined();
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
test('Request Query Ok parameter group 3', async () => {
|
|
110
|
-
expect.assertions(6);
|
|
111
|
-
await service.addRequest(new TestRequest());
|
|
112
|
-
return RequestAxiosCall.put(testUrl3, { date: 'date' })
|
|
113
|
-
.then(async (response: any) => {
|
|
114
|
-
expect(response.message).toMatch("Success");
|
|
115
|
-
expect(response.method).toMatch("testing");
|
|
116
|
-
expect(response.type).toBeUndefined();
|
|
117
|
-
expect(response.option).toBeUndefined();
|
|
118
|
-
expect(response.x).toMatch("10");
|
|
119
|
-
expect(response.y).toMatch("20");
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
test('Request Query Ok parameter group 4', async () => {
|
|
123
|
-
expect.assertions(9);
|
|
124
|
-
await service.addRequest(new TestRequest());
|
|
125
|
-
return RequestAxiosCall.put(testUrl3, { date: 'date' })
|
|
126
|
-
.then(async (response: any) => {
|
|
127
|
-
expect(response.message).toMatch("Success");
|
|
128
|
-
expect(response.method).toMatch("testing");
|
|
129
|
-
expect(response.type).toBeUndefined();
|
|
130
|
-
expect(response.option).toBeUndefined();
|
|
131
|
-
expect(response.x).toMatch("10");
|
|
132
|
-
expect(response.y).toMatch("20");
|
|
133
|
-
expect(response.date).toMatch("date");
|
|
134
|
-
expect(response.time).toBeUndefined();
|
|
135
|
-
expect(response.timestamp).toBeUndefined();
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
test('Request Query Ok parameter group 5', async () => {
|
|
139
|
-
expect.assertions(9);
|
|
140
|
-
await service.addRequest(new TestRequest());
|
|
141
|
-
return RequestAxiosCall.put(testUrl3, { time: 'time', timestamp: 'timestamp' })
|
|
142
|
-
.then(async (response: any) => {
|
|
143
|
-
expect(response.message).toMatch("Success");
|
|
144
|
-
expect(response.method).toMatch("testing");
|
|
145
|
-
expect(response.type).toBeUndefined();
|
|
146
|
-
expect(response.option).toBeUndefined();
|
|
147
|
-
expect(response.x).toMatch("10");
|
|
148
|
-
expect(response.y).toMatch("20");
|
|
149
|
-
expect(response.date).toBeUndefined();
|
|
150
|
-
expect(response.time).toMatch("time");
|
|
151
|
-
expect(response.timestamp).toMatch("timestamp");
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
test('Request Error: missing parameter in query', async () => {
|
|
155
|
-
expect.assertions(5);
|
|
156
|
-
service.addRequest(new TestRequest());
|
|
157
|
-
return RequestAxiosCall.put(testUrlMissingQuery, { property: 'body' })
|
|
158
|
-
.catch(async err => {
|
|
159
|
-
expect(err.code).toMatch("ERR_BAD_REQUEST");
|
|
160
|
-
expect(err.response.status).toBe(400);
|
|
161
|
-
expect(err.response.statusText).toMatch("Bad Request");
|
|
162
|
-
expect(err.response.data.status).toMatch("Error");
|
|
163
|
-
expect(err.response.data.message).toMatch("Parameters 'x', 'y' were not found in query");
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
});
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { MongooseModelManager } from "../../../dist";
|
|
2
|
-
import { MongoMemoryServer } from 'mongodb-memory-server';
|
|
3
|
-
import mongoose, { connect, disconnect } from "mongoose";
|
|
4
|
-
|
|
5
|
-
mongoose.set('strictQuery', false);
|
|
6
|
-
|
|
7
|
-
interface TestValue {
|
|
8
|
-
value: string
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
interface Test {
|
|
12
|
-
testId: number,
|
|
13
|
-
name: string,
|
|
14
|
-
values: TestValue[]
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
class TestManager extends MongooseModelManager<Test> {
|
|
18
|
-
constructor() {
|
|
19
|
-
super("test", {
|
|
20
|
-
testId: { type: Number, required: true },
|
|
21
|
-
name: { type: String, required: true },
|
|
22
|
-
values: {
|
|
23
|
-
type: [{
|
|
24
|
-
value: { type: String, required: true }
|
|
25
|
-
}],
|
|
26
|
-
required: true
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const manager = new TestManager();
|
|
33
|
-
let mongodb: MongoMemoryServer | undefined = undefined;
|
|
34
|
-
|
|
35
|
-
describe("> Testing Mongoose Model Manager", () => {
|
|
36
|
-
beforeAll(async() => {
|
|
37
|
-
mongodb = await MongoMemoryServer.create();
|
|
38
|
-
let url = await mongodb?.getUri() || "NONE";
|
|
39
|
-
await connect(url);
|
|
40
|
-
});
|
|
41
|
-
afterAll(async() => {
|
|
42
|
-
await disconnect();
|
|
43
|
-
await mongodb?.stop();
|
|
44
|
-
});
|
|
45
|
-
test("> Create", async() => {
|
|
46
|
-
let token: any = await manager.create({
|
|
47
|
-
name: 'test1',
|
|
48
|
-
testId: 1,
|
|
49
|
-
values: [{ value: 'value1' }]
|
|
50
|
-
});
|
|
51
|
-
expect(token.name).toMatch('test1');
|
|
52
|
-
expect(token.testId).toBe(1);
|
|
53
|
-
});
|
|
54
|
-
test("> Create Many", async() => {
|
|
55
|
-
let result = await manager.createMany([{
|
|
56
|
-
name: 'test2',
|
|
57
|
-
testId: 2,
|
|
58
|
-
values: [{ value: 'value2' }]
|
|
59
|
-
}, {
|
|
60
|
-
name: 'test3',
|
|
61
|
-
testId: 3,
|
|
62
|
-
values: [{ value: 'value3' }]
|
|
63
|
-
}]);
|
|
64
|
-
expect(result.insertedCount).toBe(2);
|
|
65
|
-
});
|
|
66
|
-
test("> Exists", async() => {
|
|
67
|
-
let result = await manager.exists({ testId: 2 });
|
|
68
|
-
expect(result).toBeDefined();
|
|
69
|
-
result = await manager.exists({ testId: 4 });
|
|
70
|
-
expect(result).toBeNull();
|
|
71
|
-
});
|
|
72
|
-
test("> Find", async() => {
|
|
73
|
-
let token: any = await manager.find({ testId: 1 });
|
|
74
|
-
expect(token.name).toMatch('test1');
|
|
75
|
-
expect(token.testId).toBe(1);
|
|
76
|
-
});
|
|
77
|
-
test("> Find Many", async() => {
|
|
78
|
-
let tokens: any[] = await manager.findMany({
|
|
79
|
-
testId: { $gt: 1 }
|
|
80
|
-
});
|
|
81
|
-
expect(tokens.length).toBe(2);
|
|
82
|
-
expect(tokens[0].name).toMatch('test2');
|
|
83
|
-
expect(tokens[0].testId).toBe(2);
|
|
84
|
-
expect(tokens[1].name).toMatch('test3');
|
|
85
|
-
expect(tokens[1].testId).toBe(3);
|
|
86
|
-
});
|
|
87
|
-
test("> Batch", async() => {
|
|
88
|
-
let tokens: any[] = await manager.batch({}, 1, 2);
|
|
89
|
-
expect(tokens.length).toBe(2);
|
|
90
|
-
expect(tokens[0].name).toMatch('test2');
|
|
91
|
-
expect(tokens[0].testId).toBe(2);
|
|
92
|
-
expect(tokens[1].name).toMatch('test3');
|
|
93
|
-
expect(tokens[1].testId).toBe(3);
|
|
94
|
-
});
|
|
95
|
-
test("Bulk Write", async() => {
|
|
96
|
-
await manager.bulkWrite([{
|
|
97
|
-
updateOne: {
|
|
98
|
-
filter: { testId: 1 },
|
|
99
|
-
update: { name: 'test_1' },
|
|
100
|
-
}
|
|
101
|
-
}, {
|
|
102
|
-
insertOne: {
|
|
103
|
-
document: {
|
|
104
|
-
name: 'test4',
|
|
105
|
-
testId: 4,
|
|
106
|
-
values: [{ value: 'value4' }]
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}, {
|
|
110
|
-
deleteOne: {
|
|
111
|
-
filter: { testId: 2 }
|
|
112
|
-
}
|
|
113
|
-
}]);
|
|
114
|
-
let update = await manager.find({ testId: 1 });
|
|
115
|
-
expect(update?.name).toMatch('test_1');
|
|
116
|
-
let insertion = await manager.find({ testId: 4 });
|
|
117
|
-
expect(insertion?.name).toMatch('test4');
|
|
118
|
-
let deletion = await manager.find({ testId: 2 });
|
|
119
|
-
expect(deletion).toBeNull();
|
|
120
|
-
});
|
|
121
|
-
test("> Count Documents", async() => {
|
|
122
|
-
expect(await manager.countDocuments({
|
|
123
|
-
testId: { $gt: 1 }
|
|
124
|
-
})).toBe(2);
|
|
125
|
-
});
|
|
126
|
-
test("> Delete", async() => {
|
|
127
|
-
let deletion = await manager.delete({ testId: 1 });
|
|
128
|
-
expect(deletion.deletedCount).toBe(1);
|
|
129
|
-
expect(await manager.countDocuments({})).toBe(2);
|
|
130
|
-
expect(await manager.find({ testId: 1 })).toBeNull();
|
|
131
|
-
});
|
|
132
|
-
test("> Delete Many", async() => {
|
|
133
|
-
let deletion = await manager.deleteMany({ testId: { $gt: 1 } });
|
|
134
|
-
expect(deletion.deletedCount).toBe(2);
|
|
135
|
-
expect(await manager.countDocuments({})).toBe(0);
|
|
136
|
-
expect(await manager.find({ testId: 3 })).toBeNull();
|
|
137
|
-
expect(await manager.find({ testId: 4 })).toBeNull();
|
|
138
|
-
});
|
|
139
|
-
});
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { SequelizeConnection } from '../../../dist';
|
|
2
|
-
import { config } from './SequealizeDefinitions';
|
|
3
|
-
import { DataTypes } from '@sequelize/core';
|
|
4
|
-
|
|
5
|
-
const validConnection = new SequelizeConnection(config);
|
|
6
|
-
|
|
7
|
-
describe("Testing Sequalize Connection", () => {
|
|
8
|
-
test("Connect OK", async () => {
|
|
9
|
-
expect(await validConnection.connect()).toBeUndefined();
|
|
10
|
-
});
|
|
11
|
-
test("Define Model", async () => {
|
|
12
|
-
let model = await validConnection.define('Test', {
|
|
13
|
-
testId: {
|
|
14
|
-
type: DataTypes.INTEGER,
|
|
15
|
-
allowNull: false
|
|
16
|
-
},
|
|
17
|
-
name: {
|
|
18
|
-
type: DataTypes.STRING,
|
|
19
|
-
allowNull: false
|
|
20
|
-
}
|
|
21
|
-
}, {
|
|
22
|
-
tableName: 'Tests'
|
|
23
|
-
});
|
|
24
|
-
expect(model.name).toMatch('Test');
|
|
25
|
-
expect(model.tableName).toMatch('Tests');
|
|
26
|
-
});
|
|
27
|
-
test("Disconnect OK", async () => {
|
|
28
|
-
expect(await validConnection.disconnect()).toBeUndefined();
|
|
29
|
-
});
|
|
30
|
-
});
|