Skip to content

Commit c768659

Browse files
authored
[Enterprise Search] Added App Search log settings routes (#82162) (#82652)
1 parent 087d057 commit c768659

3 files changed

Lines changed: 125 additions & 0 deletions

File tree

x-pack/plugins/enterprise_search/server/plugin.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { appSearchTelemetryType } from './saved_objects/app_search/telemetry';
4141
import { registerTelemetryUsageCollector as registerASTelemetryUsageCollector } from './collectors/app_search/telemetry';
4242
import { registerEnginesRoute } from './routes/app_search/engines';
4343
import { registerCredentialsRoutes } from './routes/app_search/credentials';
44+
import { registerSettingsRoutes } from './routes/app_search/settings';
4445

4546
import { workplaceSearchTelemetryType } from './saved_objects/workplace_search/telemetry';
4647
import { registerTelemetryUsageCollector as registerWSTelemetryUsageCollector } from './collectors/workplace_search/telemetry';
@@ -128,6 +129,7 @@ export class EnterpriseSearchPlugin implements Plugin {
128129
registerConfigDataRoute(dependencies);
129130
registerEnginesRoute(dependencies);
130131
registerCredentialsRoutes(dependencies);
132+
registerSettingsRoutes(dependencies);
131133
registerWSOverviewRoute(dependencies);
132134
registerWSGroupRoutes(dependencies);
133135

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__';
8+
9+
import { registerSettingsRoutes } from './settings';
10+
11+
describe('log settings routes', () => {
12+
describe('GET /api/app_search/log_settings', () => {
13+
let mockRouter: MockRouter;
14+
15+
beforeEach(() => {
16+
jest.clearAllMocks();
17+
mockRouter = new MockRouter({ method: 'get' });
18+
19+
registerSettingsRoutes({
20+
...mockDependencies,
21+
router: mockRouter.router,
22+
});
23+
});
24+
25+
it('creates a request to enterprise search', () => {
26+
mockRouter.callRoute({});
27+
28+
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
29+
path: '/as/log_settings',
30+
});
31+
});
32+
});
33+
34+
describe('PUT /api/app_search/log_settings', () => {
35+
let mockRouter: MockRouter;
36+
37+
beforeEach(() => {
38+
jest.clearAllMocks();
39+
mockRouter = new MockRouter({ method: 'put', payload: 'body' });
40+
41+
registerSettingsRoutes({
42+
...mockDependencies,
43+
router: mockRouter.router,
44+
});
45+
});
46+
47+
it('creates a request to enterprise search', () => {
48+
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
49+
path: '/as/log_settings',
50+
});
51+
});
52+
53+
describe('validates', () => {
54+
it('validates good data', () => {
55+
const request = {
56+
body: {
57+
analytics: { enabled: true },
58+
api: { enabled: true },
59+
},
60+
};
61+
mockRouter.shouldValidate(request);
62+
});
63+
64+
it('rejects bad data', () => {
65+
const request = {
66+
body: {
67+
foo: 'bar',
68+
},
69+
};
70+
mockRouter.shouldThrow(request);
71+
});
72+
});
73+
});
74+
});
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { schema } from '@kbn/config-schema';
8+
9+
import { IRouteDependencies } from '../../plugin';
10+
11+
export function registerSettingsRoutes({
12+
router,
13+
enterpriseSearchRequestHandler,
14+
}: IRouteDependencies) {
15+
router.get(
16+
{
17+
path: '/api/app_search/log_settings',
18+
validate: false,
19+
},
20+
enterpriseSearchRequestHandler.createRequest({
21+
path: '/as/log_settings',
22+
})
23+
);
24+
25+
router.put(
26+
{
27+
path: '/api/app_search/log_settings',
28+
validate: {
29+
body: schema.object({
30+
api: schema.maybe(
31+
schema.object({
32+
enabled: schema.boolean(),
33+
})
34+
),
35+
analytics: schema.maybe(
36+
schema.object({
37+
enabled: schema.boolean(),
38+
})
39+
),
40+
}),
41+
},
42+
},
43+
async (context, request, response) => {
44+
return enterpriseSearchRequestHandler.createRequest({
45+
path: '/as/log_settings',
46+
})(context, request, response);
47+
}
48+
);
49+
}

0 commit comments

Comments
 (0)