Skip to content

Commit

Permalink
[Ingest Manager] Fix agent policy bump revision to create only one PO…
Browse files Browse the repository at this point in the history
…LICY_CHANGE action (#80081) (#80329)
  • Loading branch information
nchaulet authored Oct 13, 2020
1 parent bc710a7 commit badeaae
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
36 changes: 36 additions & 0 deletions x-pack/plugins/ingest_manager/server/services/agent_policy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { savedObjectsClientMock } from 'src/core/server/mocks';
import { agentPolicyService } from './agent_policy';
import { agentPolicyUpdateEventHandler } from './agent_policy_update';
import { Output } from '../types';

function getSavedObjectMock(agentPolicyAttributes: any) {
Expand Down Expand Up @@ -59,7 +60,42 @@ jest.mock('./output', () => {
};
});

jest.mock('./agent_policy_update');

function getAgentPolicyUpdateMock() {
return (agentPolicyUpdateEventHandler as unknown) as jest.Mock<
typeof agentPolicyUpdateEventHandler
>;
}

describe('agent policy', () => {
beforeEach(() => {
getAgentPolicyUpdateMock().mockClear();
});
describe('bumpRevision', () => {
it('should call agentPolicyUpdateEventHandler with updated event once', async () => {
const soClient = getSavedObjectMock({
revision: 1,
monitoring_enabled: ['metrics'],
});
await agentPolicyService.bumpRevision(soClient, 'agent-policy');

expect(agentPolicyUpdateEventHandler).toHaveBeenCalledTimes(1);
});
});

describe('bumpAllAgentPolicies', () => {
it('should call agentPolicyUpdateEventHandler with updated event once', async () => {
const soClient = getSavedObjectMock({
revision: 1,
monitoring_enabled: ['metrics'],
});
await agentPolicyService.bumpAllAgentPolicies(soClient);

expect(agentPolicyUpdateEventHandler).toHaveBeenCalledTimes(1);
});
});

describe('getFullAgentPolicy', () => {
it('should return a policy without monitoring if monitoring is not enabled', async () => {
const soClient = getSavedObjectMock({
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/ingest_manager/server/services/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,6 @@ class AgentPolicyService {
): Promise<AgentPolicy> {
const res = await this._update(soClient, id, {}, options?.user);

await this.triggerAgentPolicyUpdatedEvent(soClient, 'updated', id);

return res;
}
public async bumpAllAgentPolicies(
Expand Down

0 comments on commit badeaae

Please sign in to comment.