import expect from '@kbn/expect' ; import { HTTPFields , MonitorFields } from '../../../../../plugins/uptime/common/runtime_types' ; import { FtrProviderContext } from '../../../ftr_provider_context' ; import { API_URLS } from '../../../../../plugins/uptime/common/constants' ; import { getFixtureJson } from './helper/get_fixture_json' ; export default function ( { getService } ) { describe ( '[DELETE] /internal/uptime/service/monitors' , ( ) => { const supertest = getService ( 'supertest' ) ; let _httpMonitorJson ; let httpMonitorJson ; const saveMonitor = async ( monitor ) => { const res = await supertest . post ( API_URLS . SYNTHETICS_MONITORS ) . set ( 'kbn-xsrf' , 'true' ) . send ( monitor ) ; return res . body ; } ; before ( ( ) => { _httpMonitorJson = getFixtureJson ( 'http_monitor' ) ; } ) ; beforeEach ( ( ) => { httpMonitorJson = _httpMonitorJson ; } ) ; it ( 'deletes monitor by id' , async ( ) => { const { id : monitorId } = await saveMonitor ( httpMonitorJson as MonitorFields ) ; const deleteResponse = await supertest . delete ( API_URLS . SYNTHETICS_MONITORS + '/' + monitorId ) . set ( 'kbn-xsrf' , 'true' ) ; expect ( deleteResponse . body ) . eql ( monitorId ) ; await supertest . get ( API_URLS . SYNTHETICS_MONITORS + '/' + monitorId ) . expect ( 404 ) ; } ) ; it ( 'returns 404 if monitor id is not found' , async ( ) => { const invalidMonitorId = 'invalid-id' ; const expected404Message = `Monitor id ${ invalidMonitorId } not found!` ; const deleteResponse = await supertest . delete ( API_URLS . SYNTHETICS_MONITORS + '/' + invalidMonitorId ) . set ( 'kbn-xsrf' , 'true' ) ; expect ( deleteResponse . status ) . eql ( 404 ) ; expect ( deleteResponse . body . message ) . eql ( expected404Message ) ; } ) ; it ( 'validates empty monitor id' , async ( ) => { const emptyMonitorId = '' ; await supertest . delete ( API_URLS . SYNTHETICS_MONITORS + '/' + emptyMonitorId ) . set ( 'kbn-xsrf' , 'true' ) . expect ( 404 ) ; } ) ; it ( 'validates param length for sanity' , async ( ) => { const veryLargeMonId = new Array ( 1050 ) . fill ( '1' ) . join ( '' ) ; await supertest . delete ( API_URLS . SYNTHETICS_MONITORS + '/' + veryLargeMonId ) . set ( 'kbn-xsrf' , 'true' ) . expect ( 400 ) ; } ) ; } ) ; }