import { getServices , chance } from './lib' ; export function docMissingSuite ( ) { beforeEach ( async ( ) => { const { osdServer , callCluster } = getServices ( ) ; await osdServer . inject ( { method : 'POST' , url : '/api/opensearch-dashboards/settings/defaultIndex' , payload : { value : 'abc' } , } ) ; await callCluster ( 'deleteByQuery' , { index : osdServer . config . get ( 'opensearchDashboards.index' ) , body : { query : { match_all : { } } , } , } ) ; } ) ; describe ( 'get route' , ( ) => { it ( 'creates doc, returns a 200 with settings' , async ( ) => { const { osdServer } = getServices ( ) ; const { statusCode , result } = await osdServer . inject ( { method : 'GET' , url : '/api/opensearch-dashboards/settings' , } ) ; expect ( statusCode ) . toBe ( 200 ) ; expect ( result ) . toMatchObject ( { settings : { buildNum : { userValue : expect . any ( Number ) , } , foo : { userValue : 'bar' , isOverridden : true , } , } , } ) ; } ) ; } ) ; describe ( 'set route' , ( ) => { it ( 'creates doc, returns a 200 with value set' , async ( ) => { const { osdServer } = getServices ( ) ; const defaultIndex = chance . word ( ) ; const { statusCode , result } = await osdServer . inject ( { method : 'POST' , url : '/api/opensearch-dashboards/settings/defaultIndex' , payload : { value : defaultIndex } , } ) ; expect ( statusCode ) . toBe ( 200 ) ; expect ( result ) . toMatchObject ( { settings : { buildNum : { userValue : expect . any ( Number ) , } , defaultIndex : { userValue : defaultIndex , } , foo : { userValue : 'bar' , isOverridden : true , } , } , } ) ; } ) ; } ) ; describe ( 'setMany route' , ( ) => { it ( 'creates doc, returns 200 with updated values' , async ( ) => { const { osdServer } = getServices ( ) ; const defaultIndex = chance . word ( ) ; const { statusCode , result } = await osdServer . inject ( { method : 'POST' , url : '/api/opensearch-dashboards/settings' , payload : { changes : { defaultIndex } , } , } ) ; expect ( statusCode ) . toBe ( 200 ) ; expect ( result ) . toMatchObject ( { settings : { buildNum : { userValue : expect . any ( Number ) , } , defaultIndex : { userValue : defaultIndex , } , foo : { userValue : 'bar' , isOverridden : true , } , } , } ) ; } ) ; } ) ; describe ( 'delete route' , ( ) => { it ( 'creates doc, returns a 200 with just buildNum' , async ( ) => { const { osdServer } = getServices ( ) ; const { statusCode , result } = await osdServer . inject ( { method : 'DELETE' , url : '/api/opensearch-dashboards/settings/defaultIndex' , } ) ; expect ( statusCode ) . toBe ( 200 ) ; expect ( result ) . toMatchObject ( { settings : { buildNum : { userValue : expect . any ( Number ) , } , foo : { userValue : 'bar' , isOverridden : true , } , } , } ) ; } ) ; } ) ; }