From ec5981f126d97cd1d95591b1a95207dfe17cdb65 Mon Sep 17 00:00:00 2001 From: Constance Date: Wed, 4 Nov 2020 17:43:09 -0800 Subject: [PATCH] [Enterprise Search] Refactor product server route registrations to their own files/folders (#82663) * Refactor all AS & WS route registrations to their own file/folders * Remove WS in route registrations since the main fn is already specific * Cover index.ts files - super basic, leaves out assertions to avoid brittleness * Move WS group routes to index.ts --- .../enterprise_search/server/plugin.ts | 14 +++------ .../server/routes/app_search/index.test.ts | 16 ++++++++++ .../server/routes/app_search/index.ts | 17 +++++++++++ .../server/routes/workplace_search/groups.ts | 10 ------- .../routes/workplace_search/index.test.ts | 16 ++++++++++ .../server/routes/workplace_search/index.ts | 29 +++++++++++++++++++ .../routes/workplace_search/overview.test.ts | 4 +-- .../routes/workplace_search/overview.ts | 2 +- 8 files changed, 85 insertions(+), 23 deletions(-) create mode 100644 x-pack/plugins/enterprise_search/server/routes/app_search/index.test.ts create mode 100644 x-pack/plugins/enterprise_search/server/routes/app_search/index.ts create mode 100644 x-pack/plugins/enterprise_search/server/routes/workplace_search/index.test.ts create mode 100644 x-pack/plugins/enterprise_search/server/routes/workplace_search/index.ts diff --git a/x-pack/plugins/enterprise_search/server/plugin.ts b/x-pack/plugins/enterprise_search/server/plugin.ts index c9ffde49eb00a..292767c8fcdb9 100644 --- a/x-pack/plugins/enterprise_search/server/plugin.ts +++ b/x-pack/plugins/enterprise_search/server/plugin.ts @@ -39,14 +39,11 @@ import { registerConfigDataRoute } from './routes/enterprise_search/config_data' import { appSearchTelemetryType } from './saved_objects/app_search/telemetry'; import { registerTelemetryUsageCollector as registerASTelemetryUsageCollector } from './collectors/app_search/telemetry'; -import { registerEnginesRoute } from './routes/app_search/engines'; -import { registerCredentialsRoutes } from './routes/app_search/credentials'; -import { registerSettingsRoutes } from './routes/app_search/settings'; +import { registerAppSearchRoutes } from './routes/app_search'; import { workplaceSearchTelemetryType } from './saved_objects/workplace_search/telemetry'; import { registerTelemetryUsageCollector as registerWSTelemetryUsageCollector } from './collectors/workplace_search/telemetry'; -import { registerWSOverviewRoute } from './routes/workplace_search/overview'; -import { registerWSGroupRoutes } from './routes/workplace_search/groups'; +import { registerWorkplaceSearchRoutes } from './routes/workplace_search'; export interface PluginsSetup { usageCollection?: UsageCollectionSetup; @@ -127,11 +124,8 @@ export class EnterpriseSearchPlugin implements Plugin { const dependencies = { router, config, log, enterpriseSearchRequestHandler }; registerConfigDataRoute(dependencies); - registerEnginesRoute(dependencies); - registerCredentialsRoutes(dependencies); - registerSettingsRoutes(dependencies); - registerWSOverviewRoute(dependencies); - registerWSGroupRoutes(dependencies); + registerAppSearchRoutes(dependencies); + registerWorkplaceSearchRoutes(dependencies); /** * Bootstrap the routes, saved objects, and collector for telemetry diff --git a/x-pack/plugins/enterprise_search/server/routes/app_search/index.test.ts b/x-pack/plugins/enterprise_search/server/routes/app_search/index.test.ts new file mode 100644 index 0000000000000..ba1d90b4968fc --- /dev/null +++ b/x-pack/plugins/enterprise_search/server/routes/app_search/index.test.ts @@ -0,0 +1,16 @@ +/* + * 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 { mockDependencies, MockRouter } from '../../__mocks__'; + +import { registerAppSearchRoutes } from './'; + +describe('registerAppSearchRoutes', () => { + it('runs without errors', () => { + const mockRouter = new MockRouter({} as any); + registerAppSearchRoutes({ ...mockDependencies, router: mockRouter.router }); + }); +}); diff --git a/x-pack/plugins/enterprise_search/server/routes/app_search/index.ts b/x-pack/plugins/enterprise_search/server/routes/app_search/index.ts new file mode 100644 index 0000000000000..b10b8190d780c --- /dev/null +++ b/x-pack/plugins/enterprise_search/server/routes/app_search/index.ts @@ -0,0 +1,17 @@ +/* + * 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 { IRouteDependencies } from '../../plugin'; + +import { registerEnginesRoute } from './engines'; +import { registerCredentialsRoutes } from './credentials'; +import { registerSettingsRoutes } from './settings'; + +export const registerAppSearchRoutes = (dependencies: IRouteDependencies) => { + registerEnginesRoute(dependencies); + registerCredentialsRoutes(dependencies); + registerSettingsRoutes(dependencies); +}; diff --git a/x-pack/plugins/enterprise_search/server/routes/workplace_search/groups.ts b/x-pack/plugins/enterprise_search/server/routes/workplace_search/groups.ts index 21d08e5c8756b..cbb78cef5b66c 100644 --- a/x-pack/plugins/enterprise_search/server/routes/workplace_search/groups.ts +++ b/x-pack/plugins/enterprise_search/server/routes/workplace_search/groups.ts @@ -244,13 +244,3 @@ export function registerBoostsGroupRoute({ } ); } - -export function registerWSGroupRoutes(dependencies: IRouteDependencies) { - registerGroupsRoute(dependencies); - registerSearchGroupsRoute(dependencies); - registerGroupRoute(dependencies); - registerGroupUsersRoute(dependencies); - registerShareGroupRoute(dependencies); - registerAssignGroupRoute(dependencies); - registerBoostsGroupRoute(dependencies); -} diff --git a/x-pack/plugins/enterprise_search/server/routes/workplace_search/index.test.ts b/x-pack/plugins/enterprise_search/server/routes/workplace_search/index.test.ts new file mode 100644 index 0000000000000..c4c50ded0099f --- /dev/null +++ b/x-pack/plugins/enterprise_search/server/routes/workplace_search/index.test.ts @@ -0,0 +1,16 @@ +/* + * 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 { mockDependencies, MockRouter } from '../../__mocks__'; + +import { registerWorkplaceSearchRoutes } from './'; + +describe('registerWorkplaceSearchRoutes', () => { + it('runs without errors', () => { + const mockRouter = new MockRouter({} as any); + registerWorkplaceSearchRoutes({ ...mockDependencies, router: mockRouter.router }); + }); +}); diff --git a/x-pack/plugins/enterprise_search/server/routes/workplace_search/index.ts b/x-pack/plugins/enterprise_search/server/routes/workplace_search/index.ts new file mode 100644 index 0000000000000..a5ebcc0d05298 --- /dev/null +++ b/x-pack/plugins/enterprise_search/server/routes/workplace_search/index.ts @@ -0,0 +1,29 @@ +/* + * 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 { IRouteDependencies } from '../../plugin'; + +import { registerOverviewRoute } from './overview'; +import { + registerGroupsRoute, + registerSearchGroupsRoute, + registerGroupRoute, + registerGroupUsersRoute, + registerShareGroupRoute, + registerAssignGroupRoute, + registerBoostsGroupRoute, +} from './groups'; + +export const registerWorkplaceSearchRoutes = (dependencies: IRouteDependencies) => { + registerOverviewRoute(dependencies); + registerGroupsRoute(dependencies); + registerSearchGroupsRoute(dependencies); + registerGroupRoute(dependencies); + registerGroupUsersRoute(dependencies); + registerShareGroupRoute(dependencies); + registerAssignGroupRoute(dependencies); + registerBoostsGroupRoute(dependencies); +}; diff --git a/x-pack/plugins/enterprise_search/server/routes/workplace_search/overview.test.ts b/x-pack/plugins/enterprise_search/server/routes/workplace_search/overview.test.ts index a9bd4020e74b7..a387cab31c17a 100644 --- a/x-pack/plugins/enterprise_search/server/routes/workplace_search/overview.test.ts +++ b/x-pack/plugins/enterprise_search/server/routes/workplace_search/overview.test.ts @@ -6,7 +6,7 @@ import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__'; -import { registerWSOverviewRoute } from './overview'; +import { registerOverviewRoute } from './overview'; describe('Overview route', () => { describe('GET /api/workplace_search/overview', () => { @@ -16,7 +16,7 @@ describe('Overview route', () => { jest.clearAllMocks(); mockRouter = new MockRouter({ method: 'get', payload: 'query' }); - registerWSOverviewRoute({ + registerOverviewRoute({ ...mockDependencies, router: mockRouter.router, }); diff --git a/x-pack/plugins/enterprise_search/server/routes/workplace_search/overview.ts b/x-pack/plugins/enterprise_search/server/routes/workplace_search/overview.ts index 8cfd65725a23a..e5f9fcc746b5b 100644 --- a/x-pack/plugins/enterprise_search/server/routes/workplace_search/overview.ts +++ b/x-pack/plugins/enterprise_search/server/routes/workplace_search/overview.ts @@ -6,7 +6,7 @@ import { IRouteDependencies } from '../../plugin'; -export function registerWSOverviewRoute({ +export function registerOverviewRoute({ router, enterpriseSearchRequestHandler, }: IRouteDependencies) {