Skip to content

Commit 2a3054f

Browse files
committed
EMT-248: review comments and some clean up
1 parent b47d7a4 commit 2a3054f

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

x-pack/plugins/ingest_manager/common/types/models/agent.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ export type AgentType =
1414

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

17-
export interface AgentAction extends SavedObjectAttributes {
17+
export interface NewAgentAction {
1818
type: 'CONFIG_CHANGE' | 'DATA_DUMP' | 'RESUME' | 'PAUSE';
19-
id: string;
20-
created_at: string;
2119
data?: string;
2220
sent_at?: string;
2321
}
2422

25-
export type NewAgentAction = Pick<AgentAction, 'type' | 'data' | 'sent_at'>;
23+
export interface AgentAction extends NewAgentAction, SavedObjectAttributes {
24+
id: string;
25+
created_at: string;
26+
}
2627

2728
export interface AgentEvent {
2829
type: 'STATE' | 'ERROR' | 'ACTION_RESULT' | 'ACTION';

x-pack/plugins/ingest_manager/server/routes/agent/actions_handlers.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import { httpServerMock } from '../../../../../../src/core/server/http/http_serv
1515
import { ActionsService } from '../../services/agents';
1616
import { AgentAction } from '../../../common/types/models';
1717
import { postNewAgentActionHandlerBuilder } from './actions_handlers';
18-
import { PostNewAgentActionResponse } from '../../../common/types/rest_spec';
18+
import {
19+
PostNewAgentActionRequest,
20+
PostNewAgentActionResponse,
21+
} from '../../../common/types/rest_spec';
1922

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

5053
it('should succeed on valid new agent action', async () => {
51-
const mockRequest = httpServerMock.createKibanaRequest({
54+
const mockRequest = httpServerMock.createKibanaRequest(({
5255
body: {
5356
action: {
5457
type: 'CONFIG_CHANGE',
@@ -59,7 +62,7 @@ describe('test actions handlers', () => {
5962
params: {
6063
agentId: 'id',
6164
},
62-
});
65+
} as unknown) as PostNewAgentActionRequest);
6366

6467
const agentAction = ({
6568
type: 'CONFIG_CHANGE',

x-pack/plugins/ingest_manager/server/services/agents/actions.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,12 @@ export async function updateAgentActions(
3131
}
3232

3333
export function createAgentAction(createdAt: Date, newAgentAction: NewAgentAction): AgentAction {
34-
const agentAction: object = {
34+
const agentAction = {
3535
id: uuid.v4(),
3636
created_at: createdAt.toISOString(),
3737
};
3838

39-
Object.assign(agentAction, ...keys(newAgentAction).map(key => ({ [key]: newAgentAction[key] })));
40-
41-
return agentAction as AgentAction;
42-
}
43-
44-
function keys<O extends object>(obj: O): Array<keyof O> {
45-
return Object.keys(obj) as Array<keyof O>;
39+
return Object.assign(agentAction, newAgentAction) as AgentAction;
4640
}
4741

4842
export interface ActionsService {

0 commit comments

Comments
 (0)