Skip to content

Commit

Permalink
[Enterprise Search] Refactor product server route registrations to th…
Browse files Browse the repository at this point in the history
…eir 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
  • Loading branch information
Constance authored and cee-chen committed Nov 5, 2020
1 parent c768659 commit ec5981f
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 23 deletions.
14 changes: 4 additions & 10 deletions x-pack/plugins/enterprise_search/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 });
});
});
17 changes: 17 additions & 0 deletions x-pack/plugins/enterprise_search/server/routes/app_search/index.ts
Original file line number Diff line number Diff line change
@@ -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);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
@@ -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 });
});
});
Original file line number Diff line number Diff line change
@@ -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);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -16,7 +16,7 @@ describe('Overview route', () => {
jest.clearAllMocks();
mockRouter = new MockRouter({ method: 'get', payload: 'query' });

registerWSOverviewRoute({
registerOverviewRoute({
...mockDependencies,
router: mockRouter.router,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { IRouteDependencies } from '../../plugin';

export function registerWSOverviewRoute({
export function registerOverviewRoute({
router,
enterpriseSearchRequestHandler,
}: IRouteDependencies) {
Expand Down

0 comments on commit ec5981f

Please sign in to comment.