import expect from '@kbn/expect' ; import { DETECTION_ENGINE_RULES_URL } from '../../../../plugins/security_solution/common/constants' ; import { FtrProviderContext } from '../../common/ftr_provider_context' ; import { createRule , createSignalsIndex , deleteAllAlerts , deleteSignalsIndex , getComplexRule , getComplexRuleOutput , getSimpleRule , getSimpleRuleOutput , removeServerGeneratedProperties , } from '../../utils' ; export default ( { getService } ) : void => { const supertest = getService ( 'supertest' ) ; const log = getService ( 'log' ) ; describe ( 'find_rules' , ( ) => { beforeEach ( async ( ) => { await createSignalsIndex ( supertest , log ) ; } ) ; afterEach ( async ( ) => { await deleteSignalsIndex ( supertest , log ) ; await deleteAllAlerts ( supertest , log ) ; } ) ; it ( 'should return an empty find body correctly if no rules are loaded' , async ( ) => { const { body } = await supertest . get ( `${ DETECTION_ENGINE_RULES_URL }/_find` ) . set ( 'kbn-xsrf' , 'true' ) . send ( ) . expect ( 200 ) ; expect ( body ) . to . eql ( { data : [ ] , page : 1 , perPage : 20 , total : 0 , } ) ; } ) ; it ( 'should return a single rule when a single rule is loaded from a find with defaults added' , async ( ) => { await createRule ( supertest , log , getSimpleRule ( ) ) ; const { body } = await supertest . get ( `${ DETECTION_ENGINE_RULES_URL }/_find` ) . set ( 'kbn-xsrf' , 'true' ) . send ( ) . expect ( 200 ) ; body . data = [ removeServerGeneratedProperties ( body . data [ 0 ] ) ] ; expect ( body ) . to . eql ( { data : [ getSimpleRuleOutput ( ) ] , page : 1 , perPage : 20 , total : 1 , } ) ; } ) ; it ( 'should return a single rule when a single rule is loaded from a find with everything for the rule added' , async ( ) => { await supertest . post ( DETECTION_ENGINE_RULES_URL ) . set ( 'kbn-xsrf' , 'true' ) . send ( getComplexRule ( ) ) . expect ( 200 ) ; const { body } = await supertest . get ( `${ DETECTION_ENGINE_RULES_URL }/_find` ) . set ( 'kbn-xsrf' , 'true' ) . send ( ) . expect ( 200 ) ; body . data = [ removeServerGeneratedProperties ( body . data [ 0 ] ) ] ; expect ( body ) . to . eql ( { data : [ getComplexRuleOutput ( ) ] , page : 1 , perPage : 20 , total : 1 , } ) ; } ) ; } ) ; } ;