Skip to content

Commit

Permalink
added unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaElastic committed Feb 22, 2024
1 parent e3a84f7 commit 1c5c811
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions x-pack/plugins/fleet/server/services/agent_policy_create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,35 @@ describe('createAgentPolicyWithPackages', () => {
);
});

it('should call deploy policy once when create policy with system package', async () => {
mockedAgentPolicyService.deployPolicy.mockClear();
mockedAgentPolicyService.create.mockImplementation((soClient, esClient, newPolicy, options) => {
if (!options?.skipDeploy) {
mockedAgentPolicyService.deployPolicy(soClientMock, 'new_id');
}
return Promise.resolve({
...newPolicy,
id: options?.id || 'new_id',
} as AgentPolicy);
});
const response = await createAgentPolicyWithPackages({
esClient: esClientMock,
soClient: soClientMock,
newPolicy: { name: 'Agent policy 1', namespace: 'default' },
withSysMonitoring: true,
spaceId: 'default',
});

expect(response.id).toEqual('new_id');
expect(mockedBulkInstallPackages).toHaveBeenCalledWith({
savedObjectsClient: soClientMock,
esClient: esClientMock,
packagesToInstall: ['system'],
spaceId: 'default',
});
expect(mockedAgentPolicyService.deployPolicy).toHaveBeenCalledTimes(1);
});

it('should create policy with system and elastic_agent package', async () => {
const response = await createAgentPolicyWithPackages({
esClient: esClientMock,
Expand Down

0 comments on commit 1c5c811

Please sign in to comment.