@nestia/e2e 0.3.2 → 0.3.4

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.
@@ -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
- * @returns Currying function
111
- */
112
- TestValidator.equals = function (title) {
113
- return function (x) {
114
- return function (y) {
115
- var diff = (0, json_equal_to_1.json_equal_to)(x, y);
116
- if (diff.length)
117
- throw new Error("Bug on ".concat(title, ": found different values - [").concat(diff.join(", "), "]"));
118
- };
119
- };
120
- };
121
- /**
122
- * Test whether error occurs.
123
- *
124
- * If error occurs, nothing would be happened.
125
- *
126
- * However, no error exists, then exception would be thrown.
127
- *
128
- * @param title Title of exception because of no error exists
129
- */
130
- TestValidator.error = function (title) {
131
- return function (task) {
132
- var message = function () { return "Bug on ".concat(title, ": exception must be thrown."); };
133
- try {
134
- var output_1 = task();
135
- if (is_promise(output_1))
136
- return new Promise(function (resolve, reject) {
137
- return output_1
138
- .catch(function () { return resolve(); })
139
- .then(function () { return reject(message()); });
140
- });
141
- else
142
- throw new Error(message());
143
- }
144
- catch (_a) {
145
- return undefined;
146
- }
147
- };
148
- };
149
- TestValidator.httpError = function (title) {
150
- return function (status) {
151
- return function (task) {
152
- var message = function (actual) {
153
- return typeof actual === "number"
154
- ? "Bug on ".concat(title, ": status code must be ").concat(status, ", but ").concat(actual, ".")
155
- : "Bug on ".concat(title, ": status code must be ").concat(status, ", but succeeded.");
156
- };
157
- var predicate = function (exp) {
158
- return typeof exp === "object" &&
159
- exp.constructor.name === "HttpError" &&
160
- exp.status === status
161
- ? null
162
- : new Error(message(typeof exp === "object" &&
163
- exp.constructor.name === "HttpError"
164
- ? exp.status
165
- : undefined));
166
- };
167
- try {
168
- var output_2 = task();
169
- if (is_promise(output_2))
170
- return new Promise(function (resolve, reject) {
171
- return output_2
172
- .catch(function (exp) {
173
- var res = predicate(exp);
174
- if (res)
175
- reject(res);
176
- else
177
- resolve();
178
- })
179
- .then(function () { return reject(new Error(message())); });
180
- });
181
- else
182
- throw new Error(message());
183
- }
184
- catch (exp) {
185
- var res = predicate(exp);
186
- if (res)
187
- throw res;
188
- return undefined;
189
- }
190
- };
191
- };
192
- };
193
- /**
194
- * Validate index API.
195
- *
196
- * Test whether two indexed values are equal.
197
- *
198
- * If two values are different, then exception would be thrown.
199
- *
200
- * @param title Title of error message when different
201
- * @return Currying function
202
- *
203
- * @example https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_search.ts
204
- */
205
- TestValidator.index = function (title) {
206
- return function (expected) {
207
- return function (gotten, trace) {
208
- if (trace === void 0) { trace = true; }
209
- var length = Math.min(expected.length, gotten.length);
210
- expected = expected.slice(0, length);
211
- gotten = gotten.slice(0, length);
212
- var xIds = get_ids(expected).slice(0, length);
213
- var yIds = get_ids(gotten)
214
- .filter(function (id) { return id >= xIds[0]; })
215
- .slice(0, length);
216
- var equals = xIds.every(function (x, i) { return x === yIds[i]; });
217
- if (equals === true)
218
- return;
219
- else if (trace === true)
220
- console.log({
221
- expected: xIds,
222
- gotten: yIds,
223
- });
224
- throw new Error("Bug on ".concat(title, ": result of the index is different with manual aggregation."));
225
- };
226
- };
227
- };
228
- /**
229
- * Valiate search options.
230
- *
231
- * Test a pagination API supporting search options.
232
- *
233
- * @param title Title of error message when searching is invalid
234
- * @returns Currying function
235
- *
236
- * @example https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_search.ts
237
- */
238
- TestValidator.search = function (title) {
239
- /**
240
- * @param getter A pagination API function to be called
241
- */
242
- return function (getter) {
243
- /**
244
- * @param total Total entity records for comparison
245
- * @param sampleCount Sampling count. Default is 1
246
- */
247
- return function (total, sampleCount) {
248
- if (sampleCount === void 0) { sampleCount = 1; }
249
- /**
250
- * @param props Search properties
251
- */
252
- return function (props) { return __awaiter(_this, void 0, void 0, function () {
253
- var samples, _loop_1, samples_1, samples_1_1, s, e_1_1;
254
- var e_1, _a;
255
- return __generator(this, function (_b) {
256
- switch (_b.label) {
257
- case 0:
258
- samples = RandomGenerator_1.RandomGenerator.sample(total)(sampleCount);
259
- _loop_1 = function (s) {
260
- var values, filtered, gotten;
261
- return __generator(this, function (_c) {
262
- switch (_c.label) {
263
- case 0:
264
- values = props.values(s);
265
- filtered = total.filter(function (entity) {
266
- return props.filter(entity, values);
267
- });
268
- return [4 /*yield*/, getter(props.request(values))];
269
- case 1:
270
- gotten = _c.sent();
271
- TestValidator.index("".concat(title, " (").concat(props.fields.join(", "), ")"))(filtered)(gotten);
272
- return [2 /*return*/];
273
- }
274
- });
275
- };
276
- _b.label = 1;
277
- case 1:
278
- _b.trys.push([1, 6, 7, 8]);
279
- samples_1 = __values(samples), samples_1_1 = samples_1.next();
280
- _b.label = 2;
281
- case 2:
282
- if (!!samples_1_1.done) return [3 /*break*/, 5];
283
- s = samples_1_1.value;
284
- return [5 /*yield**/, _loop_1(s)];
285
- case 3:
286
- _b.sent();
287
- _b.label = 4;
288
- case 4:
289
- samples_1_1 = samples_1.next();
290
- return [3 /*break*/, 2];
291
- case 5: return [3 /*break*/, 8];
292
- case 6:
293
- e_1_1 = _b.sent();
294
- e_1 = { error: e_1_1 };
295
- return [3 /*break*/, 8];
296
- case 7:
297
- try {
298
- if (samples_1_1 && !samples_1_1.done && (_a = samples_1.return)) _a.call(samples_1);
299
- }
300
- finally { if (e_1) throw e_1.error; }
301
- return [7 /*endfinally*/];
302
- case 8: return [2 /*return*/];
303
- }
304
- });
305
- }); };
306
- };
307
- };
308
- };
309
- /**
310
- * Validate sorting options.
311
- *
312
- * Test a pagination API supporting sorting options.
313
- *
314
- * You can validate detailed sorting options both asceding and descending orders
315
- * with multiple fields. However, as it forms a complicate currying function,
316
- * I recomend you to see below example code before using.
317
- *
318
- * @param title Title of error message when sorting is invalid
319
- * @example https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_sort.ts
320
- */
321
- TestValidator.sort = function (title) {
322
- /**
323
- * @param getter A pagination API function to be called
324
- */
325
- return function (getter) {
326
- /**
327
- * @param fields List of fields to be sorted
328
- */
329
- return function () {
330
- var fields = [];
331
- for (var _i = 0; _i < arguments.length; _i++) {
332
- fields[_i] = arguments[_i];
333
- }
334
- /**
335
- * @param comp Comparator function for validation
336
- * @param filter Filter function for data if required
337
- */
338
- return function (comp, filter) {
339
- /**
340
- * @param direction "+" means ascending order, and "-" means descending order
341
- */
342
- return function (direction, trace) {
343
- if (trace === void 0) { trace = true; }
344
- return __awaiter(_this, void 0, void 0, function () {
345
- var data, reversed;
346
- return __generator(this, function (_a) {
347
- switch (_a.label) {
348
- case 0: return [4 /*yield*/, getter(fields.map(function (field) { return "".concat(direction).concat(field); }))];
349
- case 1:
350
- data = _a.sent();
351
- if (filter)
352
- data = data.filter(filter);
353
- reversed = direction === "+" ? comp : function (x, y) { return comp(y, x); };
354
- if ((0, ranges_1.is_sorted)(data, function (x, y) { return reversed(x, y) < 0; }) === false) {
355
- if (fields.length === 1 &&
356
- data.length &&
357
- data[0][fields[0]] !== undefined &&
358
- trace)
359
- console.log(data.map(function (elem) { return elem[fields[0]]; }));
360
- throw new Error("Bug on ".concat(title, ": wrong sorting on ").concat(direction, "(").concat(fields.join(", "), ")."));
361
- }
362
- return [2 /*return*/];
363
- }
364
- });
365
- });
366
- };
367
- };
368
- };
369
- };
370
- };
371
- })(TestValidator = exports.TestValidator || (exports.TestValidator = {}));
372
- function get_ids(entities) {
373
- return entities.map(function (entity) { return entity.id; }).sort(function (x, y) { return (x < y ? -1 : 1); });
374
- }
375
- function is_promise(input) {
376
- return (typeof input === "object" &&
377
- input !== null &&
378
- typeof input.then === "function" &&
379
- typeof input.catch === "function");
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