Finish writing the schema tests
This commit is contained in:
parent
946a44edae
commit
c26b4318ee
3 changed files with 143 additions and 0 deletions
96
module/__tests__/schemas/row.mjs
Normal file
96
module/__tests__/schemas/row.mjs
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
import { api } from "../../api.mjs";
|
||||
import { PrivacyMode } from "../../utils/privacy.mjs";
|
||||
|
||||
export function rowTests(quench) {
|
||||
quench.registerBatch(
|
||||
`${__ID__}.rowSchema`,
|
||||
(ctx) => {
|
||||
const { describe, it, expect } = ctx;
|
||||
|
||||
describe(`the row schema`, () => {
|
||||
it(`should allow number-based values`, () => {
|
||||
const { error } = api.schemas.row.validate(
|
||||
{
|
||||
_id: `1`,
|
||||
timestamp: (new Date()).toISOString(),
|
||||
value: 1,
|
||||
privacy: PrivacyMode.PUBLIC,
|
||||
},
|
||||
);
|
||||
expect(error).to.be.undefined;
|
||||
});
|
||||
|
||||
it(`should allow string-based values`, () => {
|
||||
const { error } = api.schemas.row.validate(
|
||||
{
|
||||
_id: `1`,
|
||||
timestamp: (new Date()).toISOString(),
|
||||
value: `apple`,
|
||||
privacy: PrivacyMode.PUBLIC,
|
||||
},
|
||||
);
|
||||
expect(error).to.be.undefined;
|
||||
});
|
||||
|
||||
it(`shouldn't allow invalid privacy modes`, () => {
|
||||
const { error } = api.schemas.row.validate(
|
||||
{
|
||||
_id: `1`,
|
||||
timestamp: (new Date()).toISOString(),
|
||||
value: 1,
|
||||
privacy: `yahaha`,
|
||||
},
|
||||
);
|
||||
expect(error).not.to.be.undefined;
|
||||
});
|
||||
|
||||
it(`shouldn't allow invalid value modes`, () => {
|
||||
const { error } = api.schemas.row.validate(
|
||||
{
|
||||
_id: `1`,
|
||||
timestamp: (new Date()).toISOString(),
|
||||
value: true,
|
||||
privacy: PrivacyMode.PUBLIC,
|
||||
},
|
||||
);
|
||||
expect(error).not.to.be.undefined;
|
||||
});
|
||||
|
||||
it(`shouldn't allow non-ISO date formats`, () => {
|
||||
const { error } = api.schemas.row.validate(
|
||||
{
|
||||
_id: `1`,
|
||||
timestamp: (new Date()).toDateString(),
|
||||
value: 1,
|
||||
privacy: PrivacyMode.PUBLIC,
|
||||
},
|
||||
);
|
||||
expect(error).not.to.be.undefined;
|
||||
});
|
||||
|
||||
it(`should require an ID to be present`, () => {
|
||||
const { error } = api.schemas.row.validate(
|
||||
{
|
||||
timestamp: (new Date()).toISOString(),
|
||||
value: true,
|
||||
privacy: PrivacyMode.PUBLIC,
|
||||
},
|
||||
);
|
||||
expect(error).not.to.be.undefined;
|
||||
});
|
||||
|
||||
it(`shouldn't allow empty string as a value`, () => {
|
||||
const { error } = api.schemas.row.validate(
|
||||
{
|
||||
_id: `1`,
|
||||
timestamp: (new Date()).toISOString(),
|
||||
value: ``,
|
||||
privacy: PrivacyMode.PUBLIC,
|
||||
},
|
||||
);
|
||||
expect(error).not.to.be.undefined;
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
};
|
||||
43
module/__tests__/schemas/table.mjs
Normal file
43
module/__tests__/schemas/table.mjs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import { api } from "../../api.mjs";
|
||||
|
||||
const graph = { type: `bar` };
|
||||
const buckets = { type: `string` };
|
||||
|
||||
export function tableTests(quench) {
|
||||
quench.registerBatch(
|
||||
`${__ID__}.tableSchema`,
|
||||
(ctx) => {
|
||||
const { describe, it, expect } = ctx;
|
||||
|
||||
describe(`the table schema`, () => {
|
||||
it(`should require that name be a non-empty string`, () => {
|
||||
const { error } = api.schemas.table.validate(
|
||||
{ name: ``, graph, buckets },
|
||||
);
|
||||
expect(error).not.to.be.undefined;
|
||||
});
|
||||
|
||||
it(`should require that name only contain alphanumeric characters`, () => {
|
||||
const { error } = api.schemas.table.validate(
|
||||
{ name: `:(`, graph, buckets },
|
||||
);
|
||||
expect(error).not.to.be.undefined;
|
||||
});
|
||||
|
||||
it(`should allow the name to contain spaces`, () => {
|
||||
const { error } = api.schemas.table.validate(
|
||||
{ name: `a name with spaces`, graph, buckets },
|
||||
);
|
||||
expect(error).to.be.undefined;
|
||||
});
|
||||
|
||||
it(`should allow a single forward slash for subtables`, () => {
|
||||
const { error } = api.schemas.table.validate(
|
||||
{ name: `Table/subtable`, graph, buckets },
|
||||
);
|
||||
expect(error).to.be.undefined;
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue