-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Workplace Search] Add routes for settings (#87239)
- Loading branch information
1 parent
c69eaf8
commit 24748bf
Showing
3 changed files
with
196 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
x-pack/plugins/enterprise_search/server/routes/workplace_search/settings.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__'; | ||
|
||
import { | ||
registerOrgSettingsRoute, | ||
registerOrgSettingsCustomizeRoute, | ||
registerOrgSettingsOauthApplicationRoute, | ||
} from './settings'; | ||
|
||
describe('settings routes', () => { | ||
describe('GET /api/workplace_search/org/settings', () => { | ||
let mockRouter: MockRouter; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('creates a request handler', () => { | ||
mockRouter = new MockRouter({ | ||
method: 'get', | ||
path: '/api/workplace_search/org/settings', | ||
payload: 'params', | ||
}); | ||
|
||
registerOrgSettingsRoute({ | ||
...mockDependencies, | ||
router: mockRouter.router, | ||
}); | ||
|
||
mockRouter.callRoute({}); | ||
|
||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({ | ||
path: '/ws/org/settings', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('PUT /api/workplace_search/org/settings/customize', () => { | ||
let mockRouter: MockRouter; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('creates a request handler', () => { | ||
mockRouter = new MockRouter({ | ||
method: 'put', | ||
path: '/api/workplace_search/org/settings/customize', | ||
payload: 'body', | ||
}); | ||
|
||
registerOrgSettingsCustomizeRoute({ | ||
...mockDependencies, | ||
router: mockRouter.router, | ||
}); | ||
|
||
const mockRequest = { | ||
body: { | ||
name: 'foo', | ||
}, | ||
}; | ||
|
||
mockRouter.callRoute(mockRequest); | ||
|
||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({ | ||
path: '/ws/org/settings/customize', | ||
body: mockRequest.body, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('PUT /api/workplace_search/org/settings/oauth_application', () => { | ||
let mockRouter: MockRouter; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('creates a request handler', () => { | ||
mockRouter = new MockRouter({ | ||
method: 'put', | ||
path: '/api/workplace_search/org/settings/oauth_application', | ||
payload: 'body', | ||
}); | ||
|
||
registerOrgSettingsOauthApplicationRoute({ | ||
...mockDependencies, | ||
router: mockRouter.router, | ||
}); | ||
|
||
const mockRequest = { | ||
body: { | ||
oauth_application: { | ||
name: 'foo', | ||
confidential: true, | ||
redirect_uri: 'http://foo.bar', | ||
}, | ||
}, | ||
}; | ||
|
||
mockRouter.callRoute(mockRequest); | ||
|
||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({ | ||
path: '/ws/org/settings/oauth_application', | ||
body: mockRequest.body, | ||
}); | ||
}); | ||
}); | ||
}); |
80 changes: 80 additions & 0 deletions
80
x-pack/plugins/enterprise_search/server/routes/workplace_search/settings.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { schema } from '@kbn/config-schema'; | ||
|
||
import { RouteDependencies } from '../../plugin'; | ||
|
||
export function registerOrgSettingsRoute({ | ||
router, | ||
enterpriseSearchRequestHandler, | ||
}: RouteDependencies) { | ||
router.get( | ||
{ | ||
path: '/api/workplace_search/org/settings', | ||
validate: false, | ||
}, | ||
async (context, request, response) => { | ||
return enterpriseSearchRequestHandler.createRequest({ | ||
path: '/ws/org/settings', | ||
})(context, request, response); | ||
} | ||
); | ||
} | ||
|
||
export function registerOrgSettingsCustomizeRoute({ | ||
router, | ||
enterpriseSearchRequestHandler, | ||
}: RouteDependencies) { | ||
router.put( | ||
{ | ||
path: '/api/workplace_search/org/settings/customize', | ||
validate: { | ||
body: schema.object({ | ||
name: schema.string(), | ||
}), | ||
}, | ||
}, | ||
async (context, request, response) => { | ||
return enterpriseSearchRequestHandler.createRequest({ | ||
path: '/ws/org/settings/customize', | ||
body: request.body, | ||
})(context, request, response); | ||
} | ||
); | ||
} | ||
|
||
export function registerOrgSettingsOauthApplicationRoute({ | ||
router, | ||
enterpriseSearchRequestHandler, | ||
}: RouteDependencies) { | ||
router.put( | ||
{ | ||
path: '/api/workplace_search/org/settings/oauth_application', | ||
validate: { | ||
body: schema.object({ | ||
oauth_application: schema.object({ | ||
name: schema.string(), | ||
confidential: schema.boolean(), | ||
redirect_uri: schema.string(), | ||
}), | ||
}), | ||
}, | ||
}, | ||
async (context, request, response) => { | ||
return enterpriseSearchRequestHandler.createRequest({ | ||
path: '/ws/org/settings/oauth_application', | ||
body: request.body, | ||
})(context, request, response); | ||
} | ||
); | ||
} | ||
|
||
export const registerSettingsRoutes = (dependencies: RouteDependencies) => { | ||
registerOrgSettingsRoute(dependencies); | ||
registerOrgSettingsCustomizeRoute(dependencies); | ||
registerOrgSettingsOauthApplicationRoute(dependencies); | ||
}; |