Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 45 additions & 43 deletions json-schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,7 @@
"const": "Feature"
},
"properties": {
"allOf": [
{
"$ref": "#/definitions/require_any_field"
},
{
"$ref": "#/definitions/fields"
}
]
"$ref": "#/definitions/fields"
},
"assets": {
"$comment": "This validates the fields in Item Assets, but does not require them.",
Expand Down Expand Up @@ -75,9 +68,7 @@
"allOf": [
{
"$ref": "#/definitions/stac_extensions"
}
],
"anyOf": [
},
{
"$comment": "Requires at least one provider to contain processing fields.",
"type": "object",
Expand Down Expand Up @@ -108,7 +99,7 @@
}
},
{
"$ref": "#/definitions/require_any_field"
"$ref": "#/definitions/fields"
}
]
}
Expand All @@ -118,50 +109,70 @@
{
"$comment": "Requires at least one asset to contain processing fields.",
"type": "object",
"required": [
"assets"
],
"properties": {
"assets": {
"type": "object",
"not": {
"additionalProperties": {
"not": {
"$ref": "#/definitions/require_any_field"
}
}
"additionalProperties": {
"$ref": "#/definitions/fields"
}
}
}
},
{
"$comment": "Requires at least one item asset definition to contain processing fields.",
"type": "object",
"required": [
"item_assets"
],
"properties": {
"item_assets": {
"type": "object",
"not": {
"additionalProperties": {
"not": {
"$ref": "#/definitions/require_any_field"
}
}
"additionalProperties": {
"$ref": "#/definitions/fields"
}
}
}
},
{
"type": "object",
"$comment": "Requires at least one summary to be a processing field.",
"required": [
"summaries"
],
"properties": {
"summaries": {
"$ref": "#/definitions/require_any_field"
"type": "object",
"properties": {
"processing:expression": {
"type": "array",
"items": {
"$ref": "#/definitions/fields/properties/processing:expression"
},
"minItems": 1
},
"processing:facility": {
"type": "array",
"items": {
"$ref": "#/definitions/fields/properties/processing:facility"
},
"minItems": 1
},
"processing:level": {
"type": "array",
"items": {
"$ref": "#/definitions/fields/properties/processing:level"
},
"minItems": 1
},
"processing:lineage": {
"type": "array",
"items": {
"$ref": "#/definitions/fields/properties/processing:lineage"
},
"minItems": 1
},
"processing:software": {
"type": "array",
"items": {
"$ref": "#/definitions/fields/properties/processing:software"
},
"minItems": 1
}
}
}
}
}
Expand Down Expand Up @@ -200,15 +211,6 @@
}
}
},
"require_any_field": {
"anyOf": [
{"type": "object", "required": ["processing:expression"]},
{"type": "object", "required": ["processing:lineage"]},
{"type": "object", "required": ["processing:level"]},
{"type": "object", "required": ["processing:facility"]},
{"type": "object", "required": ["processing:software"]}
]
},
"fields": {
"type": "object",
"properties": {
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
"name": "stac-extensions",
"version": "1.1.0",
"scripts": {
"test": "npm run check-markdown && npm run check-examples",
"test": "jest && npm run check-markdown && npm run check-examples",
"check-markdown": "remark . -f -r .github/remark.yaml",
"check-examples": "stac-node-validator . --lint --verbose --schemaMap https://stac-extensions.github.io/processing/v1.1.0/schema.json=./json-schema/schema.json",
"format-examples": "stac-node-validator . --format --schemaMap https://stac-extensions.github.io/processing/v1.1.0/schema.json=./json-schema/schema.json"
},
"type": "module",
"dependencies": {
"ajv": "^8.8.2",
"jest": "^27.4.5",
"remark-cli": "^8.0.0",
"remark-lint": "^7.0.0",
"remark-lint-no-html": "^2.0.0",
Expand Down
179 changes: 179 additions & 0 deletions tests/collection.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
const {join} = require('path');
const {promises} = require('fs');
const {AjvOptions, rootDirectory, schemaPath} = require('./validation.js');
const ajv = new (require('ajv'))(AjvOptions);

const examplePath = join(rootDirectory, 'examples/collection.json');

let validate;
beforeAll(async () => {
const data = JSON.parse(await promises.readFile(schemaPath));
validate = await ajv.compileAsync(data);
});

let example;
beforeEach(async () => {
example = JSON.parse(await promises.readFile(examplePath));
});

describe('Collection example', () => {
it('should pass validation', async () => {
let valid = validate(example);

expect(valid).toBeTruthy();
});

it('should fail validation when providers processing expression is invalid', async () => {
// given
example.providers[0]['processing:expression'] = null;

// when
let valid = validate(example);

// then
expect(valid).toBeFalsy();
expect(
validate.errors.some(
(error) =>
error.instancePath === '/providers/0/processing:expression'
&& error.message === 'must be object',
)
).toBeTruthy();
});

it('should fail validation when asset processing expression is invalid', async () => {
// given
example.assets = {
'example': {
'href': 'https://example.org/file.xyz',
'processing:expression': null,
}
};

// when
let valid = validate(example);

// then
expect(valid).toBeFalsy();
expect(
validate.errors.some(
(error) =>
error.instancePath === '/assets/example/processing:expression'
&& error.message === 'must be object',
)
).toBeTruthy();
});

it('should fail validation when item asset processing expression is invalid', async () => {
// given
example.item_assets = {
'example': {
'href': 'https://example.org/file.xyz',
'processing:expression': null,
}
};

// when
let valid = validate(example);

// then
expect(valid).toBeFalsy();
expect(
validate.errors.some(
(error) =>
error.instancePath === '/item_assets/example/processing:expression'
&& error.message === 'must be object',
)
).toBeTruthy();
});

it('should fail validation when summary processing expression is invalid', async () => {
// given
example.summaries['processing:expression'] = null;

// when
let valid = validate(example);

// then
expect(valid).toBeFalsy();
expect(
validate.errors.some(
(error) =>
error.instancePath === '/summaries/processing:expression'
&& error.message === 'must be array',
)
).toBeTruthy();
});

it('should fail validation when summary processing facility is invalid', async () => {
// given
example.summaries['processing:facility'] = null;

// when
let valid = validate(example);

// then
expect(valid).toBeFalsy();
expect(
validate.errors.some(
(error) =>
error.instancePath === '/summaries/processing:facility'
&& error.message === 'must be array',
)
).toBeTruthy();
});

it('should fail validation when summary processing level is invalid', async () => {
// given
example.summaries['processing:level'] = null;

// when
let valid = validate(example);

// then
expect(valid).toBeFalsy();
expect(
validate.errors.some(
(error) =>
error.instancePath === '/summaries/processing:level'
&& error.message === 'must be array',
)
).toBeTruthy();
});

it('should fail validation when summary processing lineage is invalid', async () => {
// given
example.summaries['processing:lineage'] = null;

// when
let valid = validate(example);

// then
expect(valid).toBeFalsy();
expect(
validate.errors.some(
(error) =>
error.instancePath === '/summaries/processing:lineage'
&& error.message === 'must be array',
)
).toBeTruthy();
});

it('should fail validation when summary processing software is invalid', async () => {
// given
example.summaries['processing:software'] = null;

// when
let valid = validate(example);

// then
expect(valid).toBeFalsy();
expect(
validate.errors.some(
(error) =>
error.instancePath === '/summaries/processing:software'
&& error.message === 'must be array',
)
).toBeTruthy();
});
});
43 changes: 43 additions & 0 deletions tests/item.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const {join} = require('path');
const {promises} = require('fs');
const {AjvOptions, rootDirectory, schemaPath} = require('./validation.js');
const ajv = new (require('ajv'))(AjvOptions);

const examplePath = join(rootDirectory, 'examples/item.json');

let validate;
beforeAll(async () => {
const data = JSON.parse(await promises.readFile(schemaPath));
validate = await ajv.compileAsync(data);
});

let example;
beforeEach(async () => {
example = JSON.parse(await promises.readFile(examplePath));
});

describe('Item example', () => {
it('should pass validation', async () => {
let valid = validate(example);

expect(valid).toBeTruthy();
});

it('should fail validation when processing expression is invalid', async () => {
// given
example.properties = {'processing:expression': null};

// when
let valid = validate(example);

// then
expect(valid).toBeFalsy();
expect(
validate.errors.some(
(error) =>
error.instancePath === '/properties/processing:expression'
&& error.message === 'must be object',
)
).toBeTruthy();
});
});
Loading