import * as osdTestServer from '../../../test_helpers/osd_server' ; import { Root } from '../../root' ; let opensearchServer ; describe ( 'default route provider' , ( ) => { let root ; beforeAll ( async ( ) => { const { startOpenSearch } = osdTestServer . createTestServers ( { adjustTimeout : ( t ) => jest . setTimeout ( t ) , } ) ; opensearchServer = await startOpenSearch ( ) ; root = osdTestServer . createRootWithCorePlugins ( { server : { basePath : '/hello' , } , } ) ; await root . setup ( ) ; await root . start ( ) ; } ) ; afterAll ( async ( ) => { await osdTestServer . request . post ( root , '/api/opensearch-dashboards/settings/defaultRoute' ) . send ( { value : '/app/home' } ) ; await opensearchServer . stop ( ) ; await root . shutdown ( ) ; } ) ; beforeEach ( async ( ) => { await osdTestServer . request . post ( root , '/api/opensearch-dashboards/settings/defaultRoute' ) . send ( { value : '/app/home' } ) . expect ( 200 ) ; } ) ; it ( 'redirects to the configured default route respecting basePath' , async function ( ) { const { status , header } = await osdTestServer . request . get ( root , '/' ) ; expect ( status ) . toEqual ( 302 ) ; expect ( header ) . toMatchObject ( { location : '/hello/app/home' , } ) ; } ) ; it ( 'ignores invalid values' , async function ( ) { const invalidRoutes = [ 'http://not-your-opensearch-dashboards.com' , '///example.com' , '//example.com' , ' //example.com' , ] ; for ( const url of invalidRoutes ) { await osdTestServer . request . post ( root , '/api/opensearch-dashboards/settings/defaultRoute' ) . send ( { value : url } ) . expect ( 400 ) ; } const { status , header } = await osdTestServer . request . get ( root , '/' ) ; expect ( status ) . toEqual ( 302 ) ; expect ( header ) . toMatchObject ( { location : '/hello/app/home' , } ) ; } ) ; it ( 'consumes valid values' , async function ( ) { await osdTestServer . request . post ( root , '/api/opensearch-dashboards/settings/defaultRoute' ) . send ( { value : '/valid' } ) . expect ( 200 ) ; const { status , header } = await osdTestServer . request . get ( root , '/' ) ; expect ( status ) . toEqual ( 302 ) ; expect ( header ) . toMatchObject ( { location : '/hello/valid' , } ) ; } ) ; it ( 'replaces kibana_overview' , async function ( ) { await osdTestServer . request . post ( root , '/api/opensearch-dashboards/settings/defaultRoute' ) . send ( { value : '/kibana_overview' } ) . expect ( 200 ) ; const { status , header } = await osdTestServer . request . get ( root , '/' ) ; expect ( status ) . toEqual ( 302 ) ; expect ( header ) . toMatchObject ( { location : '/hello/opensearch_dashboards_overview' , } ) ; } ) ; it ( 'replaces kibana_overview#' , async function ( ) { await osdTestServer . request . post ( root , '/api/opensearch-dashboards/settings/defaultRoute' ) . send ( { value : '/kibana_overview#' } ) . expect ( 200 ) ; const { status , header } = await osdTestServer . request . get ( root , '/' ) ; expect ( status ) . toEqual ( 302 ) ; expect ( header ) . toMatchObject ( { location : '/hello/opensearch_dashboards_overview#' , } ) ; } ) ; it ( 'does not replace kibana' , async function ( ) { await osdTestServer . request . post ( root , '/api/opensearch-dashboards/settings/defaultRoute' ) . send ( { value : '/kibana' } ) . expect ( 200 ) ; const { status , header } = await osdTestServer . request . get ( root , '/' ) ; expect ( status ) . toEqual ( 302 ) ; expect ( header ) . toMatchObject ( { location : '/hello/kibana' , } ) ; } ) ; } ) ;