@nestia/e2e 0.1.2 → 0.1.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.
- package/lib/TestValidator.d.ts +18 -2
- package/lib/TestValidator.js +94 -2
- package/lib/TestValidator.js.map +1 -1
- package/package.json +1 -1
- package/src/TestValidator.ts +60 -2
package/lib/TestValidator.d.ts
CHANGED
|
@@ -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>, Request_1>(getter: (input: Request_1) => Promise<Entity[]>) => (total: Entity[], sampleCount?: number) => <Values extends any[]>(props: ISearchProps<Entity, Values, Request_1>) => Promise<void>;
|
|
43
|
+
interface ISearchProps<Entity extends IEntity<any>, Values extends any[], Request> {
|
|
44
|
+
fields: string[];
|
|
45
|
+
values(entity: Entity): Values;
|
|
46
|
+
filter(entity: Entity, values: Values): boolean;
|
|
47
|
+
request(values: Values): Request;
|
|
48
|
+
}
|
|
32
49
|
/**
|
|
33
50
|
* Validate sorting options.
|
|
34
51
|
*
|
|
@@ -38,8 +55,7 @@ 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
|
|
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
61
|
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>;
|
package/lib/TestValidator.js
CHANGED
|
@@ -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,87 @@ 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
|
+
*/
|
|
140
|
+
return function (getter) {
|
|
141
|
+
/**
|
|
142
|
+
* @param total Total entity records for comparison
|
|
143
|
+
* @param sampleCount Sampling count. Default is 1
|
|
144
|
+
*/
|
|
145
|
+
return function (total, sampleCount) {
|
|
146
|
+
if (sampleCount === void 0) { sampleCount = 1; }
|
|
147
|
+
/**
|
|
148
|
+
* @param props Search properties
|
|
149
|
+
*/
|
|
150
|
+
return function (props) { return __awaiter(_this, void 0, void 0, function () {
|
|
151
|
+
var samples, _loop_1, samples_1, samples_1_1, s, e_1_1;
|
|
152
|
+
var e_1, _a;
|
|
153
|
+
return __generator(this, function (_b) {
|
|
154
|
+
switch (_b.label) {
|
|
155
|
+
case 0:
|
|
156
|
+
samples = RandomGenerator_1.RandomGenerator.sample(total, sampleCount);
|
|
157
|
+
_loop_1 = function (s) {
|
|
158
|
+
var values, filtered, gotten;
|
|
159
|
+
return __generator(this, function (_c) {
|
|
160
|
+
switch (_c.label) {
|
|
161
|
+
case 0:
|
|
162
|
+
values = props.values(s);
|
|
163
|
+
filtered = total.filter(function (entity) {
|
|
164
|
+
return props.filter(entity, values);
|
|
165
|
+
});
|
|
166
|
+
return [4 /*yield*/, getter(props.request(values))];
|
|
167
|
+
case 1:
|
|
168
|
+
gotten = _c.sent();
|
|
169
|
+
TestValidator.index("".concat(title, " (").concat(props.fields.join(", "), ")"))(filtered)(gotten);
|
|
170
|
+
return [2 /*return*/];
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
_b.label = 1;
|
|
175
|
+
case 1:
|
|
176
|
+
_b.trys.push([1, 6, 7, 8]);
|
|
177
|
+
samples_1 = __values(samples), samples_1_1 = samples_1.next();
|
|
178
|
+
_b.label = 2;
|
|
179
|
+
case 2:
|
|
180
|
+
if (!!samples_1_1.done) return [3 /*break*/, 5];
|
|
181
|
+
s = samples_1_1.value;
|
|
182
|
+
return [5 /*yield**/, _loop_1(s)];
|
|
183
|
+
case 3:
|
|
184
|
+
_b.sent();
|
|
185
|
+
_b.label = 4;
|
|
186
|
+
case 4:
|
|
187
|
+
samples_1_1 = samples_1.next();
|
|
188
|
+
return [3 /*break*/, 2];
|
|
189
|
+
case 5: return [3 /*break*/, 8];
|
|
190
|
+
case 6:
|
|
191
|
+
e_1_1 = _b.sent();
|
|
192
|
+
e_1 = { error: e_1_1 };
|
|
193
|
+
return [3 /*break*/, 8];
|
|
194
|
+
case 7:
|
|
195
|
+
try {
|
|
196
|
+
if (samples_1_1 && !samples_1_1.done && (_a = samples_1.return)) _a.call(samples_1);
|
|
197
|
+
}
|
|
198
|
+
finally { if (e_1) throw e_1.error; }
|
|
199
|
+
return [7 /*endfinally*/];
|
|
200
|
+
case 8: return [2 /*return*/];
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}); };
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
};
|
|
114
207
|
/**
|
|
115
208
|
* Validate sorting options.
|
|
116
209
|
*
|
|
@@ -120,8 +213,7 @@ var TestValidator;
|
|
|
120
213
|
* with multiple fields. However, as it forms a complicate currying function,
|
|
121
214
|
* I recomend you to see below example code before using.
|
|
122
215
|
*
|
|
123
|
-
* @param title Title of error
|
|
124
|
-
*
|
|
216
|
+
* @param title Title of error message when sorting is invalid
|
|
125
217
|
* @example https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_sort.ts
|
|
126
218
|
*/
|
|
127
219
|
TestValidator.sort = function (title) {
|
package/lib/TestValidator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TestValidator.js","sourceRoot":"","sources":["../src/TestValidator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TestValidator.js","sourceRoot":"","sources":["../src/TestValidator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sCAAwC;AAExC,qDAAoD;AAEpD;;;;;;GAMG;AACH,IAAiB,aAAa,CAuL7B;AAvLD,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,EACjB,KAAqB;gBAArB,sBAAA,EAAA,YAAqB;gBAErB,IAAM,MAAM,GAAW,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;gBAChE,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;gBACrC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;gBAEjC,IAAM,IAAI,GAAa,OAAO,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;gBAC1D,IAAM,IAAI,GAAa,OAAO,CAAC,MAAM,CAAC;qBACjC,MAAM,CAAC,UAAC,EAAE,IAAK,OAAA,EAAE,IAAI,IAAI,CAAC,CAAC,CAAC,EAAb,CAAa,CAAC;qBAC7B,KAAK,CAAC,CAAC,EAAE,MAAM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G,CAAC,IAAI,CAAC,GAAG,CAAC,UAAC,IAAI,IAAK,OAAC,IAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAxB,CAAwB,CAAC,CAAC,CAAC;4CAC9D,MAAM,IAAI,KAAK,CACX,iBAAU,KAAK,gCAAsB,SAAS,cAAI,MAAM,CAAC,IAAI,CACzD,IAAI,CACP,OAAI,CACR,CAAC;yCACL;;;;;qBACJ;gBAxBD,CAwBC;YA5BD,CA4BC;QAjCD,CAiCC;IA3CD,CA2CC,CAAC;AAKV,CAAC,EAvLgB,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAuL7B;AAMD,SAAS,OAAO,CAA8B,QAAkB;IAC5D,OAAO,QAAQ,CAAC,GAAG,CAAC,UAAC,MAAM,IAAK,OAAA,MAAM,CAAC,EAAE,EAAT,CAAS,CAAC,CAAC,IAAI,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAhB,CAAgB,CAAC,CAAC;AAChF,CAAC"}
|
package/package.json
CHANGED
package/src/TestValidator.ts
CHANGED
|
@@ -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,63 @@ 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
|
+
*/
|
|
88
|
+
<Entity extends IEntity<any>, Request>(
|
|
89
|
+
getter: (input: Request) => Promise<Entity[]>,
|
|
90
|
+
) =>
|
|
91
|
+
/**
|
|
92
|
+
* @param total Total entity records for comparison
|
|
93
|
+
* @param sampleCount Sampling count. Default is 1
|
|
94
|
+
*/
|
|
95
|
+
(total: Entity[], sampleCount: number = 1) =>
|
|
96
|
+
/**
|
|
97
|
+
* @param props Search properties
|
|
98
|
+
*/
|
|
99
|
+
async <Values extends any[]>(
|
|
100
|
+
props: ISearchProps<Entity, Values, Request>,
|
|
101
|
+
): Promise<void> => {
|
|
102
|
+
const samples: Entity[] = RandomGenerator.sample(
|
|
103
|
+
total,
|
|
104
|
+
sampleCount,
|
|
105
|
+
);
|
|
106
|
+
for (const s of samples) {
|
|
107
|
+
const values: Values = props.values(s);
|
|
108
|
+
const filtered: Entity[] = total.filter((entity) =>
|
|
109
|
+
props.filter(entity, values),
|
|
110
|
+
);
|
|
111
|
+
const gotten: Entity[] = await getter(props.request(values));
|
|
112
|
+
|
|
113
|
+
TestValidator.index(`${title} (${props.fields.join(", ")})`)(
|
|
114
|
+
filtered,
|
|
115
|
+
)(gotten);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export interface ISearchProps<
|
|
120
|
+
Entity extends IEntity<any>,
|
|
121
|
+
Values extends any[],
|
|
122
|
+
Request,
|
|
123
|
+
> {
|
|
124
|
+
fields: string[];
|
|
125
|
+
values(entity: Entity): Values;
|
|
126
|
+
filter(entity: Entity, values: Values): boolean;
|
|
127
|
+
request(values: Values): Request;
|
|
128
|
+
}
|
|
129
|
+
|
|
71
130
|
/**
|
|
72
131
|
* Validate sorting options.
|
|
73
132
|
*
|
|
@@ -77,8 +136,7 @@ export namespace TestValidator {
|
|
|
77
136
|
* with multiple fields. However, as it forms a complicate currying function,
|
|
78
137
|
* I recomend you to see below example code before using.
|
|
79
138
|
*
|
|
80
|
-
* @param title Title of error
|
|
81
|
-
*
|
|
139
|
+
* @param title Title of error message when sorting is invalid
|
|
82
140
|
* @example https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_sort.ts
|
|
83
141
|
*/
|
|
84
142
|
export const sort =
|