Skip to content

Commit 3b40f03

Browse files
authored
fix: Enforce minItems (#191)
* refactor: Add some whitespace between tests * fix: Enforce `aerial-photo:run` minimum items The `minItems` property was in the wrong place. * fix: Enforce `aerial-photo:anomalies` minimum items The `minItems` property was in the wrong place. * fix: Enforce `film:id` minimum items The `minItems` property was in the wrong place. * fix: Enforce `film:physical_condition` minimum items The `minItems` property was in the wrong place. * fix: Enforce `film:physical_size` minimum items The `minItems` property was in the wrong place. * fix: Enforce `platform` minimum items The `minItems` property was in the wrong place. * fix: Enforce `mission` minimum items The `minItems` property was in the wrong place. * fix: Enforce `instruments` minimum items The `minItems` property was in the wrong place. * fix: Remove un-enforced `proj:epsg` minimum items The `minItems` property was in the wrong place, but we don't actually want to enforce it because `proj:epsg` can be `null`.
1 parent 1c6808c commit 3b40f03

File tree

6 files changed

+188
-26
lines changed

6 files changed

+188
-26
lines changed

extensions/aerial-photo/schema.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@
101101
"aerial-photo:run": {
102102
"type": "array",
103103
"items": {
104-
"type": "string",
105-
"minItems": 1
106-
}
104+
"type": "string"
105+
},
106+
"minItems": 1
107107
},
108108
"aerial-photo:sequence_number": {
109109
"type": "object",
@@ -150,9 +150,9 @@
150150
"aerial-photo:anomalies": {
151151
"type": "array",
152152
"items": {
153-
"type": "string",
154-
"minItems": 1
155-
}
153+
"type": "string"
154+
},
155+
"minItems": 1
156156
}
157157
}
158158
}

extensions/aerial-photo/tests/aerial_photo_collection.test.js

+39
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ o.spec('Aerial Photo Extension Collection', () => {
2929
// then
3030
o(valid).equals(true)(JSON.stringify(validate.errors, null, 2));
3131
});
32+
3233
o("Summaries with no 'aerial-photo:run' property should fail validation", async () => {
3334
// given
3435
const example = JSON.parse(await fs.readFile(examplePath));
@@ -46,6 +47,44 @@ o.spec('Aerial Photo Extension Collection', () => {
4647
),
4748
).equals(true)(JSON.stringify(validate.errors));
4849
});
50+
51+
o("Summaries with empty 'aerial-photo:anomalies' list should fail validation", async () => {
52+
// given
53+
const example = JSON.parse(await fs.readFile(examplePath));
54+
example.summaries['aerial-photo:anomalies'] = [];
55+
56+
// when
57+
let valid = validate(example);
58+
59+
// then
60+
o(valid).equals(false);
61+
o(
62+
validate.errors.some(
63+
(error) =>
64+
error.instancePath === '/summaries/aerial-photo:anomalies' &&
65+
error.message === 'must NOT have fewer than 1 items',
66+
),
67+
).equals(true)(JSON.stringify(validate.errors));
68+
});
69+
70+
o("Summaries with empty 'aerial-photo:run' list should fail validation", async () => {
71+
// given
72+
const example = JSON.parse(await fs.readFile(examplePath));
73+
example.summaries['aerial-photo:run'] = [];
74+
75+
// when
76+
let valid = validate(example);
77+
78+
// then
79+
o(valid).equals(false);
80+
o(
81+
validate.errors.some(
82+
(error) =>
83+
error.instancePath === '/summaries/aerial-photo:run' && error.message === 'must NOT have fewer than 1 items',
84+
),
85+
).equals(true)(JSON.stringify(validate.errors));
86+
});
87+
4988
o("Summaries with no 'aerial-photo:sequence_number' property should fail validation", async () => {
5089
// given
5190
const example = JSON.parse(await fs.readFile(examplePath));

extensions/film/schema.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@
9797
"film:id": {
9898
"type": "array",
9999
"items": {
100-
"type": "string",
101-
"minItems": 1
102-
}
100+
"type": "string"
101+
},
102+
"minItems": 1
103103
},
104104
"film:negative_sequence": {
105105
"type": "object",
@@ -118,16 +118,16 @@
118118
"film:physical_condition": {
119119
"type": "array",
120120
"items": {
121-
"type": "string",
122-
"minItems": 1
123-
}
121+
"type": "string"
122+
},
123+
"minItems": 1
124124
},
125125
"film:physical_size": {
126126
"type": "array",
127127
"items": {
128-
"type": "string",
129-
"minItems": 1
130-
}
128+
"type": "string"
129+
},
130+
"minItems": 1
131131
}
132132
}
133133
}

