import expect from '@kbn/expect' ; import { isRight } from 'fp-ts/lib/Either' ; import { FtrProviderContext } from '../../../ftr_provider_context' ; import { DynamicSettingsType , DynamicSettings , } from '../../../../../plugins/uptime/common/runtime_types' ; import { DYNAMIC_SETTINGS_DEFAULTS , API_URLS , } from '../../../../../plugins/uptime/common/constants' ; export default function ( { getService } ) { const supertest = getService ( 'supertest' ) ; describe ( 'dynamic settings' , ( ) => { it ( 'returns the defaults when no user settings have been saved' , async ( ) => { const apiResponse = await supertest . get ( API_URLS . DYNAMIC_SETTINGS ) ; expect ( apiResponse . body ) . to . eql ( DYNAMIC_SETTINGS_DEFAULTS ) ; expect ( isRight ( DynamicSettingsType . decode ( apiResponse . body ) ) ) . to . be . ok ( ) ; } ) ; it ( 'can change the settings' , async ( ) => { const newSettings = { heartbeatIndices : 'myIndex1*' , certAgeThreshold : 15 , certExpirationThreshold : 5 , defaultConnectors : [ ] , } ; const postResponse = await supertest . post ( API_URLS . DYNAMIC_SETTINGS ) . set ( 'kbn-xsrf' , 'true' ) . send ( newSettings ) ; expect ( postResponse . body ) . to . eql ( { success : true } ) ; expect ( postResponse . status ) . to . eql ( 200 ) ; const getResponse = await supertest . get ( API_URLS . DYNAMIC_SETTINGS ) ; expect ( getResponse . body ) . to . eql ( newSettings ) ; expect ( isRight ( DynamicSettingsType . decode ( getResponse . body ) ) ) . to . be . ok ( ) ; } ) ; } ) ; }