konditions
Version:
A simple and customizable JSON-based condition engine in TypeScript (e.g. GreaterThan, StringLike, Every, Some)
51 lines • 2.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const engine_default_1 = require("../engine.default");
const StringEquals_1 = require("./StringEquals");
const engine = new engine_default_1.DefaultEngine({
NumberEquals: {
resolver: StringEquals_1.Resolver,
validator: StringEquals_1.Validator,
},
});
describe(`Should resolve positively`, () => {
const cases = [
[``, ``],
[` `, ` `],
];
test.each(cases)(`given %p and %p, it should resolve positively`, async (expected, received) => {
const resolution = await StringEquals_1.Resolver({ expected, received }, engine);
expect(resolution.passed).toStrictEqual(true);
});
});
describe(`Should resolve negatively`, () => {
const cases = [[`a`, `A`]];
test.each(cases)(`given %p and %p, it should return not pass`, async (expected, received) => {
const resolution = await StringEquals_1.Resolver({ expected, received }, engine);
expect(resolution.passed).toStrictEqual(false);
});
});
describe(`Should fail validation`, () => {
const cases = [
[123, 23],
[false, ` `],
[``, 0],
];
test.each(cases)(`given %p and %p, it should return %p`, async (expected, received) => {
const resolution = await StringEquals_1.Validator({ expected, received }, engine);
expect(resolution.passed).toStrictEqual(false);
expect(resolution.passed).toStrictEqual(false);
expect(resolution.error).toBeDefined();
expect(resolution.error.type).toEqual(`ValidationError`);
expect(resolution.error.reasons.length).toBeGreaterThan(0);
});
const casesOfArgCount = [{}, { a: `1` }, { a: `1`, b: false, c: `bah` }];
test.each(casesOfArgCount)(`given %p`, async (props) => {
const resolution = await StringEquals_1.Validator(props, engine);
expect(resolution.passed).toStrictEqual(false);
expect(resolution.error).toBeDefined();
expect(resolution.error.type).toEqual(`ValidationError`);
expect(resolution.error.reasons.length).toBeGreaterThan(0);
});
});
//# sourceMappingURL=StringEquals.test.js.map