import { expectFixtureEql } from './helper/expect_fixture_eql' ; import { FtrProviderContext } from '../../../ftr_provider_context' ; import { makeChecksWithStatus , getChecksDateRange } from './helper/make_checks' ; import { API_URLS } from '../../../../../plugins/uptime/common/constants' ; export default function ( { getService } ) { const supertest = getService ( 'supertest' ) ; describe ( 'snapshot count' , ( ) => { const dateRangeStart = new Date ( ) . toISOString ( ) ; const dateRangeEnd = new Date ( ) . toISOString ( ) ; describe ( 'when no data is present' , async ( ) => { it ( 'returns a null snapshot' , async ( ) => { const apiResponse = await supertest . get ( API_URLS . SNAPSHOT_COUNT ) . query ( { dateRangeStart , dateRangeEnd , } ) ; expectFixtureEql ( apiResponse . body , 'snapshot_empty' ) ; } ) ; } ) ; describe ( 'when data is present' , async ( ) => { const numUpMonitors = 10 ; const numDownMonitors = 7 ; const numIps = 2 ; const checksPerMonitor = 5 ; const scheduleEvery = 10000 ; let dateRange ; [ true , false ] . forEach ( ( includeTimespan ) => { [ true , false ] . forEach ( ( includeObserver ) => { describe ( `with timespans=${ includeTimespan } and observer=${ includeObserver }` , async ( ) => { before ( async ( ) => { const promises = [ ] ; const mogrify = ( d ) => { if ( ! includeTimespan ) { delete d . monitor . timespan ; } if ( ! includeObserver ) { delete d . observer ; } return d ; } ; const makeMonitorChecks = async ( monitorId , status ) => { return makeChecksWithStatus ( getService ( 'es' ) , monitorId , checksPerMonitor , numIps , scheduleEvery , { } , status , mogrify ) ; } ; for ( let i = 0 ; i < numUpMonitors ; i ++ ) { promises . push ( makeMonitorChecks ( `up-${ i }` , 'up' ) ) ; } for ( let i = 0 ; i < numDownMonitors ; i ++ ) { promises . push ( makeMonitorChecks ( `down-${ i }` , 'down' ) ) ; } const allResults = await Promise . all ( promises ) ; dateRange = getChecksDateRange ( allResults ) ; } ) ; it ( 'will count all statuses correctly' , async ( ) => { const apiResponse = await supertest . get ( API_URLS . SNAPSHOT_COUNT ) . query ( { dateRangeStart : dateRange . start , dateRangeEnd : dateRange . end , } ) ; expectFixtureEql ( apiResponse . body , 'snapshot' ) ; } ) ; } ) ; } ) ; } ) ; } ) ; } ) ; }