mirror of
https://github.com/Unleash/unleash.git
synced 2024-10-23 20:07:40 +02:00
815a75a5b4
Adds environment support This PR adds environments as a first-class concept in Unleash. It necessitated a full rewrite on how we connect feature <-> strategy, as well as a rethink on which levels environments makes sense. This enables PUTs on strategy configurations for a feature, since all strategies now have ids. This also updates export/import format. The importer handles both formats, but export is no longer possible in version 1 of the export format, only in version 2, with strategy configurations for a feature as a separate object. Co-authored-by: Christopher Kolstad <chriswk@getunleash.ai> Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com> Co-authored-by: Ivar Conradi Østhus <ivarconr@gmail.com>
116 lines
3.8 KiB
TypeScript
116 lines
3.8 KiB
TypeScript
import dbInit from '../helpers/database-init';
|
|
import getLogger from '../../fixtures/no-logger';
|
|
import { AccessService } from '../../../lib/services/access-service';
|
|
import ProjectService from '../../../lib/services/project-service';
|
|
import ProjectHealthService from '../../../lib/services/project-health-service';
|
|
import { createTestConfig } from '../../config/test-config';
|
|
|
|
let stores;
|
|
let db;
|
|
let projectService;
|
|
let accessService;
|
|
let projectHealthService;
|
|
let user;
|
|
|
|
beforeAll(async () => {
|
|
const config = createTestConfig();
|
|
db = await dbInit('project_health_service_serial', getLogger);
|
|
stores = db.stores;
|
|
user = await stores.userStore.insert({
|
|
name: 'Some Name',
|
|
email: 'test@getunleash.io',
|
|
});
|
|
accessService = new AccessService(stores, config);
|
|
projectService = new ProjectService(stores, config, accessService);
|
|
projectHealthService = new ProjectHealthService(stores, config);
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await db.destroy();
|
|
});
|
|
test('Project with no stale toggles should have 100% health rating', async () => {
|
|
const project = {
|
|
id: 'health-rating',
|
|
name: 'Health rating',
|
|
description: 'Fancy',
|
|
};
|
|
const savedProject = await projectService.createProject(project, user);
|
|
await stores.featureToggleStore.createFeature('health-rating', {
|
|
name: 'health-rating-not-stale',
|
|
description: 'new',
|
|
stale: false,
|
|
});
|
|
await stores.featureToggleStore.createFeature('health-rating', {
|
|
name: 'health-rating-not-stale-2',
|
|
description: 'new too',
|
|
stale: false,
|
|
});
|
|
const rating = await projectHealthService.calculateHealthRating(
|
|
savedProject,
|
|
);
|
|
expect(rating).toBe(100);
|
|
});
|
|
|
|
test('Project with two stale toggles and two non stale should have 50% health rating', async () => {
|
|
const project = {
|
|
id: 'health-rating-2',
|
|
name: 'Health rating',
|
|
description: 'Fancy',
|
|
};
|
|
const savedProject = await projectService.createProject(project, user);
|
|
await stores.featureToggleStore.createFeature('health-rating-2', {
|
|
name: 'health-rating-2-not-stale',
|
|
description: 'new',
|
|
stale: false,
|
|
});
|
|
await stores.featureToggleStore.createFeature('health-rating-2', {
|
|
name: 'health-rating-2-not-stale-2',
|
|
description: 'new too',
|
|
stale: false,
|
|
});
|
|
await stores.featureToggleStore.createFeature('health-rating-2', {
|
|
name: 'health-rating-2-stale-1',
|
|
description: 'stale',
|
|
stale: true,
|
|
});
|
|
await stores.featureToggleStore.createFeature('health-rating-2', {
|
|
name: 'health-rating-2-stale-2',
|
|
description: 'stale too',
|
|
stale: true,
|
|
});
|
|
const rating = await projectHealthService.calculateHealthRating(
|
|
savedProject,
|
|
);
|
|
expect(rating).toBe(50);
|
|
});
|
|
|
|
test('Project with one non-stale, one potentially stale and one stale should have 33% health rating', async () => {
|
|
const project = {
|
|
id: 'health-rating-3',
|
|
name: 'Health rating',
|
|
description: 'Fancy',
|
|
};
|
|
const savedProject = await projectService.createProject(project, user);
|
|
await stores.featureToggleStore.createFeature('health-rating-3', {
|
|
name: 'health-rating-3-not-stale',
|
|
description: 'new',
|
|
stale: false,
|
|
});
|
|
await stores.featureToggleStore.createFeature('health-rating-3', {
|
|
name: 'health-rating-3-potentially-stale',
|
|
description: 'new too',
|
|
type: 'release',
|
|
stale: false,
|
|
createdAt: new Date(Date.UTC(2020, 1, 1)),
|
|
});
|
|
await stores.featureToggleStore.createFeature('health-rating-3', {
|
|
name: 'health-rating-3-stale',
|
|
description: 'stale',
|
|
stale: true,
|
|
});
|
|
const rating = await projectHealthService.calculateHealthRating(
|
|
savedProject,
|
|
);
|
|
expect(rating).toBe(33);
|
|
});
|