1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/src/lib/services/version-service.test.ts
Christopher Kolstad ff7be7696c
fix: Stores as typescript and with interfaces. (#902)
Co-authored-by: Ivar Conradi Østhus <ivarconr@gmail.com>
2021-08-12 15:04:37 +02:00

114 lines
3.4 KiB
TypeScript

import fetchMock from 'jest-fetch-mock';
import createStores from '../../test/fixtures/store';
import version from '../util/version';
import getLogger from '../../test/fixtures/no-logger';
import VersionService from './version-service';
beforeEach(() => {
fetchMock.resetMocks();
});
test('yields current versions', async () => {
const testurl = 'https://version.test';
const { settingStore } = createStores();
await settingStore.insert('instanceInfo', { id: '1234abc' });
const latest = {
oss: '5.0.0',
enterprise: '5.0.0',
};
fetchMock.mockResponse(
JSON.stringify({
latest: false,
versions: latest,
}),
{ status: 200 },
);
const service = new VersionService(
{ settingStore },
{
getLogger,
versionCheck: { url: testurl, enable: true },
},
);
await service.checkLatestVersion();
const versionInfo = service.getVersionInfo();
expect(versionInfo.current.oss).toBe(version);
expect(versionInfo.current.enterprise).toBeFalsy();
// @ts-ignore
expect(versionInfo.latest.oss).toBe(latest.oss);
// @ts-ignore
expect(versionInfo.latest.enterprise).toBe(latest.enterprise);
});
test('supports setting enterprise version as well', async () => {
const testurl = `https://version.test${Math.random() * 1000}`;
const { settingStore } = createStores();
const enterpriseVersion = '3.7.0';
await settingStore.insert('instanceInfo', { id: '1234abc' });
const latest = {
oss: '4.0.0',
enterprise: '4.0.0',
};
fetchMock.mockResponse(
JSON.stringify({
latest: false,
versions: latest,
}),
{ status: 200 },
);
const service = new VersionService(
{ settingStore },
{
getLogger,
versionCheck: { url: testurl, enable: true },
enterpriseVersion,
},
);
await service.checkLatestVersion();
const versionInfo = service.getVersionInfo();
expect(versionInfo.current.oss).toBe(version);
expect(versionInfo.current.enterprise).toBe(enterpriseVersion);
// @ts-ignore
expect(versionInfo.latest.oss).toBe(latest.oss);
// @ts-ignore
expect(versionInfo.latest.enterprise).toBe(latest.enterprise);
});
test('if version check is not enabled should not make any calls', async () => {
const testurl = `https://version.test${Math.random() * 1000}`;
const { settingStore } = createStores();
const enterpriseVersion = '3.7.0';
await settingStore.insert('instanceInfo', { id: '1234abc' });
const latest = {
oss: '4.0.0',
enterprise: '4.0.0',
};
fetchMock.mockResponse(
JSON.stringify({
latest: false,
versions: latest,
}),
{ status: 200 },
);
const service = new VersionService(
{ settingStore },
{
getLogger,
versionCheck: { url: testurl, enable: false },
enterpriseVersion,
},
);
await service.checkLatestVersion();
const versionInfo = service.getVersionInfo();
expect(fetchMock.mock.calls).toHaveLength(0);
expect(versionInfo.current.oss).toBe(version);
expect(versionInfo.current.enterprise).toBe(enterpriseVersion);
// @ts-ignore
expect(versionInfo.latest.oss).toBeFalsy();
// @ts-ignore
expect(versionInfo.latest.enterprise).toBeFalsy();
});