extensions/film/tests/film_collection.test.js

+57
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ o.spec('Film Extension Collection', () => {
2929
// then
3030
o(valid).equals(true)(JSON.stringify(validate.errors, null, 2));
3131
});
32+
3233
o("Summaries with no 'film:id' property should fail validation", async () => {
3334
// given
3435
const example = JSON.parse(await fs.readFile(examplePath));
@@ -45,6 +46,62 @@ o.spec('Film Extension Collection', () => {
4546
),
4647
).equals(true)(JSON.stringify(validate.errors));
4748
});
49+
50+
o("Summaries with empty 'film:id' list should fail validation", async () => {
51+
// given
52+
const example = JSON.parse(await fs.readFile(examplePath));
53+
example.summaries['film:id'] = [];
54+
55+
// when
56+
let valid = validate(example);
57+
58+
// then
59+
o(valid).equals(false);
60+
o(
61+
validate.errors.some(
62+
(error) => error.instancePath === '/summaries/film:id' && error.message === 'must NOT have fewer than 1 items',
63+
),
64+
).equals(true)(JSON.stringify(validate.errors));
65+
});
66+
67+
o("Summaries with empty 'film:physical_condition' list should fail validation", async () => {
68+
// given
69+
const example = JSON.parse(await fs.readFile(examplePath));
70+
example.summaries['film:physical_condition'] = [];
71+
72+
// when
73+
let valid = validate(example);
74+
75+
// then
76+
o(valid).equals(false);
77+
o(
78+
validate.errors.some(
79+
(error) =>
80+
error.instancePath === '/summaries/film:physical_condition' &&
81+
error.message === 'must NOT have fewer than 1 items',
82+
),
83+
).equals(true)(JSON.stringify(validate.errors));
84+
});
85+
86+
o("Summaries with empty 'film:physical_size' list should fail validation", async () => {
87+
// given
88+
const example = JSON.parse(await fs.readFile(examplePath));
89+
example.summaries['film:physical_size'] = [];
90+
91+
// when
92+
let valid = validate(example);
93+
94+
// then
95+
o(valid).equals(false);
96+
o(
97+
validate.errors.some(
98+
(error) =>
99+
error.instancePath === '/summaries/film:physical_size' &&
100+
error.message === 'must NOT have fewer than 1 items',
101+
),
102+
).equals(true)(JSON.stringify(validate.errors));
103+
});
104+
48105
o("Summaries with no 'film:negative_sequence' property should fail validation", async () => {
49106
// given
50107
const example = JSON.parse(await fs.readFile(examplePath));

extensions/historical-imagery/schema.json

+10-11
Original file line numberDiff line numberDiff line change
@@ -164,29 +164,28 @@
164164
"platform": {
165165
"type": "array",
166166
"items": {
167-
"type": "string",
168-
"minItems": 1
169-
}
167+
"type": "string"
168+
},
169+
"minItems": 1
170170
},
171171
"mission": {
172172
"type": "array",
173173
"items": {
174-
"type": "string",
175-
"minItems": 1
176-
}
174+
"type": "string"
175+
},
176+
"minItems": 1
177177
},
178178
"instruments": {
179179
"type": "array",
180180
"items": {
181-
"type": "string",
182-
"minItems": 1
183-
}
181+
"type": "string"
182+
},
183+
"minItems": 1
184184
},
185185
"proj:epsg": {
186186
"type": "array",
187187
"items": {
188-
"type": "integer",
189-
"minItems": 1
188+
"type": "integer"
190189
}
191190
}
192191
}

