Skip to content

Commit

Permalink
added more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaElastic committed Feb 7, 2023
1 parent ba781b9 commit 1c56354
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
44 changes: 44 additions & 0 deletions x-pack/plugins/fleet/server/services/epm/packages/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,50 @@ describe('install', () => {
expect.objectContaining({ installSource: 'upload' })
);
});

it('should fetch latest version if version not provided', async () => {
jest.spyOn(licenseService, 'hasAtLeast').mockReturnValue(true);
const response = await installPackage({
spaceId: DEFAULT_SPACE_ID,
installSource: 'registry',
pkgkey: 'test_package',
savedObjectsClient: savedObjectsClientMock.create(),
esClient: {} as ElasticsearchClient,
});

expect(response.status).toEqual('installed');

expect(sendTelemetryEvents).toHaveBeenCalledWith(
expect.anything(),
undefined,
expect.objectContaining({
newVersion: '1.3.0',
})
);
});

it('should do nothing if same version is installed', async () => {
jest.spyOn(obj, 'getInstallationObject').mockImplementationOnce(() =>
Promise.resolve({
attributes: {
version: '1.2.0',
install_status: 'installed',
installed_es: [],
installed_kibana: [],
},
} as any)
);
jest.spyOn(licenseService, 'hasAtLeast').mockReturnValue(true);
const response = await installPackage({
spaceId: DEFAULT_SPACE_ID,
installSource: 'registry',
pkgkey: 'apache-1.2.0',
savedObjectsClient: savedObjectsClientMock.create(),
esClient: {} as ElasticsearchClient,
});

expect(response.status).toEqual('already_installed');
});
});

describe('upload', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ async function installPackageFromRegistry({
const logger = appContextService.getLogger();
// TODO: change epm API to /packageName/version so we don't need to do this
const { pkgName, pkgVersion: version } = Registry.splitPkgKey(pkgkey);
let pkgVersion = version;
let pkgVersion = version ?? '';

// if an error happens during getInstallType, report that we don't know
let installType: InstallType = 'unknown';
Expand Down

0 comments on commit 1c56354

Please sign in to comment.