@@ -14,7 +14,6 @@ import {
1414 RulesSchema ,
1515 checkTypeDependents ,
1616 getDependents ,
17- addSavedId ,
1817 addQueryFields ,
1918 addTimelineTitle ,
2019 addMlFields ,
@@ -85,42 +84,25 @@ describe('rules_schema', () => {
8584 expect ( message . schema ) . toEqual ( { } ) ;
8685 } ) ;
8786
88- test ( 'it should validate a type of "saved_query" with a "saved_id" dependent' , ( ) => {
87+
88+ test ( 'it should validate a type of "saved_query" without a "saved_id" dependent' , ( ) => {
8989 const payload = getRulesSchemaMock ( ) ;
9090 payload . type = 'saved_query' ;
91- payload . saved_id = 'save id 123' ;
9291
9392 const decoded = rulesSchema . decode ( payload ) ;
9493 const checked = exactCheck ( payload , decoded ) ;
9594 const message = pipe ( checked , foldLeftRight ) ;
96- const expected = getRulesSchemaMock ( ) ;
9795
96+ const expected = getRulesSchemaMock ( ) ;
9897 expected . type = 'saved_query' ;
99- expected . saved_id = 'save id 123' ;
10098
10199 expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ ] ) ;
102100 expect ( message . schema ) . toEqual ( expected ) ;
103101 } ) ;
104102
105- test ( 'it should NOT validate a type of "saved_query" without a "saved_id" dependent' , ( ) => {
106- const payload = getRulesSchemaMock ( ) ;
107- payload . type = 'saved_query' ;
108- delete payload . saved_id ;
109-
110- const decoded = rulesSchema . decode ( payload ) ;
111- const checked = exactCheck ( payload , decoded ) ;
112- const message = pipe ( checked , foldLeftRight ) ;
113-
114- expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [
115- 'Invalid value "undefined" supplied to "saved_id"' ,
116- ] ) ;
117- expect ( message . schema ) . toEqual ( { } ) ;
118- } ) ;
119-
120103 test ( 'it should NOT validate a type of "saved_query" when it has extra data' , ( ) => {
121104 const payload : RulesSchema & { invalid_extra_data ?: string } = getRulesSchemaMock ( ) ;
122105 payload . type = 'saved_query' ;
123- payload . saved_id = 'save id 123' ;
124106 payload . invalid_extra_data = 'invalid_extra_data' ;
125107
126108 const decoded = rulesSchema . decode ( payload ) ;
@@ -187,35 +169,7 @@ describe('rules_schema', () => {
187169 expect ( message . schema ) . toEqual ( { } ) ;
188170 } ) ;
189171
190- test ( 'it should NOT validate a type of "saved_query" with a "saved_id" dependent and a "timeline_title" but there is NOT a "timeline_id"' , ( ) => {
191- const payload = getRulesSchemaMock ( ) ;
192- payload . saved_id = 'some saved id' ;
193- payload . type = 'saved_query' ;
194- payload . timeline_title = 'some timeline title' ;
195-
196- const decoded = rulesSchema . decode ( payload ) ;
197- const checked = exactCheck ( payload , decoded ) ;
198- const message = pipe ( checked , foldLeftRight ) ;
199-
200- expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ 'invalid keys "timeline_title"' ] ) ;
201- expect ( message . schema ) . toEqual ( { } ) ;
202- } ) ;
203-
204- test ( 'it should NOT validate a type of "saved_query" with a "saved_id" dependent and a "timeline_id" but there is NOT a "timeline_title"' , ( ) => {
205- const payload = getRulesSchemaMock ( ) ;
206- payload . saved_id = 'some saved id' ;
207- payload . type = 'saved_query' ;
208- payload . timeline_id = 'some timeline id' ;
209-
210- const decoded = rulesSchema . decode ( payload ) ;
211- const checked = exactCheck ( payload , decoded ) ;
212- const message = pipe ( checked , foldLeftRight ) ;
213-
214- expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [
215- 'Invalid value "undefined" supplied to "timeline_title"' ,
216- ] ) ;
217- expect ( message . schema ) . toEqual ( { } ) ;
218- } ) ;
172+
219173
220174 describe ( 'checkTypeDependents' , ( ) => {
221175 test ( 'it should validate a type of "query" without anything extra' , ( ) => {
@@ -257,42 +211,24 @@ describe('rules_schema', () => {
257211 expect ( message . schema ) . toEqual ( { } ) ;
258212 } ) ;
259213
260- test ( 'it should validate a type of "saved_query" with a "saved_id" dependent' , ( ) => {
214+ test ( 'it should validate a type of "saved_query" without a "saved_id" dependent' , ( ) => {
261215 const payload = getRulesSchemaMock ( ) ;
262216 payload . type = 'saved_query' ;
263- payload . saved_id = 'save id 123' ;
264217
265218 const decoded = checkTypeDependents ( payload ) ;
266219 const checked = exactCheck ( payload , decoded ) ;
267220 const message = pipe ( checked , foldLeftRight ) ;
268221 const expected = getRulesSchemaMock ( ) ;
269222
270223 expected . type = 'saved_query' ;
271- expected . saved_id = 'save id 123' ;
272224
273225 expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ ] ) ;
274226 expect ( message . schema ) . toEqual ( expected ) ;
275227 } ) ;
276228
277- test ( 'it should NOT validate a type of "saved_query" without a "saved_id" dependent' , ( ) => {
278- const payload = getRulesSchemaMock ( ) ;
279- payload . type = 'saved_query' ;
280- delete payload . saved_id ;
281-
282- const decoded = checkTypeDependents ( payload ) ;
283- const checked = exactCheck ( payload , decoded ) ;
284- const message = pipe ( checked , foldLeftRight ) ;
285-
286- expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [
287- 'Invalid value "undefined" supplied to "saved_id"' ,
288- ] ) ;
289- expect ( message . schema ) . toEqual ( { } ) ;
290- } ) ;
291-
292229 test ( 'it should NOT validate a type of "saved_query" when it has extra data' , ( ) => {
293230 const payload : RulesSchema & { invalid_extra_data ?: string } = getRulesSchemaMock ( ) ;
294231 payload . type = 'saved_query' ;
295- payload . saved_id = 'save id 123' ;
296232 payload . invalid_extra_data = 'invalid_extra_data' ;
297233
298234 const decoded = checkTypeDependents ( payload ) ;
@@ -358,36 +294,6 @@ describe('rules_schema', () => {
358294 expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ 'invalid keys "timeline_title"' ] ) ;
359295 expect ( message . schema ) . toEqual ( { } ) ;
360296 } ) ;
361-
362- test ( 'it should NOT validate a type of "saved_query" with a "saved_id" dependent and a "timeline_title" but there is NOT a "timeline_id"' , ( ) => {
363- const payload = getRulesSchemaMock ( ) ;
364- payload . saved_id = 'some saved id' ;
365- payload . type = 'saved_query' ;
366- payload . timeline_title = 'some timeline title' ;
367-
368- const decoded = checkTypeDependents ( payload ) ;
369- const checked = exactCheck ( payload , decoded ) ;
370- const message = pipe ( checked , foldLeftRight ) ;
371-
372- expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ 'invalid keys "timeline_title"' ] ) ;
373- expect ( message . schema ) . toEqual ( { } ) ;
374- } ) ;
375-
376- test ( 'it should NOT validate a type of "saved_query" with a "saved_id" dependent and a "timeline_id" but there is NOT a "timeline_title"' , ( ) => {
377- const payload = getRulesSchemaMock ( ) ;
378- payload . saved_id = 'some saved id' ;
379- payload . type = 'saved_query' ;
380- payload . timeline_id = 'some timeline id' ;
381-
382- const decoded = checkTypeDependents ( payload ) ;
383- const checked = exactCheck ( payload , decoded ) ;
384- const message = pipe ( checked , foldLeftRight ) ;
385-
386- expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [
387- 'Invalid value "undefined" supplied to "timeline_title"' ,
388- ] ) ;
389- expect ( message . schema ) . toEqual ( { } ) ;
390- } ) ;
391297 } ) ;
392298
393299 describe ( 'getDependents' , ( ) => {
@@ -433,25 +339,8 @@ describe('rules_schema', () => {
433339 expect ( message . schema ) . toEqual ( { } ) ;
434340 } ) ;
435341
436- test ( 'it should validate a type of "saved_query" with a "saved_id" dependent' , ( ) => {
437- const payload = getRulesSchemaMock ( ) ;
438- payload . type = 'saved_query' ;
439- payload . saved_id = 'save id 123' ;
440-
441- const dependents = getDependents ( payload ) ;
442- const decoded = dependents . decode ( payload ) ;
443- const checked = exactCheck ( payload , decoded ) ;
444- const message = pipe ( checked , foldLeftRight ) ;
445- const expected = getRulesSchemaMock ( ) ;
446-
447- expected . type = 'saved_query' ;
448- expected . saved_id = 'save id 123' ;
449-
450- expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ ] ) ;
451- expect ( message . schema ) . toEqual ( expected ) ;
452- } ) ;
453342
454- test ( 'it should NOT validate a type of "saved_query" without a "saved_id" dependent' , ( ) => {
343+ test ( 'it should validate a type of "saved_query" without a "saved_id" dependent' , ( ) => {
455344 const payload = getRulesSchemaMock ( ) ;
456345 payload . type = 'saved_query' ;
457346 delete payload . saved_id ;
@@ -461,16 +350,13 @@ describe('rules_schema', () => {
461350 const checked = exactCheck ( payload , decoded ) ;
462351 const message = pipe ( checked , foldLeftRight ) ;
463352
464- expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [
465- 'Invalid value "undefined" supplied to "saved_id"' ,
466- ] ) ;
467- expect ( message . schema ) . toEqual ( { } ) ;
353+ expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ ] ) ;
354+ expect ( message . schema ) . toEqual ( payload ) ;
468355 } ) ;
469356
470357 test ( 'it should NOT validate a type of "saved_query" when it has extra data' , ( ) => {
471358 const payload : RulesSchema & { invalid_extra_data ?: string } = getRulesSchemaMock ( ) ;
472359 payload . type = 'saved_query' ;
473- payload . saved_id = 'save id 123' ;
474360 payload . invalid_extra_data = 'invalid_extra_data' ;
475361
476362 const dependents = getDependents ( payload ) ;
@@ -542,20 +428,6 @@ describe('rules_schema', () => {
542428 expect ( message . schema ) . toEqual ( { } ) ;
543429 } ) ;
544430
545- test ( 'it should NOT validate a type of "saved_query" with a "saved_id" dependent and a "timeline_title" but there is NOT a "timeline_id"' , ( ) => {
546- const payload = getRulesSchemaMock ( ) ;
547- payload . saved_id = 'some saved id' ;
548- payload . type = 'saved_query' ;
549- payload . timeline_title = 'some timeline title' ;
550-
551- const decoded = checkTypeDependents ( payload ) ;
552- const checked = exactCheck ( payload , decoded ) ;
553- const message = pipe ( checked , foldLeftRight ) ;
554-
555- expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ 'invalid keys "timeline_title"' ] ) ;
556- expect ( message . schema ) . toEqual ( { } ) ;
557- } ) ;
558-
559431 test ( 'it should NOT validate a type of "saved_query" with a "saved_id" dependent and a "timeline_id" but there is NOT a "timeline_title"' , ( ) => {
560432 const payload = getRulesSchemaMock ( ) ;
561433 payload . saved_id = 'some saved id' ;
@@ -645,18 +517,6 @@ describe('rules_schema', () => {
645517 } ) ;
646518 } ) ;
647519
648- describe ( 'addSavedId' , ( ) => {
649- test ( 'should return empty array if not given a type of "saved_query"' , ( ) => {
650- const emptyArray = addSavedId ( { type : 'query' } ) ;
651- const expected : t . Mixed [ ] = [ ] ;
652- expect ( emptyArray ) . toEqual ( expected ) ;
653- } ) ;
654-
655- test ( 'should array of size 1 given a "saved_query"' , ( ) => {
656- const array = addSavedId ( { type : 'saved_query' } ) ;
657- expect ( array . length ) . toEqual ( 1 ) ;
658- } ) ;
659- } ) ;
660520
661521 describe ( 'addTimelineTitle' , ( ) => {
662522 test ( 'should return empty array if not given a timeline_id' , ( ) => {
@@ -762,9 +622,9 @@ describe('rules_schema', () => {
762622 expect ( fields ) . toEqual ( expected ) ;
763623 } ) ;
764624
765- test ( 'should return nine (9 ) fields for a rule of type "threat_match"' , ( ) => {
625+ test ( 'should return eight (8 ) fields for a rule of type "threat_match"' , ( ) => {
766626 const fields = addThreatMatchFields ( { type : 'threat_match' } ) ;
767- expect ( fields . length ) . toEqual ( 9 ) ;
627+ expect ( fields . length ) . toEqual ( 8 ) ;
768628 } ) ;
769629 } ) ;
770630
0 commit comments