Skip to content

Commit

Permalink
feat: require asset summary updated maximum property be a UTC datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
l0b0 committed Nov 23, 2021
1 parent 16b2487 commit 97325bc
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 97 deletions.
2 changes: 1 addition & 1 deletion extensions/linz/examples/collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"updated": {
"minimum": "1999-01-01T00:00:00Z",
"maximum": ""
"maximum": "2010-01-01T00:00:00Z"
}
},
"linz:lifecycle": "under development",
Expand Down
4 changes: 4 additions & 0 deletions extensions/linz/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,10 @@
"minimum": {
"title": "Earliest asset updated time",
"$ref": "#/definitions/utc_datetime"
},
"maximum": {
"title": "Latest asset updated time",
"$ref": "#/definitions/utc_datetime"
}
}
}
Expand Down
142 changes: 46 additions & 96 deletions extensions/linz/tests/linz_collection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,105 +243,55 @@ o.spec('LINZ collection', () => {
}
});

o("Asset summary created/updated without the mandatory 'minimum' property should fail validation", async () => {
for (const property of ['created', 'updated']) {
// given
const example = JSON.parse(await fs.readFile(examplePath));
delete example['linz:asset_summaries'][property]['minimum'];

// when
let valid = validate(example);

// then
o(valid).equals(false);
o(
validate.errors.some(
(error) =>
error.instancePath === `/linz:asset_summaries/${property}` &&
error.message === "must have required property 'minimum'",
),
).equals(true)(JSON.stringify(validate.errors));
}
});

o("Asset summary created without the mandatory 'maximum' property should fail validation", async () => {
// given
const example = JSON.parse(await fs.readFile(examplePath));
delete example['linz:asset_summaries']['created']['maximum'];

// when
let valid = validate(example);

// then
o(valid).equals(false);
o(
validate.errors.some(
(error) =>
error.instancePath === '/linz:asset_summaries/created' &&
error.message === "must have required property 'maximum'",
),
).equals(true)(JSON.stringify(validate.errors));
});

o("Asset summary updated without the mandatory 'maximum' property should fail validation", async () => {
// given
const example = JSON.parse(await fs.readFile(examplePath));
delete example['linz:asset_summaries']['updated']['maximum'];

// when
let valid = validate(example);

// then
o(valid).equals(false);
o(
validate.errors.some(
(error) =>
error.dataPath === "['linz:asset_summaries'].updated" &&
error.message === "should have required property '.maximum'",
),
).equals(true)(JSON.stringify(validate.errors));
});

o("Asset summary created/updated with invalid 'minimum' value should fail validation", async () => {
for (const property of ['created', 'updated']) {
// given
const example = JSON.parse(await fs.readFile(examplePath));
example['linz:asset_summaries'][property]['minimum'] = '1999-01-01T00:00:00';

// when
let valid = validate(example);

// then
o(valid).equals(false);
o(
validate.errors.some(
(error) =>
error.instancePath === `/linz:asset_summaries/${property}/minimum` &&
error.message === 'must match pattern "(\\+00:00|Z)$"',
),
).equals(true)(JSON.stringify(validate.errors));
o(
"Asset summary created/updated without the mandatory 'minimum'/'maximum' properties should fail validation",
async () => {
for (const outerProperty of ['created', 'updated']) {
for (const innerProperty of ['minimum', 'maximum']) {
// given
const example = JSON.parse(await fs.readFile(examplePath));
delete example['linz:asset_summaries'][outerProperty][innerProperty];

// when
let valid = validate(example);

// then
o(valid).equals(false);
o(
validate.errors.some(
(error) =>
error.instancePath === `/linz:asset_summaries/${outerProperty}` &&
error.message === `must have required property '${innerProperty}'`,
),
).equals(true)(JSON.stringify(validate.errors));
}
}
},
);

o("Asset summary created/updated with invalid 'minimum'/'maximum' value should fail validation", async () => {
for (const outerProperty of ['created', 'updated']) {
for (const innerProperty of ['minimum', 'maximum']) {
// given
const example = JSON.parse(await fs.readFile(examplePath));
example['linz:asset_summaries'][outerProperty][innerProperty] = '1999-01-01T00:00:00';

// when
let valid = validate(example);

// then
o(valid).equals(false);
o(
validate.errors.some(
(error) =>
error.instancePath === `/linz:asset_summaries/${outerProperty}/${innerProperty}` &&
error.message === 'must match pattern "(\\+00:00|Z)$"',
),
).equals(true)(JSON.stringify(validate.errors));
}
}
});

o("Asset summary created with invalid 'maximum' value should fail validation", async () => {
// given
const example = JSON.parse(await fs.readFile(examplePath));
example['linz:asset_summaries']['created']['maximum'] = '1999-01-01T00:00:00';

// when
let valid = validate(example);

// then
o(valid).equals(false);
o(
validate.errors.some(
(error) =>
error.instancePath === '/linz:asset_summaries/created/maximum' &&
error.message === 'must match pattern "(\\+00:00|Z)$"',
),
).equals(true)(JSON.stringify(validate.errors));
});

o("Example without the mandatory 'linz:history' field should fail validation", async () => {
// given
const example = JSON.parse(await fs.readFile(examplePath));
Expand Down

0 comments on commit 97325bc

Please sign in to comment.