Skip to content

Commit

Permalink
fix and test
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaElastic committed Dec 16, 2022
1 parent ed60158 commit 2c3660d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,27 @@ describe('update_agent_tags', () => {
expect(actionResults.body[1].error).not.toBeDefined();
});

it('should update action results on success - kuery', async () => {
await updateTagsBatch(
soClient,
esClient,
[],
{},
{
tagsToAdd: ['new'],
tagsToRemove: [],
kuery: '',
}
);

const actionResults = esClient.bulk.mock.calls[0][0] as any;
const agentIds = actionResults?.body
?.filter((i: any) => i.agent_id)
.map((i: any) => i.agent_id);
expect(agentIds[0]).toHaveLength(36); // uuid
expect(actionResults.body[1].error).not.toBeDefined();
});

it('should write error action results for hosted agent when agentIds are passed', async () => {
const { esClient: esClientMock, agentInHostedDoc } = createClientMock();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,14 @@ export async function updateTagsBatch(
}

// creating unique ids to use as agentId, as we don't have all agent ids in case of action by kuery
const getArray = (count: number) => [...Array(count).keys()];
const getArray = (count: number) => Array.from({ length: count }, () => uuid());

// writing successful action results
if (res.updated ?? 0 > 0) {
await bulkCreateAgentActionResults(
esClient,

(options.kuery === undefined ? agentIds : getArray(res.updated!)).map(() => ({
agentId: uuid(),
(options.kuery === undefined ? agentIds : getArray(res.updated!)).map((id) => ({
agentId: id,
actionId,
}))
);
Expand Down

0 comments on commit 2c3660d

Please sign in to comment.