Skip to content

Commit

Permalink
EMT-248: review comments and some clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
nnamdifrankie committed Mar 19, 2020
1 parent b47d7a4 commit 2a3054f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
9 changes: 5 additions & 4 deletions x-pack/plugins/ingest_manager/common/types/models/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ export type AgentType =

export type AgentStatus = 'offline' | 'error' | 'online' | 'inactive' | 'warning';

export interface AgentAction extends SavedObjectAttributes {
export interface NewAgentAction {
type: 'CONFIG_CHANGE' | 'DATA_DUMP' | 'RESUME' | 'PAUSE';
id: string;
created_at: string;
data?: string;
sent_at?: string;
}

export type NewAgentAction = Pick<AgentAction, 'type' | 'data' | 'sent_at'>;
export interface AgentAction extends NewAgentAction, SavedObjectAttributes {
id: string;
created_at: string;
}

export interface AgentEvent {
type: 'STATE' | 'ERROR' | 'ACTION_RESULT' | 'ACTION';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import { httpServerMock } from '../../../../../../src/core/server/http/http_serv
import { ActionsService } from '../../services/agents';
import { AgentAction } from '../../../common/types/models';
import { postNewAgentActionHandlerBuilder } from './actions_handlers';
import { PostNewAgentActionResponse } from '../../../common/types/rest_spec';
import {
PostNewAgentActionRequest,
PostNewAgentActionResponse,
} from '../../../common/types/rest_spec';

describe('test actions handlers schema', () => {
it('validate that new agent actions schema is valid', async () => {
Expand Down Expand Up @@ -48,7 +51,7 @@ describe('test actions handlers', () => {
});

it('should succeed on valid new agent action', async () => {
const mockRequest = httpServerMock.createKibanaRequest({
const mockRequest = httpServerMock.createKibanaRequest(({
body: {
action: {
type: 'CONFIG_CHANGE',
Expand All @@ -59,7 +62,7 @@ describe('test actions handlers', () => {
params: {
agentId: 'id',
},
});
} as unknown) as PostNewAgentActionRequest);

const agentAction = ({
type: 'CONFIG_CHANGE',
Expand Down
10 changes: 2 additions & 8 deletions x-pack/plugins/ingest_manager/server/services/agents/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,12 @@ export async function updateAgentActions(
}

export function createAgentAction(createdAt: Date, newAgentAction: NewAgentAction): AgentAction {
const agentAction: object = {
const agentAction = {
id: uuid.v4(),
created_at: createdAt.toISOString(),
};

Object.assign(agentAction, ...keys(newAgentAction).map(key => ({ [key]: newAgentAction[key] })));

return agentAction as AgentAction;
}

function keys<O extends object>(obj: O): Array<keyof O> {
return Object.keys(obj) as Array<keyof O>;
return Object.assign(agentAction, newAgentAction) as AgentAction;

This comment has been minimized.

Copy link
@jfsiii

jfsiii Mar 19, 2020

Contributor

Please don't forget to remove this as AgentAction

The result of the Object.assign should be an AgentAction without casting. Or certainly the return value of the function should not be cast.

}

export interface ActionsService {
Expand Down

0 comments on commit 2a3054f

Please sign in to comment.