|
6 | 6 |
|
7 | 7 | import { savedObjectsClientMock } from 'src/core/server/mocks'; |
8 | 8 | import { agentPolicyService } from './agent_policy'; |
| 9 | +import { agentPolicyUpdateEventHandler } from './agent_policy_update'; |
9 | 10 | import { Output } from '../types'; |
10 | 11 |
|
11 | 12 | function getSavedObjectMock(agentPolicyAttributes: any) { |
@@ -59,7 +60,42 @@ jest.mock('./output', () => { |
59 | 60 | }; |
60 | 61 | }); |
61 | 62 |
|
| 63 | +jest.mock('./agent_policy_update'); |
| 64 | + |
| 65 | +function getAgentPolicyUpdateMock() { |
| 66 | + return (agentPolicyUpdateEventHandler as unknown) as jest.Mock< |
| 67 | + typeof agentPolicyUpdateEventHandler |
| 68 | + >; |
| 69 | +} |
| 70 | + |
62 | 71 | describe('agent policy', () => { |
| 72 | + beforeEach(() => { |
| 73 | + getAgentPolicyUpdateMock().mockClear(); |
| 74 | + }); |
| 75 | + describe('bumpRevision', () => { |
| 76 | + it('should call agentPolicyUpdateEventHandler with updated event once', async () => { |
| 77 | + const soClient = getSavedObjectMock({ |
| 78 | + revision: 1, |
| 79 | + monitoring_enabled: ['metrics'], |
| 80 | + }); |
| 81 | + await agentPolicyService.bumpRevision(soClient, 'agent-policy'); |
| 82 | + |
| 83 | + expect(agentPolicyUpdateEventHandler).toHaveBeenCalledTimes(1); |
| 84 | + }); |
| 85 | + }); |
| 86 | + |
| 87 | + describe('bumpAllAgentPolicies', () => { |
| 88 | + it('should call agentPolicyUpdateEventHandler with updated event once', async () => { |
| 89 | + const soClient = getSavedObjectMock({ |
| 90 | + revision: 1, |
| 91 | + monitoring_enabled: ['metrics'], |
| 92 | + }); |
| 93 | + await agentPolicyService.bumpAllAgentPolicies(soClient); |
| 94 | + |
| 95 | + expect(agentPolicyUpdateEventHandler).toHaveBeenCalledTimes(1); |
| 96 | + }); |
| 97 | + }); |
| 98 | + |
63 | 99 | describe('getFullAgentPolicy', () => { |
64 | 100 | it('should return a policy without monitoring if monitoring is not enabled', async () => { |
65 | 101 | const soClient = getSavedObjectMock({ |
|
0 commit comments