@oada/oadaify
Version:
Make OADA data nicer to work with in JS/TS
58 lines • 1.64 kB
JavaScript
;
/**
* Tests for playing nicely with JSON, ajv, etc.
*
* @packageDocumentation
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ava_1 = __importDefault(require("ava"));
const ajv_1 = __importDefault(require("ajv"));
const __1 = require("../");
ava_1.default('should be idempotent', (t) => {
const input = {
_id: 'resources/1223',
_rev: 2,
_meta: {},
foo: 'bar',
foo2: 'baz',
};
const output1 = __1.oadaify(input);
const output2 = __1.oadaify(output1);
t.deepEqual(output1, output2);
});
ava_1.default('should include OADA keys in JSON', (t) => {
const input = {
_id: 'resources/123',
_rev: 0,
foo: 'bar',
baz: {
_id: 'resources/456',
},
};
const output = __1.oadaify(input);
const json = JSON.parse(JSON.stringify(output));
t.deepEqual(json, input);
});
ava_1.default('should work right with ajv', (t) => {
const input = {
_id: 'resources/123',
_rev: 1,
foo: 'bar',
};
const schema = {
type: 'object',
properties: {
_id: { type: 'string' },
_rev: { type: 'integer' },
foo: { const: 'bar' },
},
required: ['_id', '_rev', 'foo'],
};
const output = __1.oadaify(input);
const ajv = new ajv_1.default();
t.true(ajv.validate(schema, output), ajv.errorsText());
});
//# sourceMappingURL=compatability.spec.js.map