Skip to content

Commit

Permalink
Fix fleet test
Browse files Browse the repository at this point in the history
  • Loading branch information
afharo committed Aug 23, 2024
1 parent be642b6 commit b8c6716
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions x-pack/plugins/fleet/server/services/fleet_server/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import { elasticsearchServiceMock } from '@kbn/core-elasticsearch-server-mocks';
import { savedObjectsClientMock } from '@kbn/core-saved-objects-api-server-mocks';

import type { PackagePolicy } from '../../../common';

import { appContextService } from '..';

import type { MockedFleetAppContext } from '../../mocks';
Expand All @@ -24,7 +26,6 @@ import {
} from '.';

jest.mock('../agent_policy');
jest.mock('../package_policy');
jest.mock('../agents');

const mockedAgentPolicyService = agentPolicyService as jest.Mocked<typeof agentPolicyService>;
Expand Down Expand Up @@ -54,7 +55,8 @@ describe('checkFleetServerVersionsForSecretsStorage', () => {
it('should return true if all fleet server versions are at least the specified version and there are no managed policies', async () => {
const version = '1.0.0';

mockedPackagePolicyService.list
jest
.spyOn(mockedPackagePolicyService, 'list')
.mockResolvedValueOnce({
items: [
{
Expand Down Expand Up @@ -162,7 +164,7 @@ describe('getFleetServerPolicies', () => {
policy_id: 'agent-policy-2',
policy_ids: ['agent-policy-2'],
},
];
] as PackagePolicy[];
const mockFleetServerPolicies = [
{
id: 'fs-policy-1',
Expand All @@ -185,16 +187,22 @@ describe('getFleetServerPolicies', () => {
];

it('should return no policies if there are no fleet server package policies', async () => {
(mockedPackagePolicyService.list as jest.Mock).mockResolvedValueOnce({
jest.spyOn(mockedPackagePolicyService, 'list').mockResolvedValueOnce({
items: [],
total: 0,
page: 1,
perPage: 10,
});
const result = await getFleetServerPolicies(soClient);
expect(result).toEqual([]);
});

it('should return agent policies with fleet server package policies', async () => {
(mockedPackagePolicyService.list as jest.Mock).mockResolvedValueOnce({
jest.spyOn(mockedPackagePolicyService, 'list').mockResolvedValueOnce({
items: mockPackagePolicies,
total: mockPackagePolicies.length,
page: 1,
perPage: mockPackagePolicies.length,
});
(mockedAgentPolicyService.getByIDs as jest.Mock).mockResolvedValueOnce(mockFleetServerPolicies);
const result = await getFleetServerPolicies(soClient);
Expand Down

0 comments on commit b8c6716

Please sign in to comment.