import { migratorInstanceMock } from './migrate.test.mocks' ; import * as osdTestServer from '../../../../test_helpers/osd_server' ; describe ( 'SavedObjects /_migrate endpoint' , ( ) => { let root ; beforeEach ( async ( ) => { root = osdTestServer . createRoot ( { migrations : { skip : true } , plugins : { initialize : false } } ) ; await root . setup ( ) ; await root . start ( ) ; migratorInstanceMock . runMigrations . mockClear ( ) ; } , 30000 ) ; afterEach ( async ( ) => { await root . shutdown ( ) ; } ) ; it ( 'calls runMigrations on the migrator with rerun=true when accessed' , async ( ) => { await osdTestServer . request . post ( root , '/internal/saved_objects/_migrate' ) . send ( { } ) . expect ( 200 ) ; expect ( migratorInstanceMock . runMigrations ) . toHaveBeenCalledTimes ( 1 ) ; expect ( migratorInstanceMock . runMigrations ) . toHaveBeenCalledWith ( { rerun : true } ) ; } ) ; it ( 'calls runMigrations multiple time when multiple access' , async ( ) => { await osdTestServer . request . post ( root , '/internal/saved_objects/_migrate' ) . send ( { } ) . expect ( 200 ) ; expect ( migratorInstanceMock . runMigrations ) . toHaveBeenCalledTimes ( 1 ) ; await osdTestServer . request . post ( root , '/internal/saved_objects/_migrate' ) . send ( { } ) . expect ( 200 ) ; expect ( migratorInstanceMock . runMigrations ) . toHaveBeenCalledTimes ( 2 ) ; } ) ; } ) ;