@nestia/e2e 0.1.2 → 0.1.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.
@@ -29,6 +29,23 @@ export declare namespace TestValidator {
29
29
  * @example https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_search.ts
30
30
  */
31
31
  const index: (title: string) => <Solution extends IEntity<any>>(expected: Solution[]) => <Summary extends IEntity<any>>(gotten: Summary[], trace?: boolean) => void;
32
+ /**
33
+ * Valiate search options.
34
+ *
35
+ * Test a pagination API supporting search options.
36
+ *
37
+ * @param title Title of error message when searching is invalid
38
+ * @returns Currying function
39
+ *
40
+ * @example https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_search.ts
41
+ */
42
+ const search: (title: string) => <Entity extends IEntity<any>, Input>(getter: (input: Input) => Promise<Entity[]>, validator?: ((data: Entity[]) => any) | undefined) => (total: Entity[], sampleCount?: number) => <Values extends any[]>(props: ISearchProps<Entity, Values, Input>) => Promise<void>;
43
+ interface ISearchProps<Entity extends IEntity<any>, Values extends any[], Input> {
44
+ fields: string[];
45
+ values(entity: Entity): Values;
46
+ filter(entity: Entity, values: Values): boolean;
47
+ search(values: Values): Input;
48
+ }
32
49
  /**
33
50
  * Validate sorting options.
34
51
  *
@@ -38,11 +55,10 @@ export declare namespace TestValidator {
38
55
  * with multiple fields. However, as it forms a complicate currying function,
39
56
  * I recomend you to see below example code before using.
40
57
  *
41
- * @param title Title of error messaeg when sorting is invalid
42
- *
58
+ * @param title Title of error message when sorting is invalid
43
59
  * @example https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_sort.ts
44
60
  */
45
- const sort: (title: string) => <T extends object, Fields extends string, Sortable_1 extends (`-${Fields}` | `+${Fields}`)[]>(getter: (sortable: Sortable_1) => Promise<T[]>) => (...fields: Fields[]) => (comp: (x: T, y: T) => number, filter?: ((elem: T) => boolean) | undefined) => (direction: "+" | "-", trace?: boolean) => Promise<void>;
61
+ const sort: (title: string) => <T extends object, Fields extends string, Sortable_1 extends (`-${Fields}` | `+${Fields}`)[]>(getter: (sortable: Sortable_1) => Promise<T[]>, validator?: ((data: T[]) => any) | undefined) => (...fields: Fields[]) => (comp: (x: T, y: T) => number, filter?: ((elem: T) => boolean) | undefined) => (direction: "+" | "-", trace?: boolean) => Promise<void>;
46
62
  type Sortable<Literal extends string> = Array<`-${Literal}` | `+${Literal}`>;
47
63
  }
48
64
  interface IEntity<Type extends string | number | bigint> {
@@ -35,9 +35,21 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
36
  }
37
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
+ };
38
49
  Object.defineProperty(exports, "__esModule", { value: true });
39
50
  exports.TestValidator = void 0;
40
51
  var ranges_1 = require("tstl/ranges");
