Socket
Socket
Sign inDemoInstall

@nestia/e2e

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nestia/e2e - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

22

lib/TestValidator.d.ts

@@ -33,2 +33,19 @@ /**

/**
* Valiate search options.
*
* Test a pagination API supporting search options.
*
* @param title Title of error message when searching is invalid
* @returns Currying function
*
* @example https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_search.ts
*/
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>;
interface ISearchProps<Entity extends IEntity<any>, Values extends any[], Input> {
fields: string[];
values(entity: Entity): Values;
filter(entity: Entity, values: Values): boolean;
search(values: Values): Input;
}
/**
* Validate sorting options.

@@ -42,7 +59,6 @@ *

*
* @param title Title of error messaeg when sorting is invalid
*
* @param title Title of error message when sorting is invalid
* @example https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_sort.ts
*/
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>;
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>;
type Sortable<Literal extends string> = Array<`-${Literal}` | `+${Literal}`>;

@@ -49,0 +65,0 @@ }

@@ -38,5 +38,17 @@ "use strict";

};
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TestValidator = void 0;
var ranges_1 = require("tstl/ranges");
var RandomGenerator_1 = require("./RandomGenerator");
/**

@@ -116,2 +128,86 @@ * Test validator.

/**
* Valiate search options.
*
* Test a pagination API supporting search options.
*
* @param title Title of error message when searching is invalid
* @returns Currying function
*
* @example https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_search.ts
*/
TestValidator.search = function (title) {
/**
* @param getter A pagination API function to be called
* @param validator Validator function if required
*/
return function (getter, validator) {
/**
* @param total Total entity records for comparison
* @param sampleCount Sampling count. Default is 1
*/
return function (total, sampleCount) {
if (sampleCount === void 0) { sampleCount = 1; }
/**
* @param props Search properties
*/
return function (props) { return __awaiter(_this, void 0, void 0, function () {
var samples, _loop_1, samples_1, samples_1_1, s, e_1_1;
var e_1, _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
samples = RandomGenerator_1.RandomGenerator.sample(total, sampleCount);
_loop_1 = function (s) {
var values, filtered, gotten;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
values = props.values(s);
filtered = total.filter(function (entity) {
return props.filter(entity, values);
});
return [4 /*yield*/, getter(props.search(values))];
case 1:
gotten = _c.sent();
if (validator)
validator(gotten);
TestValidator.index("".concat(title, " (").concat(props.fields.join(", "), ")"))(filtered)(gotten);
return [2 /*return*/];
}
});
};
_b.label = 1;
case 1:
_b.trys.push([1, 6, 7, 8]);
samples_1 = __values(samples), samples_1_1 = samples_1.next();
_b.label = 2;
case 2:
if (!!samples_1_1.done) return [3 /*break*/, 5];
s = samples_1_1.value;
return [5 /*yield**/, _loop_1(s)];
case 3:
_b.sent();
_b.label = 4;
case 4:
samples_1_1 = samples_1.next();
return [3 /*break*/, 2];
case 5: return [3 /*break*/, 8];
case 6:
e_1_1 = _b.sent();
e_1 = { error: e_1_1 };
return [3 /*break*/, 8];
case 7:
try {
if (samples_1_1 && !samples_1_1.done && (_a = samples_1.return)) _a.call(samples_1);
}
finally { if (e_1) throw e_1.error; }
return [7 /*endfinally*/];
case 8: return [2 /*return*/];
}
});
}); };
};
};
};
/**
* Validate sorting options.

@@ -125,4 +221,3 @@ *

*
* @param title Title of error messaeg when sorting is invalid
*
* @param title Title of error message when sorting is invalid
* @example https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_sort.ts

@@ -134,3 +229,3 @@ */

*/
return function (getter) {
return function (getter, validator) {
/**

@@ -161,2 +256,4 @@ * @param fields List of fields to be sorted

data = _a.sent();
if (validator)
validator(data);
if (filter)

@@ -163,0 +260,0 @@ data = data.filter(filter);

2

package.json
{
"name": "@nestia/e2e",
"version": "0.1.2",
"version": "0.1.3",
"description": "E2E test utilify functions",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

import { is_sorted } from "tstl/ranges";
import { RandomGenerator } from "./RandomGenerator";
/**

@@ -72,2 +74,62 @@ * Test validator.

/**
* Valiate search options.
*
* Test a pagination API supporting search options.
*
* @param title Title of error message when searching is invalid
* @returns Currying function
*
* @example https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_search.ts
*/
export const search =
(title: string) =>
/**
* @param getter A pagination API function to be called
* @param validator Validator function if required
*/
<Entity extends IEntity<any>, Input>(
getter: (input: Input) => Promise<Entity[]>,
validator?: (data: Entity[]) => any,
) =>
/**
* @param total Total entity records for comparison
* @param sampleCount Sampling count. Default is 1
*/
(total: Entity[], sampleCount: number = 1) =>
/**
* @param props Search properties
*/
async <Values extends any[]>(
props: ISearchProps<Entity, Values, Input>,
) => {
const samples: Entity[] = RandomGenerator.sample(
total,
sampleCount,
);
for (const s of samples) {
const values: Values = props.values(s);
const filtered: Entity[] = total.filter((entity) =>
props.filter(entity, values),
);
const gotten: Entity[] = await getter(props.search(values));
if (validator) validator(gotten);
TestValidator.index(`${title} (${props.fields.join(", ")})`)(
filtered,
)(gotten);
}
};
export interface ISearchProps<
Entity extends IEntity<any>,
Values extends any[],
Input,
> {
fields: string[];
values(entity: Entity): Values;
filter(entity: Entity, values: Values): boolean;
search(values: Values): Input;
}
/**
* Validate sorting options.

@@ -81,4 +143,3 @@ *

*
* @param title Title of error messaeg when sorting is invalid
*
* @param title Title of error message when sorting is invalid
* @example https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_sort.ts

@@ -97,2 +158,3 @@ */

getter: (sortable: Sortable) => Promise<T[]>,
validator?: (data: T[]) => any,
) =>

@@ -117,2 +179,3 @@ /**

);
if (validator) validator(data);
if (filter) data = data.filter(filter);

@@ -119,0 +182,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc