44 * you may not use this file except in compliance with the Elastic License.
55 */
66
7- import {
8- createRulesBulkSchema ,
9- CreateRulesBulkSchema ,
10- CreateRulesBulkSchemaDecoded ,
11- } from './create_rules_bulk_schema' ;
7+ import { createRulesBulkSchema , CreateRulesBulkSchema } from './create_rules_bulk_schema' ;
128import { exactCheck } from '../../../exact_check' ;
139import { foldLeftRight } from '../../../test_utils' ;
14- import {
15- getCreateRulesSchemaMock ,
16- getCreateRulesSchemaDecodedMock ,
17- } from './create_rules_schema.mock' ;
1810import { formatErrors } from '../../../format_errors' ;
19- import { CreateRulesSchema } from './create_rules_schema ' ;
11+ import { getCreateRulesSchemaMock } from './rule_schemas.mock ' ;
2012
2113// only the basics of testing are here.
22- // see: create_rules_schema .test.ts for the bulk of the validation tests
14+ // see: rule_schemas .test.ts for the bulk of the validation tests
2315// this just wraps createRulesSchema in an array
2416describe ( 'create_rules_bulk_schema' , ( ) => {
2517 test ( 'can take an empty array and validate it' , ( ) => {
@@ -38,13 +30,16 @@ describe('create_rules_bulk_schema', () => {
3830 const decoded = createRulesBulkSchema . decode ( payload ) ;
3931 const checked = exactCheck ( payload , decoded ) ;
4032 const output = foldLeftRight ( checked ) ;
41- expect ( formatErrors ( output . errors ) ) . toEqual ( [
42- 'Invalid value "undefined" supplied to "description"' ,
43- 'Invalid value "undefined" supplied to "risk_score"' ,
44- 'Invalid value "undefined" supplied to "name"' ,
45- 'Invalid value "undefined" supplied to "severity"' ,
46- 'Invalid value "undefined" supplied to "type"' ,
47- ] ) ;
33+ expect ( formatErrors ( output . errors ) ) . toContain (
34+ 'Invalid value "undefined" supplied to "description"'
35+ ) ;
36+ expect ( formatErrors ( output . errors ) ) . toContain (
37+ 'Invalid value "undefined" supplied to "risk_score"'
38+ ) ;
39+ expect ( formatErrors ( output . errors ) ) . toContain ( 'Invalid value "undefined" supplied to "name"' ) ;
40+ expect ( formatErrors ( output . errors ) ) . toContain (
41+ 'Invalid value "undefined" supplied to "severity"'
42+ ) ;
4843 expect ( output . schema ) . toEqual ( { } ) ;
4944 } ) ;
5045
@@ -55,7 +50,7 @@ describe('create_rules_bulk_schema', () => {
5550 const checked = exactCheck ( payload , decoded ) ;
5651 const output = foldLeftRight ( checked ) ;
5752 expect ( formatErrors ( output . errors ) ) . toEqual ( [ ] ) ;
58- expect ( output . schema ) . toEqual ( [ getCreateRulesSchemaDecodedMock ( ) ] ) ;
53+ expect ( output . schema ) . toEqual ( payload ) ;
5954 } ) ;
6055
6156 test ( 'two array elements do validate' , ( ) => {
@@ -65,10 +60,7 @@ describe('create_rules_bulk_schema', () => {
6560 const checked = exactCheck ( payload , decoded ) ;
6661 const output = foldLeftRight ( checked ) ;
6762 expect ( formatErrors ( output . errors ) ) . toEqual ( [ ] ) ;
68- expect ( output . schema ) . toEqual ( [
69- getCreateRulesSchemaDecodedMock ( ) ,
70- getCreateRulesSchemaDecodedMock ( ) ,
71- ] ) ;
63+ expect ( output . schema ) . toEqual ( payload ) ;
7264 } ) ;
7365
7466 test ( 'single array element with a missing value (risk_score) will not validate' , ( ) => {
@@ -137,7 +129,7 @@ describe('create_rules_bulk_schema', () => {
137129 } ) ;
138130
139131 test ( 'two array elements where the first is invalid (extra key and value) but the second is valid will not validate' , ( ) => {
140- const singleItem : CreateRulesSchema & { madeUpValue : string } = {
132+ const singleItem = {
141133 ...getCreateRulesSchemaMock ( ) ,
142134 madeUpValue : 'something' ,
143135 } ;
@@ -152,8 +144,8 @@ describe('create_rules_bulk_schema', () => {
152144 } ) ;
153145
154146 test ( 'two array elements where the second is invalid (extra key and value) but the first is valid will not validate' , ( ) => {
155- const singleItem : CreateRulesSchema = getCreateRulesSchemaMock ( ) ;
156- const secondItem : CreateRulesSchema & { madeUpValue : string } = {
147+ const singleItem = getCreateRulesSchemaMock ( ) ;
148+ const secondItem = {
157149 ...getCreateRulesSchemaMock ( ) ,
158150 madeUpValue : 'something' ,
159151 } ;
@@ -167,11 +159,11 @@ describe('create_rules_bulk_schema', () => {
167159 } ) ;
168160
169161 test ( 'two array elements where both are invalid (extra key and value) will not validate' , ( ) => {
170- const singleItem : CreateRulesSchema & { madeUpValue : string } = {
162+ const singleItem = {
171163 ...getCreateRulesSchemaMock ( ) ,
172164 madeUpValue : 'something' ,
173165 } ;
174- const secondItem : CreateRulesSchema & { madeUpValue : string } = {
166+ const secondItem = {
175167 ...getCreateRulesSchemaMock ( ) ,
176168 madeUpValue : 'something' ,
177169 } ;
@@ -184,28 +176,6 @@ describe('create_rules_bulk_schema', () => {
184176 expect ( output . schema ) . toEqual ( { } ) ;
185177 } ) ;
186178
187- test ( 'The default for "from" will be "now-6m"' , ( ) => {
188- const { from, ...withoutFrom } = getCreateRulesSchemaMock ( ) ;
189- const payload : CreateRulesBulkSchema = [ withoutFrom ] ;
190-
191- const decoded = createRulesBulkSchema . decode ( payload ) ;
192- const checked = exactCheck ( payload , decoded ) ;
193- const output = foldLeftRight ( checked ) ;
194- expect ( formatErrors ( output . errors ) ) . toEqual ( [ ] ) ;
195- expect ( ( output . schema as CreateRulesBulkSchemaDecoded ) [ 0 ] . from ) . toEqual ( 'now-6m' ) ;
196- } ) ;
197-
198- test ( 'The default for "to" will be "now"' , ( ) => {
199- const { to, ...withoutTo } = getCreateRulesSchemaMock ( ) ;
200- const payload : CreateRulesBulkSchema = [ withoutTo ] ;
201-
202- const decoded = createRulesBulkSchema . decode ( payload ) ;
203- const checked = exactCheck ( payload , decoded ) ;
204- const output = foldLeftRight ( checked ) ;
205- expect ( formatErrors ( output . errors ) ) . toEqual ( [ ] ) ;
206- expect ( ( output . schema as CreateRulesBulkSchemaDecoded ) [ 0 ] . to ) . toEqual ( 'now' ) ;
207- } ) ;
208-
209179 test ( 'You cannot set the severity to a value other than low, medium, high, or critical' , ( ) => {
210180 const badSeverity = { ...getCreateRulesSchemaMock ( ) , severity : 'madeup' } ;
211181 const payload = [ badSeverity ] ;
@@ -226,9 +196,7 @@ describe('create_rules_bulk_schema', () => {
226196 const checked = exactCheck ( payload , decoded ) ;
227197 const output = foldLeftRight ( checked ) ;
228198 expect ( formatErrors ( output . errors ) ) . toEqual ( [ ] ) ;
229- expect ( output . schema ) . toEqual ( [
230- { ...getCreateRulesSchemaDecodedMock ( ) , note : '# test markdown' } ,
231- ] ) ;
199+ expect ( output . schema ) . toEqual ( payload ) ;
232200 } ) ;
233201
234202 test ( 'You can set "note" to an empty string' , ( ) => {
@@ -238,10 +206,10 @@ describe('create_rules_bulk_schema', () => {
238206 const checked = exactCheck ( payload , decoded ) ;
239207 const output = foldLeftRight ( checked ) ;
240208 expect ( formatErrors ( output . errors ) ) . toEqual ( [ ] ) ;
241- expect ( output . schema ) . toEqual ( [ { ... getCreateRulesSchemaDecodedMock ( ) , note : '' } ] ) ;
209+ expect ( output . schema ) . toEqual ( payload ) ;
242210 } ) ;
243211
244- test ( 'You can set "note" to anything other than string' , ( ) => {
212+ test ( 'You cant set "note" to anything other than string' , ( ) => {
245213 const payload = [
246214 {
247215 ...getCreateRulesSchemaMock ( ) ,
@@ -259,26 +227,4 @@ describe('create_rules_bulk_schema', () => {
259227 ] ) ;
260228 expect ( output . schema ) . toEqual ( { } ) ;
261229 } ) ;
262-
263- test ( 'The default for "actions" will be an empty array' , ( ) => {
264- const { actions, ...withoutActions } = getCreateRulesSchemaMock ( ) ;
265- const payload : CreateRulesBulkSchema = [ withoutActions ] ;
266-
267- const decoded = createRulesBulkSchema . decode ( payload ) ;
268- const checked = exactCheck ( payload , decoded ) ;
269- const output = foldLeftRight ( checked ) ;
270- expect ( formatErrors ( output . errors ) ) . toEqual ( [ ] ) ;
271- expect ( ( output . schema as CreateRulesBulkSchemaDecoded ) [ 0 ] . actions ) . toEqual ( [ ] ) ;
272- } ) ;
273-
274- test ( 'The default for "throttle" will be null' , ( ) => {
275- const { throttle, ...withoutThrottle } = getCreateRulesSchemaMock ( ) ;
276- const payload : CreateRulesBulkSchema = [ withoutThrottle ] ;
277-
278- const decoded = createRulesBulkSchema . decode ( payload ) ;
279- const checked = exactCheck ( payload , decoded ) ;
280- const output = foldLeftRight ( checked ) ;
281- expect ( formatErrors ( output . errors ) ) . toEqual ( [ ] ) ;
282- expect ( ( output . schema as CreateRulesBulkSchemaDecoded ) [ 0 ] . throttle ) . toEqual ( null ) ;
283- } ) ;
284230} ) ;
0 commit comments