Skip to content

Commit f928599

Browse files
committed
Test for validating an invalid catalog #20
1 parent 685b63b commit f928599

File tree

2 files changed

+55
-6
lines changed

2 files changed

+55
-6
lines changed

tests/cli.test.js

+48-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
const app = require('../index');
22

3-
let consoleErrSpy, consoleInfSpy, consoleLogSpy, mockExit;
3+
let consoleErrSpy, consoleWarnSpy, consoleInfSpy, consoleLogSpy, mockExit;
44
const initString = 'STAC Node Validator v1.1.0';
55

66
beforeEach(() => {
77
mockExit = jest.spyOn(process, 'exit').mockImplementation();
88
consoleInfSpy = jest.spyOn(console, 'info').mockImplementation();
99
consoleLogSpy = jest.spyOn(console, 'log').mockImplementation();
10+
consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation();
1011
consoleErrSpy = jest.spyOn(console, 'error').mockImplementation();
1112
});
1213

@@ -29,15 +30,17 @@ describe('Running without parameters or configuration', () => {
2930
});
3031
});
3132

32-
describe('Running with a configured simple catalog', () => {
33+
describe('Running with a configured valid catalog', () => {
34+
let files = ['tests/catalog.json'];
35+
3336
it('Should return exit code 0', async () => {
34-
await app({files: ['tests/catalog.json']});
37+
await app({files});
3538

3639
expect(mockExit).toHaveBeenCalledWith(0);
3740
});
3841

3942
it('Should print informational messages', async () => {
40-
await app({files: ['tests/catalog.json']});
43+
await app({files});
4144

4245
expect(consoleLogSpy.mock.calls[0][0]).toContain(initString);
4346
expect(consoleLogSpy.mock.calls[1][0]).toContain('tests/catalog.json');
@@ -46,8 +49,47 @@ describe('Running with a configured simple catalog', () => {
4649
expect(consoleInfSpy.mock.calls[2][0]).toContain('Invalid: 0');
4750
});
4851

49-
it('Should not print an error message', async () => {
50-
await app({files: ['tests/catalog.json']});
52+
it('Should not print a critical error message', async () => {
53+
await app({files});
54+
55+
expect(consoleErrSpy).not.toHaveBeenCalled();
56+
});
57+
});
58+
59+
describe('Running with a configured invalid catalog', () => {
60+
let files = ['tests/invalid-catalog.json'];
61+
it('Should return exit code 1', async () => {
62+
await app({files});
63+
64+
expect(mockExit).toHaveBeenCalledWith(1);
65+
});
66+
67+
it('Should print informational messages', async () => {
68+
await app({files});
69+
70+
expect(consoleLogSpy.mock.calls[0][0]).toContain(initString);
71+
expect(consoleLogSpy.mock.calls[1][0]).toContain('tests/invalid-catalog.json');
72+
expect(consoleInfSpy.mock.calls[0][0]).toContain('Files: 1');
73+
expect(consoleInfSpy.mock.calls[1][0]).toContain('Valid: 0');
74+
expect(consoleInfSpy.mock.calls[2][0]).toContain('Invalid: 1');
75+
});
76+
77+
it('Should print validation warnings', async () => {
78+
await app({files});
79+
80+
console.log(consoleWarnSpy);
81+
82+
expect(consoleWarnSpy.mock.calls[0][0]).toEqual([{
83+
"instancePath": "",
84+
"keyword": "required",
85+
"message": "must have required property 'links'",
86+
"params": {"missingProperty": "links"},
87+
"schemaPath": "#/required"
88+
}]);
89+
});
90+
91+
it('Should not print a critical error message', async () => {
92+
await app({files});
5193

5294
expect(consoleErrSpy).not.toHaveBeenCalled();
5395
});

tests/invalid-catalog.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"stac_version": "1.0.0",
3+
"id": "example",
4+
"type": "Catalog",
5+
"title": "Example Catalog",
6+
"description": "A minimal example for tests"
7+
}

0 commit comments

Comments
 (0)