import expect from '@kbn/expect' ; import { Spaces } from '../../scenarios' ; import { FtrProviderContext } from '../../../common/ftr_provider_context' ; import { AlertUtils , checkAAD , getUrlPrefix , getTestAlertData , ObjectRemover , } from '../../../common/lib' ; export default function createUnmuteTests ( { getService } ) { const supertestWithoutAuth = getService ( 'supertestWithoutAuth' ) ; describe ( 'unmute_all' , ( ) => { const objectRemover = new ObjectRemover ( supertestWithoutAuth ) ; const alertUtils = new AlertUtils ( { space : Spaces . space1 , supertestWithoutAuth } ) ; after ( ( ) => objectRemover . removeAll ( ) ) ; it ( 'should handle unmute alert request appropriately' , async ( ) => { const { body : createdAlert } = await supertestWithoutAuth . post ( `${ getUrlPrefix ( Spaces . space1 . id ) }/api/alerting/rule` ) . set ( 'kbn-xsrf' , 'foo' ) . send ( getTestAlertData ( { enabled : false } ) ) . expect ( 200 ) ; objectRemover . add ( Spaces . space1 . id , createdAlert . id , 'rule' , 'alerting' ) ; await alertUtils . muteAll ( createdAlert . id ) ; await alertUtils . unmuteAll ( createdAlert . id ) ; const { body : updatedAlert } = await supertestWithoutAuth . get ( `${ getUrlPrefix ( Spaces . space1 . id ) }/api/alerting/rule/${ createdAlert . id }` ) . set ( 'kbn-xsrf' , 'foo' ) . expect ( 200 ) ; expect ( updatedAlert . mute_all ) . to . eql ( false ) ; await checkAAD ( { supertest : supertestWithoutAuth , spaceId : Spaces . space1 . id , type : 'alert' , id : createdAlert . id , } ) ; } ) ; describe ( 'legacy' , ( ) => { it ( 'should handle unmute alert request appropriately' , async ( ) => { const { body : createdAlert } = await supertestWithoutAuth . post ( `${ getUrlPrefix ( Spaces . space1 . id ) }/api/alerting/rule` ) . set ( 'kbn-xsrf' , 'foo' ) . send ( getTestAlertData ( { enabled : false } ) ) . expect ( 200 ) ; objectRemover . add ( Spaces . space1 . id , createdAlert . id , 'rule' , 'alerting' ) ; await supertestWithoutAuth . post ( `${ getUrlPrefix ( Spaces . space1 . id ) }/api/alerts/alert/${ createdAlert . id }/_mute_all` ) . set ( 'kbn-xsrf' , 'foo' ) . expect ( 204 ) ; await supertestWithoutAuth . post ( `${ getUrlPrefix ( Spaces . space1 . id ) }/api/alerts/alert/${ createdAlert . id }/_unmute_all` ) . set ( 'kbn-xsrf' , 'foo' ) . expect ( 204 ) ; const { body : updatedAlert } = await supertestWithoutAuth . get ( `${ getUrlPrefix ( Spaces . space1 . id ) }/api/alerting/rule/${ createdAlert . id }` ) . set ( 'kbn-xsrf' , 'foo' ) . expect ( 200 ) ; expect ( updatedAlert . mute_all ) . to . eql ( false ) ; await checkAAD ( { supertest : supertestWithoutAuth , spaceId : Spaces . space1 . id , type : 'alert' , id : createdAlert . id , } ) ; } ) ; } ) ; } ) ; }