Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Workplace Search] Add additional sources routes #83227

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__';

import {
registerAccountSourcesRoute,
registerAccountSourcesStatusRoute,
registerAccountSourceRoute,
registerAccountCreateSourceRoute,
registerAccountSourceDocumentsRoute,
Expand All @@ -15,6 +17,9 @@ import {
registerAccountSourceSettingsRoute,
registerAccountPreSourceRoute,
registerAccountPrepareSourcesRoute,
registerAccountSourceSearchableRoute,
registerOrgSourcesRoute,
registerOrgSourcesStatusRoute,
registerOrgSourceRoute,
registerOrgCreateSourceRoute,
registerOrgSourceDocumentsRoute,
Expand All @@ -23,6 +28,7 @@ import {
registerOrgSourceSettingsRoute,
registerOrgPreSourceRoute,
registerOrgPrepareSourcesRoute,
registerOrgSourceSearchableRoute,
registerOrgSourceOauthConfigurationsRoute,
registerOrgSourceOauthConfigurationRoute,
} from './sources';
Expand All @@ -38,6 +44,60 @@ const mockConfig = {
};

describe('sources routes', () => {
describe('GET /api/workplace_search/account/sources', () => {
let mockRouter: MockRouter;

beforeEach(() => {
jest.clearAllMocks();
});

it('creates a request handler', () => {
mockRouter = new MockRouter({
method: 'get',
path: '/api/workplace_search/account/sources',
payload: 'params',
});

registerAccountSourcesRoute({
...mockDependencies,
router: mockRouter.router,
});

mockRouter.callRoute({});

expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
path: '/ws/sources',
});
});
});

describe('GET /api/workplace_search/account/sources/status', () => {
let mockRouter: MockRouter;

beforeEach(() => {
jest.clearAllMocks();
});

it('creates a request handler', () => {
mockRouter = new MockRouter({
method: 'get',
path: '/api/workplace_search/account/sources/status',
payload: 'params',
});

registerAccountSourcesStatusRoute({
...mockDependencies,
router: mockRouter.router,
});

mockRouter.callRoute({});

expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
path: '/ws/sources/status',
});
});
});

describe('GET /api/workplace_search/account/sources/{id}', () => {
let mockRouter: MockRouter;

Expand Down Expand Up @@ -351,6 +411,97 @@ describe('sources routes', () => {
});
});

describe('PUT /api/workplace_search/sources/{id}/searchable', () => {
let mockRouter: MockRouter;

beforeEach(() => {
jest.clearAllMocks();
});

it('creates a request handler', () => {
mockRouter = new MockRouter({
method: 'put',
path: '/api/workplace_search/sources/{id}/searchable',
payload: 'body',
});

registerAccountSourceSearchableRoute({
...mockDependencies,
router: mockRouter.router,
});

const mockRequest = {
params: {
id: '123',
},
body: {
searchable: true,
},
};

mockRouter.callRoute(mockRequest);

expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
path: '/ws/sources/123/searchable',
body: mockRequest.body,
});
});
});

describe('GET /api/workplace_search/org/sources', () => {
let mockRouter: MockRouter;

beforeEach(() => {
jest.clearAllMocks();
});

it('creates a request handler', () => {
mockRouter = new MockRouter({
method: 'get',
path: '/api/workplace_search/org/sources',
payload: 'params',
});

registerOrgSourcesRoute({
...mockDependencies,
router: mockRouter.router,
});

mockRouter.callRoute({});

expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
path: '/ws/org/sources',
});
});
});

describe('GET /api/workplace_search/org/sources/status', () => {
let mockRouter: MockRouter;

beforeEach(() => {
jest.clearAllMocks();
});

it('creates a request handler', () => {
mockRouter = new MockRouter({
method: 'get',
path: '/api/workplace_search/org/sources/status',
payload: 'params',
});

registerOrgSourcesStatusRoute({
...mockDependencies,
router: mockRouter.router,
});

mockRouter.callRoute({});

expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
path: '/ws/org/sources/status',
});
});
});

describe('GET /api/workplace_search/org/sources/{id}', () => {
let mockRouter: MockRouter;

Expand Down Expand Up @@ -664,6 +815,43 @@ describe('sources routes', () => {
});
});

describe('PUT /api/workplace_search/org/sources/{id}/searchable', () => {
let mockRouter: MockRouter;

beforeEach(() => {
jest.clearAllMocks();
});

it('creates a request handler', () => {
mockRouter = new MockRouter({
method: 'put',
path: '/api/workplace_search/org/sources/{id}/searchable',
payload: 'body',
});

registerOrgSourceSearchableRoute({
...mockDependencies,
router: mockRouter.router,
});

const mockRequest = {
params: {
id: '123',
},
body: {
searchable: true,
},
};

mockRouter.callRoute(mockRequest);

expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
path: '/ws/org/sources/123/searchable',
body: mockRequest.body,
});
});
});

