import { MockRouter , mockRequestHandler , mockDependencies } from '../../__mocks__' ; import { registerAnalyticsRoutes } from './analytics' ; describe ( 'analytics routes' , ( ) => { describe ( 'GET /internal/app_search/engines/{engineName}/analytics/queries' , ( ) => { let mockRouter ; beforeEach ( ( ) => { jest . clearAllMocks ( ) ; mockRouter = new MockRouter ( { method : 'get' , path : '/internal/app_search/engines/{engineName}/analytics/queries' , } ) ; registerAnalyticsRoutes ( { ... mockDependencies , router : mockRouter . router , } ) ; } ) ; it ( 'creates a request handler' , ( ) => { expect ( mockRequestHandler . createRequest ) . toHaveBeenCalledWith ( { path : '/as/engines/:engineName/analytics/queries' , } ) ; } ) ; describe ( 'validates' , ( ) => { it ( 'correctly without optional query params' , ( ) => { const request = { query : { } } ; mockRouter . shouldValidate ( request ) ; } ) ; it ( 'correctly with all optional query params' , ( ) => { const request = { query : { size : 20 , start : '1970-01-01' , end : '1970-01-02' , tag : 'some-tag' , } , } ; mockRouter . shouldValidate ( request ) ; } ) ; it ( 'incorrect types' , ( ) => { const request = { query : { start : 100 , size : '100' , } , } ; mockRouter . shouldThrow ( request ) ; } ) ; } ) ; } ) ; describe ( 'GET /internal/app_search/engines/{engineName}/analytics/queries/{query}' , ( ) => { let mockRouter ; beforeEach ( ( ) => { jest . clearAllMocks ( ) ; mockRouter = new MockRouter ( { method : 'get' , path : '/internal/app_search/engines/{engineName}/analytics/queries/{query}' , } ) ; registerAnalyticsRoutes ( { ... mockDependencies , router : mockRouter . router , } ) ; } ) ; it ( 'creates a request handler' , ( ) => { expect ( mockRequestHandler . createRequest ) . toHaveBeenCalledWith ( { path : '/as/engines/:engineName/analytics/query/:query' , } ) ; } ) ; describe ( 'validates' , ( ) => { it ( 'correctly without optional query params' , ( ) => { const request = { query : { } } ; mockRouter . shouldValidate ( request ) ; } ) ; it ( 'correctly with all optional query params' , ( ) => { const request = { query : { start : '1970-01-01' , end : '1970-01-02' , tag : 'some-tag' , } , } ; mockRouter . shouldValidate ( request ) ; } ) ; it ( 'incorrect types' , ( ) => { const request = { query : { start : 100 , tag : false , } , } ; mockRouter . shouldThrow ( request ) ; } ) ; } ) ; } ) ; } ) ;