2022-04-28 10:57:52 +02:00
|
|
|
import nock from 'nock';
|
2021-08-12 15:04:37 +02:00
|
|
|
import createStores from '../../test/fixtures/store';
|
|
|
|
import version from '../util/version';
|
|
|
|
import getLogger from '../../test/fixtures/no-logger';
|
|
|
|
import VersionService from './version-service';
|
2023-06-13 15:54:20 +02:00
|
|
|
import { v4 as uuidv4 } from 'uuid';
|
2022-08-31 08:06:25 +02:00
|
|
|
import { randomId } from '../util/random-id';
|
2021-05-28 11:10:24 +02:00
|
|
|
|
2022-08-31 08:06:25 +02:00
|
|
|
beforeAll(() => {
|
2022-04-28 10:57:52 +02:00
|
|
|
nock.disableNetConnect();
|
|
|
|
});
|
|
|
|
|
2022-08-31 08:06:25 +02:00
|
|
|
afterAll(() => {
|
2022-04-28 10:57:52 +02:00
|
|
|
nock.enableNetConnect();
|
2021-08-12 15:04:37 +02:00
|
|
|
});
|
2021-02-19 11:13:25 +01:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('yields current versions', async () => {
|
2022-08-31 08:06:25 +02:00
|
|
|
const url = `https://${randomId()}.example.com`;
|
2023-06-13 15:54:20 +02:00
|
|
|
const stores = createStores();
|
|
|
|
await stores.settingStore.insert('instanceInfo', { id: '1234abc' });
|
2021-02-19 11:13:25 +01:00
|
|
|
const latest = {
|
2021-04-22 10:07:10 +02:00
|
|
|
oss: '5.0.0',
|
|
|
|
enterprise: '5.0.0',
|
2021-02-19 11:13:25 +01:00
|
|
|
};
|
2022-08-31 08:06:25 +02:00
|
|
|
const scope = nock(url)
|
2022-04-28 10:57:52 +02:00
|
|
|
.post('/')
|
|
|
|
.reply(() => [
|
|
|
|
200,
|
|
|
|
JSON.stringify({
|
|
|
|
latest: false,
|
|
|
|
versions: latest,
|
|
|
|
}),
|
|
|
|
]);
|
2023-06-13 15:54:20 +02:00
|
|
|
const service = new VersionService(stores, {
|
|
|
|
getLogger,
|
|
|
|
versionCheck: { url, enable: true },
|
2023-06-15 15:11:58 +02:00
|
|
|
telemetry: true,
|
2023-06-13 15:54:20 +02:00
|
|
|
});
|
2021-02-19 11:13:25 +01:00
|
|
|
await service.checkLatestVersion();
|
|
|
|
const versionInfo = service.getVersionInfo();
|
2022-08-31 08:06:25 +02:00
|
|
|
expect(scope.isDone()).toEqual(true);
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(versionInfo.current.oss).toBe(version);
|
|
|
|
expect(versionInfo.current.enterprise).toBeFalsy();
|
|
|
|
expect(versionInfo.latest.oss).toBe(latest.oss);
|
|
|
|
expect(versionInfo.latest.enterprise).toBe(latest.enterprise);
|
2021-02-19 11:13:25 +01:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('supports setting enterprise version as well', async () => {
|
2022-08-31 08:06:25 +02:00
|
|
|
const url = `https://${randomId()}.example.com`;
|
2023-06-13 15:54:20 +02:00
|
|
|
const stores = createStores();
|
2021-02-19 11:13:25 +01:00
|
|
|
const enterpriseVersion = '3.7.0';
|
2023-06-13 15:54:20 +02:00
|
|
|
await stores.settingStore.insert('instanceInfo', { id: '1234abc' });
|
2021-02-19 11:13:25 +01:00
|
|
|
const latest = {
|
|
|
|
oss: '4.0.0',
|
|
|
|
enterprise: '4.0.0',
|
|
|
|
};
|
2022-08-31 08:06:25 +02:00
|
|
|
const scope = nock(url)
|
2022-04-28 10:57:52 +02:00
|
|
|
.post('/')
|
|
|
|
.reply(() => [
|
|
|
|
200,
|
|
|
|
JSON.stringify({
|
|
|
|
latest: false,
|
|
|
|
versions: latest,
|
|
|
|
}),
|
|
|
|
]);
|
2021-08-12 15:04:37 +02:00
|
|
|
|
2023-06-13 15:54:20 +02:00
|
|
|
const service = new VersionService(stores, {
|
|
|
|
getLogger,
|
|
|
|
versionCheck: { url, enable: true },
|
|
|
|
enterpriseVersion,
|
2023-06-15 15:11:58 +02:00
|
|
|
telemetry: true,
|
2023-06-13 15:54:20 +02:00
|
|
|
});
|
2021-02-19 11:13:25 +01:00
|
|
|
await service.checkLatestVersion();
|
|
|
|
const versionInfo = service.getVersionInfo();
|
2022-08-31 08:06:25 +02:00
|
|
|
expect(scope.isDone()).toEqual(true);
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(versionInfo.current.oss).toBe(version);
|
|
|
|
expect(versionInfo.current.enterprise).toBe(enterpriseVersion);
|
|
|
|
expect(versionInfo.latest.oss).toBe(latest.oss);
|
|
|
|
expect(versionInfo.latest.enterprise).toBe(latest.enterprise);
|
2021-02-19 11:13:25 +01:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('if version check is not enabled should not make any calls', async () => {
|
2022-08-31 08:06:25 +02:00
|
|
|
const url = `https://${randomId()}.example.com`;
|
2023-06-13 15:54:20 +02:00
|
|
|
const stores = createStores();
|
2021-05-28 11:10:24 +02:00
|
|
|
const enterpriseVersion = '3.7.0';
|
2023-06-13 15:54:20 +02:00
|
|
|
await stores.settingStore.insert('instanceInfo', { id: '1234abc' });
|
2021-05-28 11:10:24 +02:00
|
|
|
const latest = {
|
|
|
|
oss: '4.0.0',
|
|
|
|
enterprise: '4.0.0',
|
|
|
|
};
|
2022-08-31 08:06:25 +02:00
|
|
|
const scope = nock(url)
|
2022-04-28 10:57:52 +02:00
|
|
|
.get('/')
|
|
|
|
.reply(() => [
|
|
|
|
200,
|
|
|
|
JSON.stringify({
|
|
|
|
latest: false,
|
|
|
|
versions: latest,
|
|
|
|
}),
|
|
|
|
]);
|
2021-08-12 15:04:37 +02:00
|
|
|
|
2023-06-13 15:54:20 +02:00
|
|
|
const service = new VersionService(stores, {
|
|
|
|
getLogger,
|
|
|
|
versionCheck: { url, enable: false },
|
|
|
|
enterpriseVersion,
|
2023-06-15 15:11:58 +02:00
|
|
|
telemetry: true,
|
2023-06-13 15:54:20 +02:00
|
|
|
});
|
2021-05-28 11:10:24 +02:00
|
|
|
await service.checkLatestVersion();
|
|
|
|
const versionInfo = service.getVersionInfo();
|
2022-08-31 08:06:25 +02:00
|
|
|
expect(scope.isDone()).toEqual(false);
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(versionInfo.current.oss).toBe(version);
|
|
|
|
expect(versionInfo.current.enterprise).toBe(enterpriseVersion);
|
|
|
|
expect(versionInfo.latest.oss).toBeFalsy();
|
|
|
|
expect(versionInfo.latest.enterprise).toBeFalsy();
|
2022-04-28 10:57:52 +02:00
|
|
|
nock.cleanAll();
|
2021-05-28 11:10:24 +02:00
|
|
|
});
|
2023-06-13 15:54:20 +02:00
|
|
|
|
|
|
|
test('sets featureinfo', async () => {
|
|
|
|
const url = `https://${randomId()}.example.com`;
|
|
|
|
const stores = createStores();
|
|
|
|
const enterpriseVersion = '4.0.0';
|
|
|
|
await stores.settingStore.insert('instanceInfo', { id: '1234abc' });
|
|
|
|
const latest = {
|
|
|
|
oss: '4.0.0',
|
|
|
|
enterprise: '4.0.0',
|
|
|
|
};
|
|
|
|
|
|
|
|
const scope = nock(url)
|
|
|
|
.post(
|
|
|
|
'/',
|
|
|
|
(body) =>
|
|
|
|
body.featureInfo &&
|
|
|
|
body.featureInfo.featureToggles === 0 &&
|
|
|
|
body.featureInfo.environments === 0,
|
|
|
|
)
|
|
|
|
.reply(() => [
|
|
|
|
200,
|
|
|
|
JSON.stringify({
|
|
|
|
latest: true,
|
|
|
|
versions: latest,
|
|
|
|
}),
|
|
|
|
]);
|
|
|
|
|
|
|
|
const service = new VersionService(stores, {
|
|
|
|
getLogger,
|
|
|
|
versionCheck: { url, enable: true },
|
|
|
|
enterpriseVersion,
|
2023-06-15 15:11:58 +02:00
|
|
|
telemetry: true,
|
2023-06-13 15:54:20 +02:00
|
|
|
});
|
|
|
|
await service.checkLatestVersion();
|
|
|
|
expect(scope.isDone()).toEqual(true);
|
|
|
|
nock.cleanAll();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('counts toggles', async () => {
|
|
|
|
const url = `https://${randomId()}.example.com`;
|
|
|
|
const stores = createStores();
|
|
|
|
const enterpriseVersion = '4.0.0';
|
|
|
|
await stores.settingStore.insert('instanceInfo', { id: '1234abc' });
|
|
|
|
await stores.settingStore.insert('unleash.enterprise.auth.oidc', {
|
|
|
|
enabled: true,
|
|
|
|
});
|
|
|
|
await stores.featureToggleStore.create('project', { name: uuidv4() });
|
|
|
|
await stores.strategyStore.createStrategy({
|
|
|
|
name: uuidv4(),
|
|
|
|
editable: true,
|
|
|
|
});
|
|
|
|
const latest = {
|
|
|
|
oss: '4.0.0',
|
|
|
|
enterprise: '4.0.0',
|
|
|
|
};
|
|
|
|
|
|
|
|
const scope = nock(url)
|
|
|
|
.post(
|
|
|
|
'/',
|
|
|
|
(body) =>
|
|
|
|
body.featureInfo &&
|
|
|
|
body.featureInfo.featureToggles === 1 &&
|
|
|
|
body.featureInfo.environments === 0 &&
|
|
|
|
body.featureInfo.customStrategies === 1 &&
|
|
|
|
body.featureInfo.customStrategiesInUse === 3 &&
|
|
|
|
body.featureInfo.OIDCenabled,
|
|
|
|
)
|
|
|
|
.reply(() => [
|
|
|
|
200,
|
|
|
|
JSON.stringify({
|
|
|
|
latest: true,
|
|
|
|
versions: latest,
|
|
|
|
}),
|
|
|
|
]);
|
|
|
|
|
|
|
|
const service = new VersionService(stores, {
|
|
|
|
getLogger,
|
|
|
|
versionCheck: { url, enable: true },
|
|
|
|
enterpriseVersion,
|
2023-06-15 15:11:58 +02:00
|
|
|
telemetry: true,
|
2023-06-13 15:54:20 +02:00
|
|
|
});
|
|
|
|
await service.checkLatestVersion();
|
|
|
|
expect(scope.isDone()).toEqual(true);
|
|
|
|
nock.cleanAll();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('counts custom strategies', async () => {
|
|
|
|
const url = `https://${randomId()}.example.com`;
|
|
|
|
const stores = createStores();
|
|
|
|
const enterpriseVersion = '4.0.0';
|
|
|
|
const strategyName = uuidv4();
|
|
|
|
const toggleName = uuidv4();
|
|
|
|
await stores.settingStore.insert('instanceInfo', { id: '1234abc' });
|
|
|
|
await stores.settingStore.insert('unleash.enterprise.auth.oidc', {
|
|
|
|
enabled: true,
|
|
|
|
});
|
|
|
|
await stores.featureToggleStore.create('project', { name: toggleName });
|
|
|
|
await stores.strategyStore.createStrategy({
|
|
|
|
name: strategyName,
|
|
|
|
editable: true,
|
|
|
|
});
|
|
|
|
await stores.strategyStore.createStrategy({
|
|
|
|
name: uuidv4(),
|
|
|
|
editable: true,
|
|
|
|
});
|
|
|
|
await stores.featureStrategiesStore.createStrategyFeatureEnv({
|
|
|
|
featureName: toggleName,
|
|
|
|
projectId: 'project',
|
|
|
|
environment: 'default',
|
|
|
|
strategyName: strategyName,
|
|
|
|
parameters: {},
|
|
|
|
constraints: [],
|
|
|
|
});
|
|
|
|
const latest = {
|
|
|
|
oss: '4.0.0',
|
|
|
|
enterprise: '4.0.0',
|
|
|
|
};
|
|
|
|
|
|
|
|
const scope = nock(url)
|
|
|
|
.post(
|
|
|
|
'/',
|
|
|
|
(body) =>
|
|
|
|
body.featureInfo &&
|
|
|
|
body.featureInfo.featureToggles === 1 &&
|
|
|
|
body.featureInfo.environments === 0 &&
|
|
|
|
body.featureInfo.customStrategies === 2 &&
|
|
|
|
body.featureInfo.customStrategiesInUse === 3 &&
|
|
|
|
body.featureInfo.OIDCenabled,
|
|
|
|
)
|
|
|
|
.reply(() => [
|
|
|
|
200,
|
|
|
|
JSON.stringify({
|
|
|
|
latest: true,
|
|
|
|
versions: latest,
|
|
|
|
}),
|
|
|
|
]);
|
|
|
|
|
|
|
|
const service = new VersionService(stores, {
|
|
|
|
getLogger,
|
|
|
|
versionCheck: { url, enable: true },
|
|
|
|
enterpriseVersion,
|
2023-06-15 15:11:58 +02:00
|
|
|
telemetry: true,
|
2023-06-13 15:54:20 +02:00
|
|
|
});
|
|
|
|
await service.checkLatestVersion();
|
|
|
|
expect(scope.isDone()).toEqual(true);
|
|
|
|
nock.cleanAll();
|
|
|
|
});
|