Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdover committed Apr 13, 2022
1 parent d8969e5 commit f2f30fe
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions x-pack/plugins/fleet/server/services/epm/packages/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ describe('When using EPM `get` services', () => {
beforeEach(() => {
const mockContract = createAppContextStartContractMock();
appContextService.start(mockContract);
jest.clearAllMocks();
MockRegistry.fetchFindLatestPackageOrUndefined.mockResolvedValue({
name: 'my-package',
version: '1.0.0',
Expand Down Expand Up @@ -320,6 +321,56 @@ describe('When using EPM `get` services', () => {
status: 'installed',
});
});

it('sets the latestVersion to installed version when an installed package is newer than package in registry', async () => {
const soClient = savedObjectsClientMock.create();
soClient.get.mockResolvedValue({
id: 'my-package',
type: PACKAGES_SAVED_OBJECT_TYPE,
references: [],
attributes: {
version: '2.0.0',
install_status: 'installed',
},
});

await expect(
getPackageInfo({
savedObjectsClient: soClient,
pkgName: 'my-package',
pkgVersion: '1.0.0',
})
).resolves.toMatchObject({
latestVersion: '1.0.0',
status: 'installed',
});
});
});

describe('skipArchive', () => {
it('avoids loading archive when skipArchive = true', async () => {
const soClient = savedObjectsClientMock.create();
soClient.get.mockRejectedValue(SavedObjectsErrorHelpers.createGenericNotFoundError());
MockRegistry.fetchInfo.mockResolvedValue({
name: 'my-package',
version: '1.0.0',
assets: [],
} as RegistryPackage);

await expect(
getPackageInfo({
savedObjectsClient: soClient,
pkgName: 'my-package',
pkgVersion: '1.0.0',
skipArchive: true,
})
).resolves.toMatchObject({
latestVersion: '1.0.0',
status: 'not_installed',
});

expect(MockRegistry.getRegistryPackage).not.toHaveBeenCalled();
});
});
});
});

0 comments on commit f2f30fe

Please sign in to comment.