Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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