validata-mongo
Version:
MongoDB update `$set` operations
69 lines • 2.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.expectValue = exports.expectSuccess = exports.expectIssue = exports.runTests = void 0;
const validata_1 = require("validata");
const runTests = (fut, ...tests) => {
tests.forEach((test) => {
const result = fut.process(test.input);
if (test.issues) {
expect(result).toBeDefined();
if (!(0, validata_1.isIssue)(result)) {
fail(result.value);
}
else {
test.issues.forEach((issue) => {
expect(result.issues).toEqual(expect.arrayContaining([
expect.objectContaining({
path: issue.path || [],
reason: issue.reason,
}),
]));
});
}
}
else {
expect(result).toBeDefined();
if ((0, validata_1.isIssue)(result)) {
fail(result.issues);
}
else {
expect(result.value).toEqual(test.expect);
}
}
});
};
exports.runTests = runTests;
const expectIssue = (fut, value, reason, path = []) => {
const result = fut.process(value);
if (!(0, validata_1.isIssue)(result)) {
fail('no issue');
}
expect(result.issues).toEqual(expect.arrayContaining([
expect.objectContaining({
path,
reason,
}),
]));
};
exports.expectIssue = expectIssue;
const expectSuccess = (fut, value) => {
const result = fut.process(value);
expect(result).toBeDefined();
if ((0, validata_1.isIssue)(result)) {
fail(`Unexpected issue: ${JSON.stringify(result)}`);
}
return result;
};
exports.expectSuccess = expectSuccess;
const expectValue = (fut, value, coerced) => {
const result = fut.process(value);
expect(result).toBeDefined();
if ((0, validata_1.isIssue)(result)) {
fail(`Unexpected issue: ${JSON.stringify(result)}`);
}
if (result) {
expect(result.value).toEqual(coerced);
}
};
exports.expectValue = expectValue;
//# sourceMappingURL=test-helpers.js.map