Skip to content

Commit

Permalink
EMT-248: use core client
Browse files Browse the repository at this point in the history
  • Loading branch information
nnamdifrankie committed Mar 19, 2020
1 parent 74a4729 commit 58c3420
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,18 @@ describe('test actions handlers', () => {
getAgent: jest.fn().mockReturnValueOnce({
id: 'agent',
}),
getSavedObjectsClientContract: jest.fn().mockReturnValueOnce(mockSavedObjectsClient),
updateAgentActions: jest.fn().mockReturnValueOnce(agentAction),
} as jest.Mocked<ActionsService>;

const postNewAgentActionHandler = postNewAgentActionHandlerBuilder(actionsService);
await postNewAgentActionHandler(
({} as unknown) as RequestHandlerContext,
({
core: {
savedObjects: {
client: mockSavedObjectsClient,
},
},
} as unknown) as RequestHandlerContext,
mockRequest,
mockResponse
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const postNewAgentActionHandlerBuilder = function(
> {
return async (context, request, response) => {
try {
const soClient = actionsService.getSavedObjectsClientContract(request);
const soClient = context.core.savedObjects.client;

const agent = await actionsService.getAgent(soClient, request.params.agentId);

Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/ingest_manager/server/routes/agent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ export const registerRoutes = (router: IRouter) => {
},
postNewAgentActionHandlerBuilder({
getAgent: AgentService.getAgent,
getSavedObjectsClientContract: getInternalUserSOClient,
updateAgentActions: AgentService.updateAgentActions,
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ interface UpdatedActions {
describe('test agent actions services', () => {
it('should update agent current actions with new action', async () => {
const mockSavedObjectsClient = savedObjectsClientMock.create();

const newAgentAction: NewAgentAction = {
type: 'CONFIG_CHANGE',
data: 'data',
sent_at: '2020-03-14T19:45:02.620Z',
};

await updateAgentActions(
mockSavedObjectsClient,
({
Expand All @@ -41,6 +43,7 @@ describe('test agent actions services', () => {

const updatedAgentActions = (mockSavedObjectsClient.update.mock
.calls[0][2] as unknown) as UpdatedActions;

expect(updatedAgentActions.actions.length).toEqual(2);
const actualAgentAction = updatedAgentActions.actions.find(action => action?.data === 'data');
expect(actualAgentAction?.type).toEqual(newAgentAction.type);
Expand All @@ -56,6 +59,7 @@ describe('test agent actions services', () => {
};
const now = new Date();
const agentAction = createAgentAction(now, newAgentAction);

expect(agentAction.type).toEqual(newAgentAction.type);
expect(agentAction.data).toEqual(newAgentAction.data);
expect(agentAction.sent_at).toEqual(newAgentAction.sent_at);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { KibanaRequest, SavedObjectsClientContract } from 'kibana/server';
import { SavedObjectsClientContract } from 'kibana/server';
import uuid from 'uuid';
import {
Agent,
Expand Down Expand Up @@ -42,8 +42,6 @@ export function createAgentAction(createdAt: Date, newAgentAction: NewAgentActio
export interface ActionsService {
getAgent: (soClient: SavedObjectsClientContract, agentId: string) => Promise<Agent>;

getSavedObjectsClientContract: (kibanaRequest: KibanaRequest) => SavedObjectsClientContract;

updateAgentActions: (
soClient: SavedObjectsClientContract,
agent: Agent,
Expand Down

0 comments on commit 58c3420

Please sign in to comment.