1
1
const app = require ( '../index' ) ;
2
2
3
- let consoleErrSpy , consoleInfSpy , consoleLogSpy , mockExit ;
3
+ let consoleErrSpy , consoleWarnSpy , consoleInfSpy , consoleLogSpy , mockExit ;
4
4
const initString = 'STAC Node Validator v1.1.0' ;
5
5
6
6
beforeEach ( ( ) => {
7
7
mockExit = jest . spyOn ( process , 'exit' ) . mockImplementation ( ) ;
8
8
consoleInfSpy = jest . spyOn ( console , 'info' ) . mockImplementation ( ) ;
9
9
consoleLogSpy = jest . spyOn ( console , 'log' ) . mockImplementation ( ) ;
10
+ consoleWarnSpy = jest . spyOn ( console , 'warn' ) . mockImplementation ( ) ;
10
11
consoleErrSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( ) ;
11
12
} ) ;
12
13
@@ -29,15 +30,17 @@ describe('Running without parameters or configuration', () => {
29
30
} ) ;
30
31
} ) ;
31
32
32
- describe ( 'Running with a configured simple catalog' , ( ) => {
33
+ describe ( 'Running with a configured valid catalog' , ( ) => {
34
+ let files = [ 'tests/catalog.json' ] ;
35
+
33
36
it ( 'Should return exit code 0' , async ( ) => {
34
- await app ( { files : [ 'tests/catalog.json' ] } ) ;
37
+ await app ( { files} ) ;
35
38
36
39
expect ( mockExit ) . toHaveBeenCalledWith ( 0 ) ;
37
40
} ) ;
38
41
39
42
it ( 'Should print informational messages' , async ( ) => {
40
- await app ( { files : [ 'tests/catalog.json' ] } ) ;
43
+ await app ( { files} ) ;
41
44
42
45
expect ( consoleLogSpy . mock . calls [ 0 ] [ 0 ] ) . toContain ( initString ) ;
43
46
expect ( consoleLogSpy . mock . calls [ 1 ] [ 0 ] ) . toContain ( 'tests/catalog.json' ) ;
@@ -46,8 +49,47 @@ describe('Running with a configured simple catalog', () => {
46
49
expect ( consoleInfSpy . mock . calls [ 2 ] [ 0 ] ) . toContain ( 'Invalid: 0' ) ;
47
50
} ) ;
48
51
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} ) ;
51
93
52
94
expect ( consoleErrSpy ) . not . toHaveBeenCalled ( ) ;
53
95
} ) ;
0 commit comments