Skip to content

Commit 97325bc

Browse files
committed
feat: require asset summary updated maximum property be a UTC datetime
1 parent 16b2487 commit 97325bc

File tree

3 files changed

+51
-97
lines changed

3 files changed

+51
-97
lines changed

extensions/linz/examples/collection.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"updated": {
2121
"minimum": "1999-01-01T00:00:00Z",
22-
"maximum": ""
22+
"maximum": "2010-01-01T00:00:00Z"
2323
}
2424
},
2525
"linz:lifecycle": "under development",

extensions/linz/schema.json

+4
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,10 @@
959959
"minimum": {
960960
"title": "Earliest asset updated time",
961961
"$ref": "#/definitions/utc_datetime"
962+
},
963+
"maximum": {
964+
"title": "Latest asset updated time",
965+
"$ref": "#/definitions/utc_datetime"
962966
}
963967
}
964968
}

extensions/linz/tests/linz_collection.test.js

+46-96
Original file line numberDiff line numberDiff line change
@@ -243,105 +243,55 @@ o.spec('LINZ collection', () => {
243243
}
244244
});
245245

246-
o("Asset summary created/updated without the mandatory 'minimum' property should fail validation", async () => {
247-
for (const property of ['created', 'updated']) {
248-
// given
249-
const example = JSON.parse(await fs.readFile(examplePath));
250-
delete example['linz:asset_summaries'][property]['minimum'];
251-
252-
// when
253-
let valid = validate(example);
254-
255-
// then
256-
o(valid).equals(false);
257-
o(
258-
validate.errors.some(
259-
(error) =>
260-
error.instancePath === `/linz:asset_summaries/${property}` &&
261-
error.message === "must have required property 'minimum'",
262-
),
263-
).equals(true)(JSON.stringify(validate.errors));
264-
}
265-
});
266-
267-
o("Asset summary created without the mandatory 'maximum' property should fail validation", async () => {
268-
// given
269-
const example = JSON.parse(await fs.readFile(examplePath));
270-
delete example['linz:asset_summaries']['created']['maximum'];
271-
272-
// when
273-
let valid = validate(example);
274-
275-
// then
276-
o(valid).equals(false);
277-
o(
278-
validate.errors.some(
279-
(error) =>
280-
error.instancePath === '/linz:asset_summaries/created' &&
281-
error.message === "must have required property 'maximum'",
282-
),
283-
).equals(true)(JSON.stringify(validate.errors));
284-
});
285-
286-
o("Asset summary updated without the mandatory 'maximum' property should fail validation", async () => {
287-
// given
288-
const example = JSON.parse(await fs.readFile(examplePath));
289-
delete example['linz:asset_summaries']['updated']['maximum'];
290-
291-
// when
292-
let valid = validate(example);
293-
294-
// then
295-
o(valid).equals(false);
296-
o(
297-
validate.errors.some(
298-
(error) =>
299-
error.dataPath === "['linz:asset_summaries'].updated" &&
300-
error.message === "should have required property '.maximum'",
301-
),
302-
).equals(true)(JSON.stringify(validate.errors));
303-
});
304-
305-
o("Asset summary created/updated with invalid 'minimum' value should fail validation", async () => {
306-
for (const property of ['created', 'updated']) {
307-
// given
308-
const example = JSON.parse(await fs.readFile(examplePath));
309-
example['linz:asset_summaries'][property]['minimum'] = '1999-01-01T00:00:00';
310-
311-
// when
312-
let valid = validate(example);
313-
314-
// then
315-
o(valid).equals(false);
316-
o(
317-
validate.errors.some(
318-
(error) =>
319-
error.instancePath === `/linz:asset_summaries/${property}/minimum` &&
320-
error.message === 'must match pattern "(\\+00:00|Z)$"',
321-
),
322-
).equals(true)(JSON.stringify(validate.errors));
246+
o(
247+
"Asset summary created/updated without the mandatory 'minimum'/'maximum' properties should fail validation",
248+
async () => {
249+
for (const outerProperty of ['created', 'updated']) {
250+
for (const innerProperty of ['minimum', 'maximum']) {
251+
// given
252+
const example = JSON.parse(await fs.readFile(examplePath));
253+
delete example['linz:asset_summaries'][outerProperty][innerProperty];
254+
255+
// when
256+
let valid = validate(example);
257+
258+
// then
259+
o(valid).equals(false);
260+
o(
261+
validate.errors.some(
262+
(error) =>
263+
error.instancePath === `/linz:asset_summaries/${outerProperty}` &&
264+
error.message === `must have required property '${innerProperty}'`,
265+
),
266+
).equals(true)(JSON.stringify(validate.errors));
267+
}
268+
}
269+
},
270+
);
271+
272+
o("Asset summary created/updated with invalid 'minimum'/'maximum' value should fail validation", async () => {
273+
for (const outerProperty of ['created', 'updated']) {
274+
for (const innerProperty of ['minimum', 'maximum']) {
275+
// given
276+
const example = JSON.parse(await fs.readFile(examplePath));
277+
example['linz:asset_summaries'][outerProperty][innerProperty] = '1999-01-01T00:00:00';
278+
279+
// when
280+
let valid = validate(example);
281+
282+
// then
283+
o(valid).equals(false);
284+
o(
285+
validate.errors.some(
286+
(error) =>
287+
error.instancePath === `/linz:asset_summaries/${outerProperty}/${innerProperty}` &&
288+
error.message === 'must match pattern "(\\+00:00|Z)$"',
289+
),
290+
).equals(true)(JSON.stringify(validate.errors));
291+
}
323292
}
324293
});
325294

326-
o("Asset summary created with invalid 'maximum' value should fail validation", async () => {
327-
// given
328-
const example = JSON.parse(await fs.readFile(examplePath));
329-
example['linz:asset_summaries']['created']['maximum'] = '1999-01-01T00:00:00';
330-
331-
// when
332-
let valid = validate(example);
333-
334-
// then
335-
o(valid).equals(false);
336-
o(
337-
validate.errors.some(
338-
(error) =>
339-
error.instancePath === '/linz:asset_summaries/created/maximum' &&
340-
error.message === 'must match pattern "(\\+00:00|Z)$"',
341-
),
342-
).equals(true)(JSON.stringify(validate.errors));
343-
});
344-
345295
o("Example without the mandatory 'linz:history' field should fail validation", async () => {
346296
// given
347297
const example = JSON.parse(await fs.readFile(examplePath));

0 commit comments

Comments
 (0)