-
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.
Added App Search log settings routes
- Loading branch information
1 parent
f5b1fae
commit 4f21b1b
Showing
3 changed files
with
137 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
82 changes: 82 additions & 0 deletions
82
x-pack/plugins/enterprise_search/server/routes/app_search/log_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,82 @@ | ||
/* | ||
* 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 { registerLogSettingsRoutes } from './log_settings'; | ||
|
||
describe('log settings routes', () => { | ||
describe('PUT /api/app_search/log_settings', () => { | ||
let mockRouter: MockRouter; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mockRouter = new MockRouter({ method: 'put', payload: 'body' }); | ||
|
||
registerLogSettingsRoutes({ | ||
...mockDependencies, | ||
router: mockRouter.router, | ||
}); | ||
}); | ||
|
||
it('creates a request to enterprise search', () => { | ||
const mockRequest = { | ||
body: { | ||
analytics: true, | ||
}, | ||
}; | ||
|
||
mockRouter.callRoute(mockRequest); | ||
|
||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({ | ||
path: '/as/log_settings', | ||
}); | ||
}); | ||
|
||
describe('validates', () => { | ||
it('validates good data', () => { | ||
const request = { | ||
body: { | ||
analytics: { enabled: true }, | ||
api: { enabled: true }, | ||
}, | ||
}; | ||
mockRouter.shouldValidate(request); | ||
}); | ||
|
||
it('rejects bad data', () => { | ||
const request = { | ||
body: { | ||
foo: 'bar', | ||
}, | ||
}; | ||
mockRouter.shouldThrow(request); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('GET /api/app_search/log_settings', () => { | ||
let mockRouter: MockRouter; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mockRouter = new MockRouter({ method: 'get' }); | ||
|
||
registerLogSettingsRoutes({ | ||
...mockDependencies, | ||
router: mockRouter.router, | ||
}); | ||
}); | ||
|
||
it('creates a request to enterprise search', () => { | ||
mockRouter.callRoute({}); | ||
|
||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({ | ||
path: '/as/log_settings', | ||
}); | ||
}); | ||
}); | ||
}); |
53 changes: 53 additions & 0 deletions
53
x-pack/plugins/enterprise_search/server/routes/app_search/log_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,53 @@ | ||
/* | ||
* 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 { IRouteDependencies } from '../../plugin'; | ||
|
||
const logSettingsSchema = schema.object({ | ||
api: schema.maybe( | ||
schema.object({ | ||
enabled: schema.boolean(), | ||
}) | ||
), | ||
analytics: schema.maybe( | ||
schema.object({ | ||
enabled: schema.boolean(), | ||
}) | ||
), | ||
}); | ||
|
||
export function registerLogSettingsRoutes({ | ||
router, | ||
enterpriseSearchRequestHandler, | ||
}: IRouteDependencies) { | ||
router.get( | ||
{ | ||
path: '/api/app_search/log_settings', | ||
validate: false, | ||
}, | ||
async (context, request, response) => { | ||
return enterpriseSearchRequestHandler.createRequest({ | ||
path: '/as/log_settings', | ||
})(context, request, response); | ||
} | ||
); | ||
|
||
router.put( | ||
{ | ||
path: '/api/app_search/log_settings', | ||
validate: { | ||
body: logSettingsSchema, | ||
}, | ||
}, | ||
async (context, request, response) => { | ||
return enterpriseSearchRequestHandler.createRequest({ | ||
path: '/as/log_settings', | ||
})(context, request, response); | ||
} | ||
); | ||
} |