52
+ var RandomGenerator_1 = require("./RandomGenerator");
41
53
  /**
42
54
  * Test validator.
43
55
  *
@@ -111,6 +123,90 @@ var TestValidator;
111
123
  };
112
124
  };
113
125
  };
126
+ /**
127
+ * Valiate search options.
128
+ *
129
+ * Test a pagination API supporting search options.
130
+ *
131
+ * @param title Title of error message when searching is invalid
132
+ * @returns Currying function
133
+ *
134
+ * @example https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_search.ts
135
+ */
136
+ TestValidator.search = function (title) {
137
+ /**
138
+ * @param getter A pagination API function to be called
139
+ * @param validator Validator function if required
140
+ */
141
+ return function (getter, validator) {
142
+ /**
143
+ * @param total Total entity records for comparison
144
+ * @param sampleCount Sampling count. Default is 1
145
+ */
146
+ return function (total, sampleCount) {
147
+ if (sampleCount === void 0) { sampleCount = 1; }
148
+ /**
149
+ * @param props Search properties
150
+ */
151
+ return function (props) { return __awaiter(_this, void 0, void 0, function () {
152
+ var samples, _loop_1, samples_1, samples_1_1, s, e_1_1;
153
+ var e_1, _a;
154
+ return __generator(this, function (_b) {
155
+ switch (_b.label) {
156
+ case 0:
157
+ samples = RandomGenerator_1.RandomGenerator.sample(total, sampleCount);
158
+ _loop_1 = function (s) {
159
+ var values, filtered, gotten;
160
+ return __generator(this, function (_c) {
161
+ switch (_c.label) {
162
+ case 0:
163
+ values = props.values(s);
164
+ filtered = total.filter(function (entity) {
165
+ return props.filter(entity, values);
166
+ });
167
+ return [4 /*yield*/, getter(props.search(values))];
168
+ case 1:
169
+ gotten = _c.sent();
170
+ if (validator)
171
+ validator(gotten);
172
+ TestValidator.index("".concat(title, " (").concat(props.fields.join(", "), ")"))(filtered)(gotten);
173
+ return [2 /*return*/];
174
+ }
175
+ });
176
+ };
177
+ _b.label = 1;
178
+ case 1:
179
+ _b.trys.push([1, 6, 7, 8]);
180
+ samples_1 = __values(samples), samples_1_1 = samples_1.next();
181
+ _b.label = 2;
182
+ case 2:
183
+ if (!!samples_1_1.done) return [3 /*break*/, 5];
184
+ s = samples_1_1.value;
185
+ return [5 /*yield**/, _loop_1(s)];
186
+ case 3:
187
+ _b.sent();
188
+ _b.label = 4;
189
+ case 4:
190
+ samples_1_1 = samples_1.next();
191
+ return [3 /*break*/, 2];
192
+ case 5: return [3 /*break*/, 8];
193
+ case 6:
194
+ e_1_1 = _b.sent();
195
+ e_1 = { error: e_1_1 };
196
+ return [3 /*break*/, 8];
197
+ case 7:
198
+ try {
199
+ if (samples_1_1 && !samples_1_1.done && (_a = samples_1.return)) _a.call(samples_1);
200
+ }
201
+ finally { if (e_1) throw e_1.error; }
202
+ return [7 /*endfinally*/];
203
+ case 8: return [2 /*return*/];
204
+ }
205
+ });
206
+ }); };
207
+ };
208
+ };
209
+ };
114
210
  /**
115
211
  * Validate sorting options.
116
212
  *
@@ -120,15 +216,14 @@ var TestValidator;
120
216
  * with multiple fields. However, as it forms a complicate currying function,
121
217
  * I recomend you to see below example code before using.
122
218
  *
123
- * @param title Title of error messaeg when sorting is invalid
124
- *
219
+ * @param title Title of error message when sorting is invalid
125
220
  * @example https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_sort.ts
126
221
  */
