diff --git a/x-pack/plugins/fleet/server/services/fleet_server/index.test.ts b/x-pack/plugins/fleet/server/services/fleet_server/index.test.ts index ac97411a5b92f..5b9155a756645 100644 --- a/x-pack/plugins/fleet/server/services/fleet_server/index.test.ts +++ b/x-pack/plugins/fleet/server/services/fleet_server/index.test.ts @@ -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'; @@ -24,7 +26,6 @@ import { } from '.'; jest.mock('../agent_policy'); -jest.mock('../package_policy'); jest.mock('../agents'); const mockedAgentPolicyService = agentPolicyService as jest.Mocked; @@ -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: [ { @@ -162,7 +164,7 @@ describe('getFleetServerPolicies', () => { policy_id: 'agent-policy-2', policy_ids: ['agent-policy-2'], }, - ]; + ] as PackagePolicy[]; const mockFleetServerPolicies = [ { id: 'fs-policy-1', @@ -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);