@nestia/e2e 0.3.2 → 0.3.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/lib/ArrayUtil.d.ts +15 -15
- package/lib/ArrayUtil.js +226 -226
- package/lib/ArrayUtil.js.map +1 -1
- package/lib/DynamicExecutor.d.ts +137 -137
- package/lib/DynamicExecutor.js +355 -356
- package/lib/DynamicExecutor.js.map +1 -1
- package/lib/GaffComparator.d.ts +33 -33
- package/lib/GaffComparator.js +67 -67
- package/lib/GaffComparator.js.map +1 -1
- package/lib/RandomGenerator.d.ts +82 -82
- package/lib/RandomGenerator.js +173 -173
- package/lib/RandomGenerator.js.map +1 -1
- package/lib/StopWatch.d.ts +24 -24
- package/lib/StopWatch.js +88 -88
- package/lib/StopWatch.js.map +1 -1
- package/lib/TestValidator.d.ts +88 -87
- package/lib/TestValidator.js +382 -380
- package/lib/TestValidator.js.map +1 -1
- package/lib/index.d.ts +3 -3
- package/lib/index.js +31 -31
- package/lib/internal/json_equal_to.d.ts +1 -1
- package/lib/internal/json_equal_to.js +72 -35
- package/lib/internal/json_equal_to.js.map +1 -1
- package/lib/module.d.ts +6 -6
- package/lib/module.js +22 -22
- package/package.json +4 -4
- package/src/TestValidator.ts +3 -2
- package/src/internal/json_equal_to.ts +35 -36
package/lib/TestValidator.js
CHANGED
|
@@ -1,381 +1,383 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __values = (this && this.__values) || function(o) {
|
|
39
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
40
|
-
if (m) return m.call(o);
|
|
41
|
-
if (o && typeof o.length === "number") return {
|
|
42
|
-
next: function () {
|
|
43
|
-
if (o && i >= o.length) o = void 0;
|
|
44
|
-
return { value: o && o[i++], done: !o };
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
48
|
-
};
|
|
49
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.TestValidator = void 0;
|
|
51
|
-
var ranges_1 = require("tstl/ranges");
|
|
52
|
-
var RandomGenerator_1 = require("./RandomGenerator");
|
|
53
|
-
var json_equal_to_1 = require("./internal/json_equal_to");
|
|
54
|
-
/**
|
|
55
|
-
* Test validator.
|
|
56
|
-
*
|
|
57
|
-
* `TestValidator` is a collection gathering E2E validation functions.
|
|
58
|
-
*
|
|
59
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
60
|
-
*/
|
|
61
|
-
var TestValidator;
|
|
62
|
-
(function (TestValidator) {
|
|
63
|
-
var _this = this;
|
|
64
|
-
/**
|
|
65
|
-
* Test whether condition is satisfied.
|
|
66
|
-
*
|
|
67
|
-
* @param title Title of error message when condition is not satisfied
|
|
68
|
-
* @return Currying function
|
|
69
|
-
*/
|
|
70
|
-
TestValidator.predicate = function (title) {
|
|
71
|
-
return function (condition) {
|
|
72
|
-
var message = function () {
|
|
73
|
-
return "Bug on ".concat(title, ": expected condition is not satisfied.");
|
|
74
|
-
};
|
|
75
|
-
// SCALAR
|
|
76
|
-
if (typeof condition === "boolean") {
|
|
77
|
-
if (condition !== true)
|
|
78
|
-
throw new Error(message());
|
|
79
|
-
return undefined;
|
|
80
|
-
}
|
|
81
|
-
// CLOSURE
|
|
82
|
-
var output = condition();
|
|
83
|
-
if (typeof output === "boolean") {
|
|
84
|
-
if (output !== true)
|
|
85
|
-
throw new Error(message());
|
|
86
|
-
return undefined;
|
|
87
|
-
}
|
|
88
|
-
// ASYNCHRONOUS
|
|
89
|
-
return new Promise(function (resolve, reject) {
|
|
90
|
-
output
|
|
91
|
-
.then(function (flag) {
|
|
92
|
-
if (flag === true)
|
|
93
|
-
resolve();
|
|
94
|
-
else
|
|
95
|
-
reject(message());
|
|
96
|
-
})
|
|
97
|
-
.catch(reject);
|
|
98
|
-
});
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
/**
|
|
102
|
-
* Test whether two values are equal.
|
|
103
|
-
*
|
|
104
|
-
* If you want to validate `covers` relationship,
|
|
105
|
-
* call smaller first and then larger.
|
|
106
|
-
*
|
|
107
|
-
* Otherwise you wanna non equals validator, combine with {@link error}.
|
|
108
|
-
*
|
|
109
|
-
* @param title Title of error message when different
|
|
110
|
-
* @
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
* @
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
* @
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
_b.
|
|
279
|
-
|
|
280
|
-
_b.
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
return [
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
function
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __values = (this && this.__values) || function(o) {
|
|
39
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
40
|
+
if (m) return m.call(o);
|
|
41
|
+
if (o && typeof o.length === "number") return {
|
|
42
|
+
next: function () {
|
|
43
|
+
if (o && i >= o.length) o = void 0;
|
|
44
|
+
return { value: o && o[i++], done: !o };
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.TestValidator = void 0;
|
|
51
|
+
var ranges_1 = require("tstl/ranges");
|
|
52
|
+
var RandomGenerator_1 = require("./RandomGenerator");
|
|
53
|
+
var json_equal_to_1 = require("./internal/json_equal_to");
|
|
54
|
+
/**
|
|
55
|
+
* Test validator.
|
|
56
|
+
*
|
|
57
|
+
* `TestValidator` is a collection gathering E2E validation functions.
|
|
58
|
+
*
|
|
59
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
60
|
+
*/
|
|
61
|
+
var TestValidator;
|
|
62
|
+
(function (TestValidator) {
|
|
63
|
+
var _this = this;
|
|
64
|
+
/**
|
|
65
|
+
* Test whether condition is satisfied.
|
|
66
|
+
*
|
|
67
|
+
* @param title Title of error message when condition is not satisfied
|
|
68
|
+
* @return Currying function
|
|
69
|
+
*/
|
|
70
|
+
TestValidator.predicate = function (title) {
|
|
71
|
+
return function (condition) {
|
|
72
|
+
var message = function () {
|
|
73
|
+
return "Bug on ".concat(title, ": expected condition is not satisfied.");
|
|
74
|
+
};
|
|
75
|
+
// SCALAR
|
|
76
|
+
if (typeof condition === "boolean") {
|
|
77
|
+
if (condition !== true)
|
|
78
|
+
throw new Error(message());
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
// CLOSURE
|
|
82
|
+
var output = condition();
|
|
83
|
+
if (typeof output === "boolean") {
|
|
84
|
+
if (output !== true)
|
|
85
|
+
throw new Error(message());
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
// ASYNCHRONOUS
|
|
89
|
+
return new Promise(function (resolve, reject) {
|
|
90
|
+
output
|
|
91
|
+
.then(function (flag) {
|
|
92
|
+
if (flag === true)
|
|
93
|
+
resolve();
|
|
94
|
+
else
|
|
95
|
+
reject(message());
|
|
96
|
+
})
|
|
97
|
+
.catch(reject);
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Test whether two values are equal.
|
|
103
|
+
*
|
|
104
|
+
* If you want to validate `covers` relationship,
|
|
105
|
+
* call smaller first and then larger.
|
|
106
|
+
*
|
|
107
|
+
* Otherwise you wanna non equals validator, combine with {@link error}.
|
|
108
|
+
*
|
|
109
|
+
* @param title Title of error message when different
|
|
110
|
+
* @param exception Exception filter for ignoring some keys
|
|
111
|
+
* @returns Currying function
|
|
112
|
+
*/
|
|
113
|
+
TestValidator.equals = function (title, exception) {
|
|
114
|
+
if (exception === void 0) { exception = function () { return false; }; }
|
|
115
|
+
return function (x) {
|
|
116
|
+
return function (y) {
|
|
117
|
+
var diff = (0, json_equal_to_1.json_equal_to)(exception)(x)(y);
|
|
118
|
+
if (diff.length)
|
|
119
|
+
throw new Error("Bug on ".concat(title, ": found different values - [").concat(diff.join(", "), "]"));
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Test whether error occurs.
|
|
125
|
+
*
|
|
126
|
+
* If error occurs, nothing would be happened.
|
|
127
|
+
*
|
|
128
|
+
* However, no error exists, then exception would be thrown.
|
|
129
|
+
*
|
|
130
|
+
* @param title Title of exception because of no error exists
|
|
131
|
+
*/
|
|
132
|
+
TestValidator.error = function (title) {
|
|
133
|
+
return function (task) {
|
|
134
|
+
var message = function () { return "Bug on ".concat(title, ": exception must be thrown."); };
|
|
135
|
+
try {
|
|
136
|
+
var output_1 = task();
|
|
137
|
+
if (is_promise(output_1))
|
|
138
|
+
return new Promise(function (resolve, reject) {
|
|
139
|
+
return output_1
|
|
140
|
+
.catch(function () { return resolve(); })
|
|
141
|
+
.then(function () { return reject(message()); });
|
|
142
|
+
});
|
|
143
|
+
else
|
|
144
|
+
throw new Error(message());
|
|
145
|
+
}
|
|
146
|
+
catch (_a) {
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
TestValidator.httpError = function (title) {
|
|
152
|
+
return function (status) {
|
|
153
|
+
return function (task) {
|
|
154
|
+
var message = function (actual) {
|
|
155
|
+
return typeof actual === "number"
|
|
156
|
+
? "Bug on ".concat(title, ": status code must be ").concat(status, ", but ").concat(actual, ".")
|
|
157
|
+
: "Bug on ".concat(title, ": status code must be ").concat(status, ", but succeeded.");
|
|
158
|
+
};
|
|
159
|
+
var predicate = function (exp) {
|
|
160
|
+
return typeof exp === "object" &&
|
|
161
|
+
exp.constructor.name === "HttpError" &&
|
|
162
|
+
exp.status === status
|
|
163
|
+
? null
|
|
164
|
+
: new Error(message(typeof exp === "object" &&
|
|
165
|
+
exp.constructor.name === "HttpError"
|
|
166
|
+
? exp.status
|
|
167
|
+
: undefined));
|
|
168
|
+
};
|
|
169
|
+
try {
|
|
170
|
+
var output_2 = task();
|
|
171
|
+
if (is_promise(output_2))
|
|
172
|
+
return new Promise(function (resolve, reject) {
|
|
173
|
+
return output_2
|
|
174
|
+
.catch(function (exp) {
|
|
175
|
+
var res = predicate(exp);
|
|
176
|
+
if (res)
|
|
177
|
+
reject(res);
|
|
178
|
+
else
|
|
179
|
+
resolve();
|
|
180
|
+
})
|
|
181
|
+
.then(function () { return reject(new Error(message())); });
|
|
182
|
+
});
|
|
183
|
+
else
|
|
184
|
+
throw new Error(message());
|
|
185
|
+
}
|
|
186
|
+
catch (exp) {
|
|
187
|
+
var res = predicate(exp);
|
|
188
|
+
if (res)
|
|
189
|
+
throw res;
|
|
190
|
+
return undefined;
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
/**
|
|
196
|
+
* Validate index API.
|
|
197
|
+
*
|
|
198
|
+
* Test whether two indexed values are equal.
|
|
199
|
+
*
|
|
200
|
+
* If two values are different, then exception would be thrown.
|
|
201
|
+
*
|
|
202
|
+
* @param title Title of error message when different
|
|
203
|
+
* @return Currying function
|
|
204
|
+
*
|
|
205
|
+
* @example https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_search.ts
|
|
206
|
+
*/
|
|
207
|
+
TestValidator.index = function (title) {
|
|
208
|
+
return function (expected) {
|
|
209
|
+
return function (gotten, trace) {
|
|
210
|
+
if (trace === void 0) { trace = true; }
|
|
211
|
+
var length = Math.min(expected.length, gotten.length);
|
|
212
|
+
expected = expected.slice(0, length);
|
|
213
|
+
gotten = gotten.slice(0, length);
|
|
214
|
+
var xIds = get_ids(expected).slice(0, length);
|
|
215
|
+
var yIds = get_ids(gotten)
|
|
216
|
+
.filter(function (id) { return id >= xIds[0]; })
|
|
217
|
+
.slice(0, length);
|
|
218
|
+
var equals = xIds.every(function (x, i) { return x === yIds[i]; });
|
|
219
|
+
if (equals === true)
|
|
220
|
+
return;
|
|
221
|
+
else if (trace === true)
|
|
222
|
+
console.log({
|
|
223
|
+
expected: xIds,
|
|
224
|
+
gotten: yIds,
|
|
225
|
+
});
|
|
226
|
+
throw new Error("Bug on ".concat(title, ": result of the index is different with manual aggregation."));
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
};
|
|
230
|
+
/**
|
|
231
|
+
* Valiate search options.
|
|
232
|
+
*
|
|
233
|
+
* Test a pagination API supporting search options.
|
|
234
|
+
*
|
|
235
|
+
* @param title Title of error message when searching is invalid
|
|
236
|
+
* @returns Currying function
|
|
237
|
+
*
|
|
238
|
+
* @example https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_search.ts
|
|
239
|
+
*/
|
|
240
|
+
TestValidator.search = function (title) {
|
|
241
|
+
/**
|
|
242
|
+
* @param getter A pagination API function to be called
|
|
243
|
+
*/
|
|
244
|
+
return function (getter) {
|
|
245
|
+
/**
|
|
246
|
+
* @param total Total entity records for comparison
|
|
247
|
+
* @param sampleCount Sampling count. Default is 1
|
|
248
|
+
*/
|
|
249
|
+
return function (total, sampleCount) {
|
|
250
|
+
if (sampleCount === void 0) { sampleCount = 1; }
|
|
251
|
+
/**
|
|
252
|
+
* @param props Search properties
|
|
253
|
+
*/
|
|
254
|
+
return function (props) { return __awaiter(_this, void 0, void 0, function () {
|
|
255
|
+
var samples, _loop_1, samples_1, samples_1_1, s, e_1_1;
|
|
256
|
+
var e_1, _a;
|
|
257
|
+
return __generator(this, function (_b) {
|
|
258
|
+
switch (_b.label) {
|
|
259
|
+
case 0:
|
|
260
|
+
samples = RandomGenerator_1.RandomGenerator.sample(total)(sampleCount);
|
|
261
|
+
_loop_1 = function (s) {
|
|
262
|
+
var values, filtered, gotten;
|
|
263
|
+
return __generator(this, function (_c) {
|
|
264
|
+
switch (_c.label) {
|
|
265
|
+
case 0:
|
|
266
|
+
values = props.values(s);
|
|
267
|
+
filtered = total.filter(function (entity) {
|
|
268
|
+
return props.filter(entity, values);
|
|
269
|
+
});
|
|
270
|
+
return [4 /*yield*/, getter(props.request(values))];
|
|
271
|
+
case 1:
|
|
272
|
+
gotten = _c.sent();
|
|
273
|
+
TestValidator.index("".concat(title, " (").concat(props.fields.join(", "), ")"))(filtered)(gotten);
|
|
274
|
+
return [2 /*return*/];
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
};
|
|
278
|
+
_b.label = 1;
|
|
279
|
+
case 1:
|
|
280
|
+
_b.trys.push([1, 6, 7, 8]);
|
|
281
|
+
samples_1 = __values(samples), samples_1_1 = samples_1.next();
|
|
282
|
+
_b.label = 2;
|
|
283
|
+
case 2:
|
|
284
|
+
if (!!samples_1_1.done) return [3 /*break*/, 5];
|
|
285
|
+
s = samples_1_1.value;
|
|
286
|
+
return [5 /*yield**/, _loop_1(s)];
|
|
287
|
+
case 3:
|
|
288
|
+
_b.sent();
|
|
289
|
+
_b.label = 4;
|
|
290
|
+
case 4:
|
|
291
|
+
samples_1_1 = samples_1.next();
|
|
292
|
+
return [3 /*break*/, 2];
|
|
293
|
+
case 5: return [3 /*break*/, 8];
|
|
294
|
+
case 6:
|
|
295
|
+
e_1_1 = _b.sent();
|
|
296
|
+
e_1 = { error: e_1_1 };
|
|
297
|
+
return [3 /*break*/, 8];
|
|
298
|
+
case 7:
|
|
299
|
+
try {
|
|
300
|
+
if (samples_1_1 && !samples_1_1.done && (_a = samples_1.return)) _a.call(samples_1);
|
|
301
|
+
}
|
|
302
|
+
finally { if (e_1) throw e_1.error; }
|
|
303
|
+
return [7 /*endfinally*/];
|
|
304
|
+
case 8: return [2 /*return*/];
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
}); };
|
|
308
|
+
};
|
|
309
|
+
};
|
|
310
|
+
};
|
|
311
|
+
/**
|
|
312
|
+
* Validate sorting options.
|
|
313
|
+
*
|
|
314
|
+
* Test a pagination API supporting sorting options.
|
|
315
|
+
*
|
|
316
|
+
* You can validate detailed sorting options both asceding and descending orders
|
|
317
|
+
* with multiple fields. However, as it forms a complicate currying function,
|
|
318
|
+
* I recomend you to see below example code before using.
|
|
319
|
+
*
|
|
320
|
+
* @param title Title of error message when sorting is invalid
|
|
321
|
+
* @example https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_sort.ts
|
|
322
|
+
*/
|
|
323
|
+
TestValidator.sort = function (title) {
|
|
324
|
+
/**
|
|
325
|
+
* @param getter A pagination API function to be called
|
|
326
|
+
*/
|
|
327
|
+
return function (getter) {
|
|
328
|
+
/**
|
|
329
|
+
* @param fields List of fields to be sorted
|
|
330
|
+
*/
|
|
331
|
+
return function () {
|
|
332
|
+
var fields = [];
|
|
333
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
334
|
+
fields[_i] = arguments[_i];
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* @param comp Comparator function for validation
|
|
338
|
+
* @param filter Filter function for data if required
|
|
339
|
+
*/
|
|
340
|
+
return function (comp, filter) {
|
|
341
|
+
/**
|
|
342
|
+
* @param direction "+" means ascending order, and "-" means descending order
|
|
343
|
+
*/
|
|
344
|
+
return function (direction, trace) {
|
|
345
|
+
if (trace === void 0) { trace = true; }
|
|
346
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
347
|
+
var data, reversed;
|
|
348
|
+
return __generator(this, function (_a) {
|
|
349
|
+
switch (_a.label) {
|
|
350
|
+
case 0: return [4 /*yield*/, getter(fields.map(function (field) { return "".concat(direction).concat(field); }))];
|
|
351
|
+
case 1:
|
|
352
|
+
data = _a.sent();
|
|
353
|
+
if (filter)
|
|
354
|
+
data = data.filter(filter);
|
|
355
|
+
reversed = direction === "+" ? comp : function (x, y) { return comp(y, x); };
|
|
356
|
+
if ((0, ranges_1.is_sorted)(data, function (x, y) { return reversed(x, y) < 0; }) === false) {
|
|
357
|
+
if (fields.length === 1 &&
|
|
358
|
+
data.length &&
|
|
359
|
+
data[0][fields[0]] !== undefined &&
|
|
360
|
+
trace)
|
|
361
|
+
console.log(data.map(function (elem) { return elem[fields[0]]; }));
|
|
362
|
+
throw new Error("Bug on ".concat(title, ": wrong sorting on ").concat(direction, "(").concat(fields.join(", "), ")."));
|
|
363
|
+
}
|
|
364
|
+
return [2 /*return*/];
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
};
|
|
369
|
+
};
|
|
370
|
+
};
|
|
371
|
+
};
|
|
372
|
+
};
|
|
373
|
+
})(TestValidator || (exports.TestValidator = TestValidator = {}));
|
|
374
|
+
function get_ids(entities) {
|
|
375
|
+
return entities.map(function (entity) { return entity.id; }).sort(function (x, y) { return (x < y ? -1 : 1); });
|
|
376
|
+
}
|
|
377
|
+
function is_promise(input) {
|
|
378
|
+
return (typeof input === "object" &&
|
|
379
|
+
input !== null &&
|
|
380
|
+
typeof input.then === "function" &&
|
|
381
|
+
typeof input.catch === "function");
|
|
382
|
+
}
|
|
381
383
|
//# sourceMappingURL=TestValidator.js.map
|