unleash-server
Version:
Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.
71 lines • 2.61 kB
JavaScript
import dbInit from '../../../test/e2e/helpers/database-init.js';
import getLogger from '../../../test/fixtures/no-logger.js';
import { FeatureLifecycleReadModel } from './feature-lifecycle-read-model.js';
let db;
let featureLifecycleReadModel;
let featureLifecycleStore;
let featureToggleStore;
beforeAll(async () => {
db = await dbInit('feature_lifecycle_read_model', getLogger);
featureLifecycleReadModel = new FeatureLifecycleReadModel(db.rawDatabase);
featureLifecycleStore = db.stores.featureLifecycleStore;
featureToggleStore = db.stores.featureToggleStore;
});
afterAll(async () => {
if (db) {
await db.destroy();
}
});
beforeEach(async () => {
await featureToggleStore.deleteAll();
});
test('can return stage count', async () => {
await featureToggleStore.create('default', {
name: 'featureA',
createdByUserId: 9999,
});
await featureToggleStore.create('default', {
name: 'featureB',
createdByUserId: 9999,
});
await featureToggleStore.create('default', {
name: 'featureC',
createdByUserId: 9999,
});
await featureLifecycleStore.insert([
{ feature: 'featureA', stage: 'initial' },
{ feature: 'featureB', stage: 'initial' },
{ feature: 'featureC', stage: 'initial' },
]);
await featureLifecycleStore.insert([
{ feature: 'featureA', stage: 'pre-live' },
]);
const stageCount = await featureLifecycleReadModel.getStageCount();
expect(stageCount).toMatchObject([
{ stage: 'pre-live', count: 1 },
{ stage: 'initial', count: 2 },
]);
const stageCountByProject = await featureLifecycleReadModel.getStageCountByProject();
expect(stageCountByProject).toMatchObject([
{ project: 'default', stage: 'pre-live', count: 1 },
{ project: 'default', stage: 'initial', count: 2 },
]);
});
test('returns stage count only for accessible projects', async () => {
await featureToggleStore.create('projectA', {
name: 'featureA1',
createdByUserId: 1,
});
await featureToggleStore.create('projectB', {
name: 'featureB1',
createdByUserId: 2,
});
await featureLifecycleStore.insert([
{ feature: 'featureA1', stage: 'pre-live' },
{ feature: 'featureB1', stage: 'pre-live' },
]);
const accessibleProjects = ['projectA'];
const stageCount = await featureLifecycleReadModel.getStageCount(accessibleProjects);
expect(stageCount).toEqual([{ stage: 'pre-live', count: 1 }]);
});
//# sourceMappingURL=feature-lifecycle-read-model.test.js.map