1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-05-31 01:16:01 +02:00

fix: attempt to unflake version service tests (#2008)

This commit is contained in:
olav 2022-08-31 08:06:25 +02:00 committed by GitHub
parent 5c003e3b2e
commit f06470dfa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 20 deletions

View File

@ -2,26 +2,26 @@ import nock from 'nock';
import createStores from '../../test/fixtures/store';
import version from '../util/version';
import getLogger from '../../test/fixtures/no-logger';
import VersionService from './version-service';
import { randomId } from '../util/random-id';
beforeEach(() => {
beforeAll(() => {
nock.disableNetConnect();
});
afterEach(() => {
afterAll(() => {
nock.enableNetConnect();
});
test('yields current versions', async () => {
const testurl = 'https://version.test';
const url = `https://${randomId()}.example.com`;
const { settingStore } = createStores();
await settingStore.insert('instanceInfo', { id: '1234abc' });
const latest = {
oss: '5.0.0',
enterprise: '5.0.0',
};
nock(testurl)
const scope = nock(url)
.post('/')
.reply(() => [
200,
@ -34,21 +34,20 @@ test('yields current versions', async () => {
{ settingStore },
{
getLogger,
versionCheck: { url: testurl, enable: true },
versionCheck: { url, enable: true },
},
);
await service.checkLatestVersion();
const versionInfo = service.getVersionInfo();
expect(scope.isDone()).toEqual(true);
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 url = `https://${randomId()}.example.com`;
const { settingStore } = createStores();
const enterpriseVersion = '3.7.0';
await settingStore.insert('instanceInfo', { id: '1234abc' });
@ -56,7 +55,7 @@ test('supports setting enterprise version as well', async () => {
oss: '4.0.0',
enterprise: '4.0.0',
};
nock(testurl)
const scope = nock(url)
.post('/')
.reply(() => [
200,
@ -70,22 +69,21 @@ test('supports setting enterprise version as well', async () => {
{ settingStore },
{
getLogger,
versionCheck: { url: testurl, enable: true },
versionCheck: { url, enable: true },
enterpriseVersion,
},
);
await service.checkLatestVersion();
const versionInfo = service.getVersionInfo();
expect(scope.isDone()).toEqual(true);
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 url = `https://${randomId()}.example.com`;
const { settingStore } = createStores();
const enterpriseVersion = '3.7.0';
await settingStore.insert('instanceInfo', { id: '1234abc' });
@ -93,7 +91,7 @@ test('if version check is not enabled should not make any calls', async () => {
oss: '4.0.0',
enterprise: '4.0.0',
};
const scope = nock(testurl)
const scope = nock(url)
.get('/')
.reply(() => [
200,
@ -107,18 +105,16 @@ test('if version check is not enabled should not make any calls', async () => {
{ settingStore },
{
getLogger,
versionCheck: { url: testurl, enable: false },
versionCheck: { url, enable: false },
enterpriseVersion,
},
);
await service.checkLatestVersion();
const versionInfo = service.getVersionInfo();
expect(scope.isDone()).toBeFalsy();
expect(scope.isDone()).toEqual(false);
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();
nock.cleanAll();
});

View File

@ -13,7 +13,7 @@ export interface IVersionInfo {
export interface IVersionHolder {
current: IVersionInfo;
latest: IVersionInfo | {};
latest: Partial<IVersionInfo>;
isLatest: boolean;
instanceId: string;
}