extensions/historical-imagery/tests/historical-imagery_collection.test.js

+67
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ o.spec('Historical Imagery Extension Collection', () => {
8080
).equals(true)(JSON.stringify(validate.errors));
8181
}
8282
});
83+
8384
o("Summaries with no 'platform' property should fail validation", async () => {
8485
// given
8586
const example = JSON.parse(await fs.readFile(examplePath));
@@ -96,6 +97,24 @@ o.spec('Historical Imagery Extension Collection', () => {
9697
),
9798
).equals(true)(JSON.stringify(validate.errors));
9899
});
100+
101+
o("Summaries with empty 'platform' list should fail validation", async () => {
102+
// given
103+
const example = JSON.parse(await fs.readFile(examplePath));
104+
example.summaries.platform = [];
105+
106+
// when
107+
let valid = validate(example);
108+
109+
// then
110+
o(valid).equals(false);
111+
o(
112+
validate.errors.some(
113+
(error) => error.instancePath === '/summaries/platform' && error.message === 'must NOT have fewer than 1 items',
114+
),
115+
).equals(true)(JSON.stringify(validate.errors));
116+
});
117+
99118
o("Summaries with no 'mission' property should fail validation", async () => {
100119
// given
101120
const example = JSON.parse(await fs.readFile(examplePath));
@@ -112,6 +131,42 @@ o.spec('Historical Imagery Extension Collection', () => {
112131
),
113132
).equals(true)(JSON.stringify(validate.errors));
114133
});
134+
135+
o("Summaries with empty 'mission' list should fail validation", async () => {
136+
// given
137+
const example = JSON.parse(await fs.readFile(examplePath));
138+
example.summaries.mission = [];
139+
140+
// when
141+
let valid = validate(example);
142+
143+
// then
144+
o(valid).equals(false);
145+
o(
146+
validate.errors.some(
147+
(error) => error.instancePath === '/summaries/mission' && error.message === 'must NOT have fewer than 1 items',
148+
),
149+
).equals(true)(JSON.stringify(validate.errors));
150+
});
151+
152+
o("Summaries with empty 'instruments' list should fail validation", async () => {
153+
// given
154+
const example = JSON.parse(await fs.readFile(examplePath));
155+
example.summaries.instruments = [];
156+
157+
// when
158+
let valid = validate(example);
159+
160+
// then
161+
o(valid).equals(false);
162+
o(
163+
validate.errors.some(
164+
(error) =>
165+
error.instancePath === '/summaries/instruments' && error.message === 'must NOT have fewer than 1 items',
166+
),
167+
).equals(true)(JSON.stringify(validate.errors));
168+
});
169+
115170
o("Summaries with no 'proj:epsg' property should fail validation", async () => {
116171
// given
117172
const example = JSON.parse(await fs.readFile(examplePath));
@@ -128,4 +183,16 @@ o.spec('Historical Imagery Extension Collection', () => {
128183
),
129184
).equals(true)(JSON.stringify(validate.errors));
130185
});
186+
187+
o("Summaries with empty 'proj:epsg' list should pass validation", async () => {
188+
// given
189+
const example = JSON.parse(await fs.readFile(examplePath));
190+
example.summaries['proj:epsg'] = [];
191+
192+
// when
193+
let valid = validate(example);
194+
195+
// then
196+
o(valid).equals(true);
197+
});
131198
});

0 commit comments

Comments
 (0)