describe('GET /api/workplace_search/org/settings/connectors', () => {
let mockRouter: MockRouter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,40 @@ const oAuthConfigSchema = schema.object({
consumer_key: schema.string(),
});

export function registerAccountSourcesRoute({
router,
enterpriseSearchRequestHandler,
}: RouteDependencies) {
router.get(
{
path: '/api/workplace_search/account/sources',
validate: false,
},
async (context, request, response) => {
return enterpriseSearchRequestHandler.createRequest({
path: '/ws/sources',
})(context, request, response);
}
);
}

export function registerAccountSourcesStatusRoute({
router,
enterpriseSearchRequestHandler,
}: RouteDependencies) {
router.get(
{
path: '/api/workplace_search/account/sources/status',
validate: false,
},
async (context, request, response) => {
return enterpriseSearchRequestHandler.createRequest({
path: '/ws/sources/status',
})(context, request, response);
}
);
}

export function registerAccountSourceRoute({
router,
enterpriseSearchRequestHandler,
Expand Down Expand Up @@ -228,6 +262,65 @@ export function registerAccountPrepareSourcesRoute({
);
}

export function registerAccountSourceSearchableRoute({
router,
enterpriseSearchRequestHandler,
}: RouteDependencies) {
router.put(
{
path: '/api/workplace_search/sources/{id}/searchable',
validate: {
body: schema.object({
searchable: schema.boolean(),
}),
params: schema.object({
id: schema.string(),
}),
},
},
async (context, request, response) => {
return enterpriseSearchRequestHandler.createRequest({
path: `/ws/sources/${request.params.id}/searchable`,
body: request.body,
})(context, request, response);
}
);
}

export function registerOrgSourcesRoute({
router,
enterpriseSearchRequestHandler,
}: RouteDependencies) {
router.get(
{
path: '/api/workplace_search/org/sources',
validate: false,
},
async (context, request, response) => {
return enterpriseSearchRequestHandler.createRequest({
path: '/ws/org/sources',
})(context, request, response);
}
);
}

export function registerOrgSourcesStatusRoute({
router,
enterpriseSearchRequestHandler,
}: RouteDependencies) {
router.get(
{
path: '/api/workplace_search/org/sources/status',
validate: false,
},
async (context, request, response) => {
return enterpriseSearchRequestHandler.createRequest({
path: '/ws/org/sources/status',
})(context, request, response);
}
);
}

export function registerOrgSourceRoute({
router,
enterpriseSearchRequestHandler,
Expand Down Expand Up @@ -431,6 +524,31 @@ export function registerOrgPrepareSourcesRoute({
);
}

export function registerOrgSourceSearchableRoute({
router,
enterpriseSearchRequestHandler,
}: RouteDependencies) {
router.put(
{
path: '/api/workplace_search/org/sources/{id}/searchable',
validate: {
body: schema.object({
searchable: schema.boolean(),
}),
params: schema.object({
id: schema.string(),
}),
},
},
async (context, request, response) => {
return enterpriseSearchRequestHandler.createRequest({
path: `/ws/org/sources/${request.params.id}/searchable`,
body: request.body,
})(context, request, response);
}
);
}

export function registerOrgSourceOauthConfigurationsRoute({
router,
enterpriseSearchRequestHandler,
Expand Down Expand Up @@ -522,6 +640,8 @@ export function registerOrgSourceOauthConfigurationRoute({
}

export const registerSourcesRoutes = (dependencies: RouteDependencies) => {
registerAccountSourcesRoute(dependencies);
registerAccountSourcesStatusRoute(dependencies);
registerAccountSourceRoute(dependencies);
registerAccountCreateSourceRoute(dependencies);
registerAccountSourceDocumentsRoute(dependencies);
Expand All @@ -530,6 +650,9 @@ export const registerSourcesRoutes = (dependencies: RouteDependencies) => {
registerAccountSourceSettingsRoute(dependencies);
registerAccountPreSourceRoute(dependencies);
registerAccountPrepareSourcesRoute(dependencies);
registerAccountSourceSearchableRoute(dependencies);
registerOrgSourcesRoute(dependencies);
registerOrgSourcesStatusRoute(dependencies);
registerOrgSourceRoute(dependencies);
registerOrgCreateSourceRoute(dependencies);
registerOrgSourceDocumentsRoute(dependencies);
Expand All @@ -538,6 +661,7 @@ export const registerSourcesRoutes = (dependencies: RouteDependencies) => {
registerOrgSourceSettingsRoute(dependencies);
registerOrgPreSourceRoute(dependencies);
registerOrgPrepareSourcesRoute(dependencies);
registerOrgSourceSearchableRoute(dependencies);
registerOrgSourceOauthConfigurationsRoute(dependencies);
registerOrgSourceOauthConfigurationRoute(dependencies);
};