Skip to content

Commit

Permalink
test: added tests for has strategies and enabled strategies
Browse files Browse the repository at this point in the history
Co-authored-by: Tymoteusz Czech <[email protected]>
  • Loading branch information
kwasniew and Tymek committed Oct 20, 2023
1 parent f1b8d9b commit 4eb6e65
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions src/test/e2e/api/admin/project/projects.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import getLogger from '../../../../fixtures/no-logger';

import { IProjectStore } from 'lib/types';
import { DEFAULT_ENV } from '../../../../../lib/util';

let app: IUnleashTest;
let db: ITestDb;
Expand All @@ -22,6 +23,7 @@ beforeAll(async () => {
experimental: {
flags: {
strictSchemaValidation: true,
featureSwitchRefactor: true,
},
},
},
Expand All @@ -30,11 +32,87 @@ beforeAll(async () => {
projectStore = db.stores.projectStore;
});

afterEach(async () => {
await db.stores.featureToggleStore.deleteAll();
});

afterAll(async () => {
await app.destroy();
await db.destroy();
});

test('should report has strategies and enabled strategies', async () => {
const app = await setupAppWithCustomConfig(
db.stores,
{
experimental: {
flags: {
featureSwitchRefactor: true,
},
},
},
db.rawDatabase,
);
await app.createFeature('featureWithStrategies');
await app.createFeature('featureWithoutStrategies');
await app.createFeature('featureWithDisabledStrategies');
await app.addStrategyToFeatureEnv(
{
name: 'default',
},
DEFAULT_ENV,
'featureWithStrategies',
);
await app.addStrategyToFeatureEnv(
{
name: 'default',
disabled: true,
},
DEFAULT_ENV,
'featureWithDisabledStrategies',
);

const { body } = await app.request
.get('/api/admin/projects/default')
.expect('Content-Type', /json/)
.expect(200);

expect(body).toMatchObject({
features: [
{
name: 'featureWithStrategies',
environments: [
{
name: 'default',
hasStrategies: true,
hasEnabledStrategies: true,
},
],
},
{
name: 'featureWithoutStrategies',
environments: [
{
name: 'default',
hasStrategies: false,
hasEnabledStrategies: false,
},
],
},
{
name: 'featureWithDisabledStrategies',
environments: [
{
name: 'default',
hasStrategies: true,
hasEnabledStrategies: false,
},
],
},
],
});
});

test('Should ONLY return default project', async () => {
projectStore.create({
id: 'test2',
Expand Down Expand Up @@ -121,6 +199,7 @@ test('response should include last seen at per environment for multiple environm
},
db.rawDatabase,
);
await app.createFeature('my-new-feature-toggle');

await db.stores.environmentStore.create({
name: 'development',
Expand Down

0 comments on commit 4eb6e65

Please sign in to comment.