import { MockRouter , mockRequestHandler , mockDependencies } from '../../__mocks__' ; import { registerOrgEnableRoleMappingsRoute , registerOrgRoleMappingsRoute , registerOrgRoleMappingRoute , registerOrgUserRoute , } from './role_mappings' ; describe ( 'role mappings routes' , ( ) => { describe ( 'POST /internal/workplace_search/org/role_mappings/enable_role_based_access' , ( ) => { let mockRouter ; beforeEach ( ( ) => { jest . clearAllMocks ( ) ; mockRouter = new MockRouter ( { method : 'post' , path : '/internal/workplace_search/org/role_mappings/enable_role_based_access' , } ) ; registerOrgEnableRoleMappingsRoute ( { ... mockDependencies , router : mockRouter . router , } ) ; } ) ; it ( 'creates a request handler' , ( ) => { expect ( mockRequestHandler . createRequest ) . toHaveBeenCalledWith ( { path : '/ws/org/role_mappings/enable_role_based_access' , } ) ; } ) ; } ) ; describe ( 'GET /internal/workplace_search/org/role_mappings' , ( ) => { let mockRouter ; beforeEach ( ( ) => { jest . clearAllMocks ( ) ; mockRouter = new MockRouter ( { method : 'get' , path : '/internal/workplace_search/org/role_mappings' , } ) ; registerOrgRoleMappingsRoute ( { ... mockDependencies , router : mockRouter . router , } ) ; } ) ; it ( 'creates a request handler' , ( ) => { expect ( mockRequestHandler . createRequest ) . toHaveBeenCalledWith ( { path : '/ws/org/role_mappings/collection' , } ) ; } ) ; } ) ; describe ( 'POST /internal/workplace_search/org/role_mappings' , ( ) => { let mockRouter ; beforeEach ( ( ) => { jest . clearAllMocks ( ) ; mockRouter = new MockRouter ( { method : 'post' , path : '/internal/workplace_search/org/role_mappings' , } ) ; registerOrgRoleMappingsRoute ( { ... mockDependencies , router : mockRouter . router , } ) ; } ) ; it ( 'creates a request handler' , ( ) => { expect ( mockRequestHandler . createRequest ) . toHaveBeenCalledWith ( { path : '/ws/org/role_mappings/collection' , } ) ; } ) ; } ) ; describe ( 'PUT /internal/workplace_search/org/role_mappings/{id}' , ( ) => { let mockRouter ; beforeEach ( ( ) => { jest . clearAllMocks ( ) ; mockRouter = new MockRouter ( { method : 'put' , path : '/internal/workplace_search/org/role_mappings/{id}' , } ) ; registerOrgRoleMappingRoute ( { ... mockDependencies , router : mockRouter . router , } ) ; } ) ; it ( 'creates a request handler' , ( ) => { expect ( mockRequestHandler . createRequest ) . toHaveBeenCalledWith ( { path : '/ws/org/role_mappings/:id' , } ) ; } ) ; } ) ; describe ( 'DELETE /internal/workplace_search/org/role_mappings/{id}' , ( ) => { let mockRouter ; beforeEach ( ( ) => { jest . clearAllMocks ( ) ; mockRouter = new MockRouter ( { method : 'delete' , path : '/internal/workplace_search/org/role_mappings/{id}' , } ) ; registerOrgRoleMappingRoute ( { ... mockDependencies , router : mockRouter . router , } ) ; } ) ; it ( 'creates a request handler' , ( ) => { expect ( mockRequestHandler . createRequest ) . toHaveBeenCalledWith ( { path : '/ws/org/role_mappings/:id' , } ) ; } ) ; } ) ; describe ( 'POST /internal/workplace_search/org/single_user_role_mapping' , ( ) => { let mockRouter ; beforeEach ( ( ) => { jest . clearAllMocks ( ) ; mockRouter = new MockRouter ( { method : 'post' , path : '/internal/workplace_search/org/single_user_role_mapping' , } ) ; registerOrgUserRoute ( { ... mockDependencies , router : mockRouter . router , } ) ; } ) ; describe ( 'validates' , ( ) => { it ( 'correctly' , ( ) => { const request = { body : { roleMapping : { groups : [ 'foo' , 'bar' ] , roleType : 'admin' , allGroups : true , id : '123asf' , } , elasticsearchUser : { username : 'user2@elastic.co' , email : 'user2' , } , } , } ; mockRouter . shouldValidate ( request ) ; } ) ; it ( 'missing required fields' , ( ) => { const request = { body : { } } ; mockRouter . shouldThrow ( request ) ; } ) ; } ) ; it ( 'creates a request handler' , ( ) => { expect ( mockRequestHandler . createRequest ) . toHaveBeenCalledWith ( { path : '/ws/org/role_mappings/upsert_single_user_role_mapping' , } ) ; } ) ; } ) ; } ) ;