127
222
  TestValidator.sort = function (title) {
128
223
  /**
129
224
  * @param getter A pagination API function to be called
130
225
  */
131
- return function (getter) {
226
+ return function (getter, validator) {
132
227
  /**
133
228
  * @param fields List of fields to be sorted
134
229
  */
@@ -154,6 +249,8 @@ var TestValidator;
154
249
  case 0: return [4 /*yield*/, getter(fields.map(function (field) { return "".concat(direction).concat(field); }))];
155
250
  case 1:
156
251
  data = _a.sent();
252
+ if (validator)
253
+ validator(data);
157
254
  if (filter)
158
255
  data = data.filter(filter);
159
256
  reversed = direction === "+" ? comp : function (x, y) { return comp(y, x); };
@@ -1 +1 @@
1
- {"version":3,"file":"TestValidator.js","sourceRoot":"","sources":["../src/TestValidator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sCAAwC;AAExC;;;;;;GAMG;AACH,IAAiB,aAAa,CA+H7B;AA/HD,WAAiB,aAAa;;IAC1B;;;;;;;;OAQG;IACU,mBAAK,GACd,UAAC,KAAa;QACd,OAAA,UAAO,IAA8B;;;;;;wBAE7B,qBAAM,IAAI,EAAE,EAAA;;wBAAZ,SAAY,CAAC;;;;wBAEb,sBAAO;4BAEX,MAAM,IAAI,KAAK,CAAC,iBAAU,KAAK,gCAA6B,CAAC,CAAC;;;aACjE;IAPD,CAOC,CAAC;IAEN;;;;;;;;;;;OAWG;IACU,mBAAK,GACd,UAAC,KAAa;QACd,OAAA,UAAgC,QAAoB;YACpD,OAAA,UACI,MAAiB,E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
4
4
  "description": "E2E test utilify functions",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -1,5 +1,7 @@
1
1
  import { is_sorted } from "tstl/ranges";
2
2
 
3
+ import { RandomGenerator } from "./RandomGenerator";
4
+
3
5
  /**
4
6
  * Test validator.
5
7
  *
@@ -68,6 +70,66 @@ export namespace TestValidator {
68
70
  );
69
71
  };
70
72
 
73
+ /**
74
+ * Valiate search options.
75
+ *
76
+ * Test a pagination API supporting search options.
77
+ *
78
+ * @param title Title of error message when searching is invalid
79
+ * @returns Currying function
80
+ *
81
+ * @example https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_search.ts
82
+ */
83
+ export const search =
84
+ (title: string) =>
85
+ /**
86
+ * @param getter A pagination API function to be called
87
+ * @param validator Validator function if required
88
+ */
89
+ <Entity extends IEntity<any>, Input>(
90
+ getter: (input: Input) => Promise<Entity[]>,
91
+ validator?: (data: Entity[]) => any,
92
+ ) =>
93
+ /**
94
+ * @param total Total entity records for comparison
95
+ * @param sampleCount Sampling count. Default is 1
96
+ */
97
+ (total: Entity[], sampleCount: number = 1) =>
98
+ /**
99
+ * @param props Search properties
100
+ */
101
+ async <Values extends any[]>(
102
+ props: ISearchProps<Entity, Values, Input>,
103
+ ) => {
104
+ const samples: Entity[] = RandomGenerator.sample(
105
+ total,
106
+ sampleCount,
107
+ );
108
+ for (const s of samples) {
109
+ const values: Values = props.values(s);
110
+ const filtered: Entity[] = total.filter((entity) =>
111
+ props.filter(entity, values),
112
+ );
113
+ const gotten: Entity[] = await getter(props.search(values));
114
+ if (validator) validator(gotten);
115
+
116
+ TestValidator.index(`${title} (${props.fields.join(", ")})`)(
117
+ filtered,
118
+ )(gotten);
119
+ }
120
+ };
121
+
122
+ export interface ISearchProps<
123
+ Entity extends IEntity<any>,
124
+ Values extends any[],
125
+ Input,
126
+ > {
127
+ fields: string[];
128
+ values(entity: Entity): Values;
129
+ filter(entity: Entity, values: Values): boolean;
130
+ search(values: Values): Input;
131
+ }
132
+
71
133
  /**
72
134
  * Validate sorting options.
73
135
  *
@@ -77,8 +139,7 @@ export namespace TestValidator {
77
139
  * with multiple fields. However, as it forms a complicate currying function,
78
140
  * I recomend you to see below example code before using.
79
141
  *
80
- * @param title Title of error messaeg when sorting is invalid
81
- *
142
+ * @param title Title of error message when sorting is invalid
82
143
  * @example https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_sort.ts
83
144
  */
84
145
  export const sort =
@@ -92,6 +153,7 @@ export namespace TestValidator {
92
153
  Sortable extends Array<`-${Fields}` | `+${Fields}`>,
93
154
  >(
94
155
  getter: (sortable: Sortable) => Promise<T[]>,
156
+ validator?: (data: T[]) => any,
95
157
  ) =>
96
158
  /**
97
159
  * @param fields List of fields to be sorted
@@ -111,6 +173,7 @@ export namespace TestValidator {
111
173
  (field) => `${direction}${field}` as const,
112
174
  ) as Sortable,
113
175
  );
176
+ if (validator) validator(data);
114
177
  if (filter) data = data.filter(filter);
115
178
 
116
179
  const reversed: typeof comp =