2021-08-12 15:04:37 +02:00
|
|
|
import faker from 'faker';
|
2021-09-13 10:23:57 +02:00
|
|
|
import { FeatureToggleDTO, IStrategyConfig } from 'lib/types/model';
|
|
|
|
import dbInit, { ITestDb } from '../../helpers/database-init';
|
|
|
|
import { IUnleashTest, setupApp } from '../../helpers/test-helper';
|
2021-08-12 15:04:37 +02:00
|
|
|
import getLogger from '../../../fixtures/no-logger';
|
2019-10-03 15:01:33 +02:00
|
|
|
|
2021-09-13 10:23:57 +02:00
|
|
|
let app: IUnleashTest;
|
|
|
|
let db: ITestDb;
|
|
|
|
|
|
|
|
const defaultStrategy = {
|
|
|
|
name: 'default',
|
|
|
|
parameters: {},
|
|
|
|
constraints: [],
|
|
|
|
};
|
2019-10-03 15:01:33 +02:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
beforeAll(async () => {
|
2021-03-19 22:25:21 +01:00
|
|
|
db = await dbInit('feature_api_serial', getLogger);
|
2021-05-28 11:10:24 +02:00
|
|
|
app = await setupApp(db.stores);
|
2021-09-13 10:23:57 +02:00
|
|
|
|
|
|
|
const createToggle = async (
|
|
|
|
toggle: FeatureToggleDTO,
|
|
|
|
strategy: Omit<IStrategyConfig, 'id'> = defaultStrategy,
|
|
|
|
projectId: string = 'default',
|
|
|
|
username: string = 'test',
|
|
|
|
) => {
|
|
|
|
await app.services.featureToggleServiceV2.createFeatureToggle(
|
|
|
|
projectId,
|
|
|
|
toggle,
|
|
|
|
username,
|
|
|
|
);
|
|
|
|
await app.services.featureToggleServiceV2.createStrategy(
|
|
|
|
strategy,
|
|
|
|
projectId,
|
|
|
|
toggle.name,
|
2021-09-20 12:13:38 +02:00
|
|
|
username,
|
2021-09-13 10:23:57 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
await createToggle({
|
|
|
|
name: 'featureX',
|
|
|
|
description: 'the #1 feature',
|
|
|
|
});
|
|
|
|
|
|
|
|
await createToggle(
|
2021-07-07 10:46:50 +02:00
|
|
|
{
|
|
|
|
name: 'featureY',
|
|
|
|
description: 'soon to be the #1 feature',
|
|
|
|
},
|
2021-09-13 10:23:57 +02:00
|
|
|
{
|
|
|
|
name: 'baz',
|
|
|
|
constraints: [],
|
|
|
|
parameters: {
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
|
|
|
},
|
2021-07-07 10:46:50 +02:00
|
|
|
);
|
2021-09-13 10:23:57 +02:00
|
|
|
|
|
|
|
await createToggle(
|
2021-07-07 10:46:50 +02:00
|
|
|
{
|
|
|
|
name: 'featureZ',
|
|
|
|
description: 'terrible feature',
|
|
|
|
},
|
2021-09-13 10:23:57 +02:00
|
|
|
{
|
|
|
|
name: 'baz',
|
|
|
|
constraints: [],
|
|
|
|
parameters: {
|
|
|
|
foo: 'rab',
|
|
|
|
},
|
|
|
|
},
|
2021-07-07 10:46:50 +02:00
|
|
|
);
|
2021-09-13 10:23:57 +02:00
|
|
|
|
|
|
|
await createToggle(
|
2021-07-07 10:46:50 +02:00
|
|
|
{
|
|
|
|
name: 'featureArchivedX',
|
|
|
|
description: 'the #1 feature',
|
|
|
|
},
|
2021-09-13 10:23:57 +02:00
|
|
|
{
|
|
|
|
name: 'default',
|
|
|
|
constraints: [],
|
|
|
|
parameters: {},
|
|
|
|
},
|
2021-07-07 10:46:50 +02:00
|
|
|
);
|
2021-09-13 10:23:57 +02:00
|
|
|
|
2021-07-07 10:46:50 +02:00
|
|
|
await app.services.featureToggleServiceV2.archiveToggle(
|
|
|
|
'featureArchivedX',
|
|
|
|
'test',
|
|
|
|
);
|
2021-09-13 10:23:57 +02:00
|
|
|
|
|
|
|
await createToggle(
|
2021-07-07 10:46:50 +02:00
|
|
|
{
|
|
|
|
name: 'featureArchivedY',
|
|
|
|
description: 'soon to be the #1 feature',
|
|
|
|
},
|
2021-09-13 10:23:57 +02:00
|
|
|
{
|
|
|
|
name: 'baz',
|
|
|
|
constraints: [],
|
|
|
|
parameters: {
|
|
|
|
foo: 'bar',
|
|
|
|
},
|
|
|
|
},
|
2021-07-07 10:46:50 +02:00
|
|
|
);
|
2021-09-13 10:23:57 +02:00
|
|
|
|
2021-07-07 10:46:50 +02:00
|
|
|
await app.services.featureToggleServiceV2.archiveToggle(
|
|
|
|
'featureArchivedY',
|
|
|
|
'test',
|
|
|
|
);
|
2021-09-13 10:23:57 +02:00
|
|
|
|
|
|
|
await createToggle(
|
2021-07-07 10:46:50 +02:00
|
|
|
{
|
|
|
|
name: 'featureArchivedZ',
|
|
|
|
description: 'terrible feature',
|
|
|
|
},
|
2021-09-13 10:23:57 +02:00
|
|
|
{
|
|
|
|
name: 'baz',
|
|
|
|
constraints: [],
|
|
|
|
parameters: {
|
|
|
|
foo: 'rab',
|
|
|
|
},
|
|
|
|
},
|
2021-07-07 10:46:50 +02:00
|
|
|
);
|
2021-09-13 10:23:57 +02:00
|
|
|
|
2021-07-07 10:46:50 +02:00
|
|
|
await app.services.featureToggleServiceV2.archiveToggle(
|
|
|
|
'featureArchivedZ',
|
|
|
|
'test',
|
|
|
|
);
|
2021-09-13 10:23:57 +02:00
|
|
|
|
|
|
|
await createToggle({
|
|
|
|
name: 'feature.with.variants',
|
|
|
|
description: 'A feature toggle with variants',
|
|
|
|
variants: [
|
|
|
|
{
|
|
|
|
name: 'control',
|
|
|
|
weight: 50,
|
|
|
|
weightType: 'variable',
|
|
|
|
overrides: [],
|
|
|
|
stickiness: 'default',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'new',
|
|
|
|
weight: 50,
|
|
|
|
weightType: 'variable',
|
|
|
|
overrides: [],
|
|
|
|
stickiness: 'default',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
2019-10-03 15:01:33 +02:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
afterAll(async () => {
|
|
|
|
await app.destroy();
|
2021-03-19 22:25:21 +01:00
|
|
|
await db.destroy();
|
2019-10-03 15:01:33 +02:00
|
|
|
});
|
2017-06-28 10:20:22 +02:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('returns list of feature toggles', async () =>
|
|
|
|
app.request
|
2017-06-28 10:20:22 +02:00
|
|
|
.get('/api/admin/features')
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200)
|
2021-08-12 15:04:37 +02:00
|
|
|
.expect((res) => {
|
2021-07-07 10:46:50 +02:00
|
|
|
expect(res.body.features).toHaveLength(4);
|
2021-05-28 11:10:24 +02:00
|
|
|
}));
|
2017-06-28 10:20:22 +02:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('gets a feature by name', async () => {
|
|
|
|
expect.assertions(0);
|
|
|
|
return app.request
|
2017-06-28 10:20:22 +02:00
|
|
|
.get('/api/admin/features/featureX')
|
|
|
|
.expect('Content-Type', /json/)
|
2019-10-03 15:01:33 +02:00
|
|
|
.expect(200);
|
2017-06-28 10:20:22 +02:00
|
|
|
});
|
|
|
|
|
2021-07-07 10:46:50 +02:00
|
|
|
test('cant get feature that does not exist', async () => {
|
2021-05-28 11:10:24 +02:00
|
|
|
expect.assertions(0);
|
2021-07-07 10:46:50 +02:00
|
|
|
return app.request.get('/api/admin/features/myfeature').expect(404);
|
2017-06-28 10:20:22 +02:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('creates new feature toggle', async () => {
|
2021-07-07 10:46:50 +02:00
|
|
|
expect.assertions(2);
|
2021-05-28 11:10:24 +02:00
|
|
|
return app.request
|
2017-06-28 10:20:22 +02:00
|
|
|
.post('/api/admin/features')
|
|
|
|
.send({
|
|
|
|
name: 'com.test.feature',
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
})
|
|
|
|
.set('Content-Type', 'application/json')
|
2021-03-04 13:28:31 +01:00
|
|
|
.expect(201)
|
2021-08-12 15:04:37 +02:00
|
|
|
.expect((res) => {
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(res.body.name).toBe('com.test.feature');
|
|
|
|
expect(res.body.createdAt).toBeTruthy();
|
2021-03-04 13:28:31 +01:00
|
|
|
});
|
2017-06-28 10:20:22 +02:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('creates new feature toggle with variants', async () => {
|
|
|
|
expect.assertions(0);
|
|
|
|
return app.request
|
2018-01-30 15:57:12 +01:00
|
|
|
.post('/api/admin/features')
|
|
|
|
.send({
|
|
|
|
name: 'com.test.variants',
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
2019-01-24 11:26:07 +01:00
|
|
|
variants: [
|
|
|
|
{ name: 'variant1', weight: 50 },
|
|
|
|
{ name: 'variant2', weight: 50 },
|
|
|
|
],
|
2018-01-30 15:57:12 +01:00
|
|
|
})
|
2019-01-24 08:39:21 +01:00
|
|
|
.set('Content-Type', 'application/json')
|
2019-10-03 15:01:33 +02:00
|
|
|
.expect(201);
|
2019-01-24 08:39:21 +01:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('fetch feature toggle with variants', async () => {
|
|
|
|
expect.assertions(1);
|
|
|
|
return app.request
|
2019-01-24 08:39:21 +01:00
|
|
|
.get('/api/admin/features/feature.with.variants')
|
2021-07-07 10:46:50 +02:00
|
|
|
.expect(200)
|
2021-08-12 15:04:37 +02:00
|
|
|
.expect((res) => {
|
2021-07-07 10:46:50 +02:00
|
|
|
expect(res.body.variants).toHaveLength(2);
|
2019-10-03 15:01:33 +02:00
|
|
|
});
|
2018-01-30 15:57:12 +01:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('creates new feature toggle with createdBy unknown', async () => {
|
|
|
|
expect.assertions(1);
|
|
|
|
await app.request
|
2021-01-18 12:32:19 +01:00
|
|
|
.post('/api/admin/features')
|
|
|
|
.send({
|
|
|
|
name: 'com.test.Username',
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
})
|
|
|
|
.expect(201);
|
2021-08-12 15:04:37 +02:00
|
|
|
await app.request.get('/api/admin/events').expect((res) => {
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(res.body.events[0].createdBy).toBe('unknown');
|
2019-10-03 15:01:33 +02:00
|
|
|
});
|
2017-06-28 10:20:22 +02:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('require new feature toggle to have a name', async () => {
|
|
|
|
expect.assertions(0);
|
|
|
|
return app.request
|
2017-06-28 10:20:22 +02:00
|
|
|
.post('/api/admin/features')
|
|
|
|
.send({ name: '' })
|
|
|
|
.set('Content-Type', 'application/json')
|
2019-10-03 15:01:33 +02:00
|
|
|
.expect(400);
|
2017-06-28 10:20:22 +02:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('can not change status of feature toggle that does not exist', async () => {
|
|
|
|
expect.assertions(0);
|
|
|
|
return app.request
|
|
|
|
.put('/api/admin/features/should-not-exist')
|
|
|
|
.send({ name: 'should-not-exist', enabled: false })
|
|
|
|
.set('Content-Type', 'application/json')
|
|
|
|
.expect(404);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('can change status of feature toggle that does exist', async () => {
|
|
|
|
expect.assertions(0);
|
|
|
|
return app.request
|
2017-06-28 10:20:22 +02:00
|
|
|
.put('/api/admin/features/featureY')
|
|
|
|
.send({
|
|
|
|
name: 'featureY',
|
|
|
|
enabled: true,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
})
|
|
|
|
.set('Content-Type', 'application/json')
|
2019-10-03 15:01:33 +02:00
|
|
|
.expect(200);
|
2017-06-28 10:20:22 +02:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('can not toggle of feature that does not exist', async () => {
|
|
|
|
expect.assertions(0);
|
|
|
|
return app.request
|
2017-06-28 10:20:22 +02:00
|
|
|
.post('/api/admin/features/should-not-exist/toggle')
|
|
|
|
.set('Content-Type', 'application/json')
|
2019-10-03 15:01:33 +02:00
|
|
|
.expect(404);
|
2017-06-28 10:20:22 +02:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('can toggle a feature that does exist', async () => {
|
|
|
|
expect.assertions(0);
|
2021-09-13 10:23:57 +02:00
|
|
|
const featureName = 'existing.feature';
|
2021-09-20 12:13:38 +02:00
|
|
|
const username = 'toggle-feature';
|
2021-08-12 15:04:37 +02:00
|
|
|
const feature =
|
|
|
|
await app.services.featureToggleServiceV2.createFeatureToggle(
|
|
|
|
'default',
|
|
|
|
{
|
2021-09-13 10:23:57 +02:00
|
|
|
name: featureName,
|
2021-08-12 15:04:37 +02:00
|
|
|
},
|
|
|
|
'test',
|
|
|
|
);
|
2021-09-13 10:23:57 +02:00
|
|
|
await app.services.featureToggleServiceV2.createStrategy(
|
|
|
|
defaultStrategy,
|
|
|
|
'default',
|
|
|
|
featureName,
|
2021-09-20 12:13:38 +02:00
|
|
|
username,
|
2021-09-13 10:23:57 +02:00
|
|
|
);
|
2021-05-28 11:10:24 +02:00
|
|
|
return app.request
|
2021-07-07 10:46:50 +02:00
|
|
|
.post(`/api/admin/features/${feature.name}/toggle`)
|
2017-06-28 10:20:22 +02:00
|
|
|
.set('Content-Type', 'application/json')
|
2019-10-03 15:01:33 +02:00
|
|
|
.expect(200);
|
2017-06-28 10:20:22 +02:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('archives a feature by name', async () => {
|
|
|
|
expect.assertions(0);
|
|
|
|
return app.request.delete('/api/admin/features/featureX').expect(200);
|
2017-06-28 10:20:22 +02:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('can not archive unknown feature', async () => {
|
|
|
|
expect.assertions(0);
|
|
|
|
return app.request.delete('/api/admin/features/featureUnknown').expect(404);
|
2017-06-28 10:20:22 +02:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('refuses to create a feature with an existing name', async () => {
|
|
|
|
expect.assertions(0);
|
|
|
|
return app.request
|
2017-06-28 10:20:22 +02:00
|
|
|
.post('/api/admin/features')
|
|
|
|
.send({ name: 'featureX' })
|
|
|
|
.set('Content-Type', 'application/json')
|
2020-09-25 22:31:35 +02:00
|
|
|
.expect(409);
|
2017-06-28 10:20:22 +02:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('refuses to validate a feature with an existing name', async () => {
|
|
|
|
expect.assertions(0);
|
|
|
|
return app.request
|
2017-06-28 10:20:22 +02:00
|
|
|
.post('/api/admin/features/validate')
|
|
|
|
.send({ name: 'featureX' })
|
|
|
|
.set('Content-Type', 'application/json')
|
2020-09-25 22:31:35 +02:00
|
|
|
.expect(409);
|
2017-06-28 10:20:22 +02:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('new strategies api can add two strategies to a feature toggle', async () => {
|
|
|
|
expect.assertions(0);
|
|
|
|
return app.request
|
|
|
|
.put('/api/admin/features/featureY')
|
|
|
|
.send({
|
|
|
|
name: 'featureY',
|
|
|
|
description: 'soon to be the #14 feature',
|
|
|
|
enabled: false,
|
|
|
|
strategies: [
|
|
|
|
{
|
|
|
|
name: 'baz',
|
|
|
|
parameters: { foo: 'bar' },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
})
|
|
|
|
.set('Content-Type', 'application/json')
|
|
|
|
.expect(200);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should not be possible to create archived toggle', async () => {
|
|
|
|
expect.assertions(0);
|
|
|
|
return app.request
|
2017-12-18 09:08:04 +01:00
|
|
|
.post('/api/admin/features')
|
|
|
|
.send({
|
|
|
|
name: 'featureArchivedX',
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
})
|
|
|
|
.set('Content-Type', 'application/json')
|
2020-09-25 22:31:35 +02:00
|
|
|
.expect(409);
|
2017-12-18 09:08:04 +01:00
|
|
|
});
|
2019-01-29 09:21:54 +01:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('creates new feature toggle with variant overrides', async () => {
|
|
|
|
expect.assertions(0);
|
|
|
|
return app.request
|
2019-01-29 09:21:54 +01:00
|
|
|
.post('/api/admin/features')
|
|
|
|
.send({
|
2019-10-03 15:01:33 +02:00
|
|
|
name: 'com.test.variants.overrieds',
|
2019-01-29 09:21:54 +01:00
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
variants: [
|
|
|
|
{
|
|
|
|
name: 'variant1',
|
|
|
|
weight: 50,
|
|
|
|
overrides: [
|
|
|
|
{
|
2019-02-04 14:04:58 +01:00
|
|
|
contextName: 'userId',
|
2019-01-29 09:21:54 +01:00
|
|
|
values: ['123'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{ name: 'variant2', weight: 50 },
|
|
|
|
],
|
|
|
|
})
|
|
|
|
.set('Content-Type', 'application/json')
|
2019-10-03 15:01:33 +02:00
|
|
|
.expect(201);
|
2019-01-29 09:21:54 +01:00
|
|
|
});
|
2020-08-06 11:18:52 +02:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('creates new feature toggle without type', async () => {
|
|
|
|
expect.assertions(1);
|
|
|
|
await app.request.post('/api/admin/features').send({
|
2020-08-06 11:18:52 +02:00
|
|
|
name: 'com.test.noType',
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
});
|
2021-05-28 11:10:24 +02:00
|
|
|
return app.request
|
|
|
|
.get('/api/admin/features/com.test.noType')
|
2021-08-12 15:04:37 +02:00
|
|
|
.expect((res) => {
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(res.body.type).toBe('release');
|
|
|
|
});
|
2020-08-06 11:18:52 +02:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('creates new feature toggle with type', async () => {
|
|
|
|
expect.assertions(1);
|
|
|
|
await app.request.post('/api/admin/features').send({
|
2020-08-06 11:18:52 +02:00
|
|
|
name: 'com.test.withType',
|
|
|
|
type: 'killswitch',
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
});
|
2021-05-28 11:10:24 +02:00
|
|
|
return app.request
|
|
|
|
.get('/api/admin/features/com.test.withType')
|
2021-07-07 10:46:50 +02:00
|
|
|
.expect(200)
|
2021-08-12 15:04:37 +02:00
|
|
|
.expect((res) => {
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(res.body.type).toBe('killswitch');
|
|
|
|
});
|
2020-08-06 11:18:52 +02:00
|
|
|
});
|
2021-01-04 10:29:33 +01:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('tags feature with new tag', async () => {
|
|
|
|
expect.assertions(1);
|
|
|
|
await app.request.post('/api/admin/features').send({
|
2021-01-04 10:29:33 +01:00
|
|
|
name: 'test.feature',
|
|
|
|
type: 'killswitch',
|
|
|
|
enabled: true,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
});
|
2021-05-28 11:10:24 +02:00
|
|
|
await app.request
|
2021-01-04 10:29:33 +01:00
|
|
|
.post('/api/admin/features/test.feature/tags')
|
|
|
|
.send({
|
|
|
|
value: 'TeamGreen',
|
|
|
|
type: 'simple',
|
|
|
|
})
|
|
|
|
.set('Content-Type', 'application/json');
|
2021-05-28 11:10:24 +02:00
|
|
|
return app.request
|
|
|
|
.get('/api/admin/features/test.feature/tags')
|
2021-08-12 15:04:37 +02:00
|
|
|
.expect((res) => {
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(res.body.tags[0].value).toBe('TeamGreen');
|
|
|
|
});
|
2021-01-04 10:29:33 +01:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('tagging a feature with an already existing tag should be a noop', async () => {
|
|
|
|
expect.assertions(1);
|
|
|
|
await app.request.post('/api/admin/features').send({
|
|
|
|
name: 'test.feature',
|
|
|
|
type: 'killswitch',
|
|
|
|
enabled: true,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
});
|
|
|
|
await app.request.post('/api/admin/features/test.feature/tags').send({
|
|
|
|
value: 'TeamGreen',
|
|
|
|
type: 'simple',
|
|
|
|
});
|
|
|
|
await app.request.post('/api/admin/features/test.feature/tags').send({
|
|
|
|
value: 'TeamGreen',
|
|
|
|
type: 'simple',
|
|
|
|
});
|
|
|
|
return app.request
|
|
|
|
.get('/api/admin/features/test.feature/tags')
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200)
|
2021-08-12 15:04:37 +02:00
|
|
|
.expect((res) => {
|
2021-07-07 10:46:50 +02:00
|
|
|
expect(res.body.tags).toHaveLength(1);
|
2021-01-04 10:29:33 +01:00
|
|
|
});
|
2021-05-28 11:10:24 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('can untag feature', async () => {
|
|
|
|
expect.assertions(1);
|
2021-02-23 13:53:09 +01:00
|
|
|
const feature1Name = faker.lorem.slug(3);
|
2021-05-28 11:10:24 +02:00
|
|
|
await app.request.post('/api/admin/features').send({
|
2021-02-08 16:22:15 +01:00
|
|
|
name: feature1Name,
|
2021-01-04 10:29:33 +01:00
|
|
|
type: 'killswitch',
|
|
|
|
enabled: true,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
});
|
2021-02-23 13:53:09 +01:00
|
|
|
const tag = {
|
|
|
|
value: faker.lorem.slug(1),
|
|
|
|
type: 'simple',
|
|
|
|
};
|
2021-05-28 11:10:24 +02:00
|
|
|
await app.request
|
2021-02-08 16:22:15 +01:00
|
|
|
.post(`/api/admin/features/${feature1Name}/tags`)
|
2021-01-04 10:29:33 +01:00
|
|
|
.send(tag)
|
|
|
|
.expect(201);
|
2021-05-28 11:10:24 +02:00
|
|
|
await app.request
|
2021-01-04 10:29:33 +01:00
|
|
|
.delete(
|
2021-02-08 16:22:15 +01:00
|
|
|
`/api/admin/features/${feature1Name}/tags/${tag.type}/${tag.value}`,
|
2021-01-04 10:29:33 +01:00
|
|
|
)
|
|
|
|
.expect(200);
|
2021-05-28 11:10:24 +02:00
|
|
|
return app.request
|
2021-02-08 16:22:15 +01:00
|
|
|
.get(`/api/admin/features/${feature1Name}/tags`)
|
2021-01-04 10:29:33 +01:00
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200)
|
2021-08-12 15:04:37 +02:00
|
|
|
.expect((res) => {
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(res.body.tags).toHaveLength(0);
|
2021-01-04 10:29:33 +01:00
|
|
|
});
|
|
|
|
});
|
2021-01-22 13:39:42 +01:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('Can get features tagged by tag', async () => {
|
|
|
|
expect.assertions(2);
|
2021-02-08 16:22:15 +01:00
|
|
|
const feature1Name = faker.helpers.slugify(faker.lorem.words(3));
|
|
|
|
const feature2Name = faker.helpers.slugify(faker.lorem.words(3));
|
2021-05-28 11:10:24 +02:00
|
|
|
await app.request.post('/api/admin/features').send({
|
2021-02-08 16:22:15 +01:00
|
|
|
name: feature1Name,
|
2021-01-22 13:39:42 +01:00
|
|
|
type: 'killswitch',
|
|
|
|
enabled: true,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
});
|
2021-05-28 11:10:24 +02:00
|
|
|
await app.request.post('/api/admin/features').send({
|
2021-02-08 16:22:15 +01:00
|
|
|
name: feature2Name,
|
2021-01-22 13:39:42 +01:00
|
|
|
type: 'killswitch',
|
|
|
|
enabled: true,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
});
|
2021-02-08 16:22:15 +01:00
|
|
|
const tag = { value: faker.lorem.word(), type: 'simple' };
|
2021-05-28 11:10:24 +02:00
|
|
|
await app.request
|
2021-02-08 16:22:15 +01:00
|
|
|
.post(`/api/admin/features/${feature1Name}/tags`)
|
2021-01-22 13:39:42 +01:00
|
|
|
.send(tag)
|
|
|
|
.expect(201);
|
2021-05-28 11:10:24 +02:00
|
|
|
return app.request
|
2021-02-08 16:22:15 +01:00
|
|
|
.get(`/api/admin/features?tag=${tag.type}:${tag.value}`)
|
2021-01-22 13:39:42 +01:00
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200)
|
2021-08-12 15:04:37 +02:00
|
|
|
.expect((res) => {
|
2021-07-07 10:46:50 +02:00
|
|
|
expect(res.body.features).toHaveLength(1);
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(res.body.features[0].name).toBe(feature1Name);
|
2021-01-22 13:39:42 +01:00
|
|
|
});
|
|
|
|
});
|
2021-05-28 11:10:24 +02:00
|
|
|
test('Can query for multiple tags using OR', async () => {
|
|
|
|
expect.assertions(3);
|
2021-02-08 16:22:15 +01:00
|
|
|
const feature1Name = faker.helpers.slugify(faker.lorem.words(3));
|
|
|
|
const feature2Name = faker.helpers.slugify(faker.lorem.words(3));
|
2021-05-28 11:10:24 +02:00
|
|
|
await app.request.post('/api/admin/features').send({
|
2021-02-08 16:22:15 +01:00
|
|
|
name: feature1Name,
|
2021-01-22 13:39:42 +01:00
|
|
|
type: 'killswitch',
|
|
|
|
enabled: true,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
});
|
2021-05-28 11:10:24 +02:00
|
|
|
await app.request.post('/api/admin/features').send({
|
2021-02-08 16:22:15 +01:00
|
|
|
name: feature2Name,
|
2021-01-22 13:39:42 +01:00
|
|
|
type: 'killswitch',
|
|
|
|
enabled: true,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
});
|
2021-02-08 16:22:15 +01:00
|
|
|
const tag = { value: faker.name.firstName(), type: 'simple' };
|
|
|
|
const tag2 = { value: faker.name.firstName(), type: 'simple' };
|
2021-05-28 11:10:24 +02:00
|
|
|
await app.request
|
2021-02-08 16:22:15 +01:00
|
|
|
.post(`/api/admin/features/${feature1Name}/tags`)
|
2021-01-22 13:39:42 +01:00
|
|
|
.send(tag)
|
|
|
|
.expect(201);
|
2021-05-28 11:10:24 +02:00
|
|
|
await app.request
|
2021-02-08 16:22:15 +01:00
|
|
|
.post(`/api/admin/features/${feature2Name}/tags`)
|
2021-01-22 13:39:42 +01:00
|
|
|
.send(tag2)
|
|
|
|
.expect(201);
|
2021-05-28 11:10:24 +02:00
|
|
|
return app.request
|
2021-02-08 16:22:15 +01:00
|
|
|
.get(
|
|
|
|
`/api/admin/features?tag[]=${tag.type}:${tag.value}&tag[]=${tag2.type}:${tag2.value}`,
|
|
|
|
)
|
2021-01-22 13:39:42 +01:00
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200)
|
2021-08-12 15:04:37 +02:00
|
|
|
.expect((res) => {
|
2021-07-07 10:46:50 +02:00
|
|
|
expect(res.body.features).toHaveLength(2);
|
2021-08-12 15:04:37 +02:00
|
|
|
expect(res.body.features.some((f) => f.name === feature1Name)).toBe(
|
2021-05-28 11:10:24 +02:00
|
|
|
true,
|
|
|
|
);
|
2021-08-12 15:04:37 +02:00
|
|
|
expect(res.body.features.some((f) => f.name === feature2Name)).toBe(
|
2021-05-28 11:10:24 +02:00
|
|
|
true,
|
|
|
|
);
|
2021-01-22 13:39:42 +01:00
|
|
|
});
|
|
|
|
});
|
2021-05-28 11:10:24 +02:00
|
|
|
test('Querying with multiple filters ANDs the filters', async () => {
|
2021-02-08 16:22:15 +01:00
|
|
|
const feature1Name = `test.${faker.helpers.slugify(faker.hacker.phrase())}`;
|
|
|
|
const feature2Name = faker.helpers.slugify(faker.lorem.words());
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
await app.request.post('/api/admin/features').send({
|
2021-02-08 16:22:15 +01:00
|
|
|
name: feature1Name,
|
2021-01-22 13:39:42 +01:00
|
|
|
type: 'killswitch',
|
|
|
|
enabled: true,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
});
|
2021-05-28 11:10:24 +02:00
|
|
|
await app.request.post('/api/admin/features').send({
|
2021-02-08 16:22:15 +01:00
|
|
|
name: feature2Name,
|
2021-01-22 13:39:42 +01:00
|
|
|
type: 'killswitch',
|
|
|
|
enabled: true,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
});
|
2021-05-28 11:10:24 +02:00
|
|
|
await app.request.post('/api/admin/features').send({
|
2021-01-22 13:39:42 +01:00
|
|
|
name: 'notestprefix.feature3',
|
|
|
|
type: 'release',
|
|
|
|
enabled: true,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
});
|
2021-02-08 16:22:15 +01:00
|
|
|
const tag = { value: faker.lorem.word(), type: 'simple' };
|
|
|
|
const tag2 = { value: faker.name.firstName(), type: 'simple' };
|
2021-05-28 11:10:24 +02:00
|
|
|
await app.request
|
2021-02-08 16:22:15 +01:00
|
|
|
.post(`/api/admin/features/${feature1Name}/tags`)
|
2021-01-22 13:39:42 +01:00
|
|
|
.send(tag)
|
|
|
|
.expect(201);
|
2021-05-28 11:10:24 +02:00
|
|
|
await app.request
|
2021-02-08 16:22:15 +01:00
|
|
|
.post(`/api/admin/features/${feature2Name}/tags`)
|
2021-01-22 13:39:42 +01:00
|
|
|
.send(tag2)
|
|
|
|
.expect(201);
|
2021-05-28 11:10:24 +02:00
|
|
|
await app.request
|
2021-01-22 13:39:42 +01:00
|
|
|
.post('/api/admin/features/notestprefix.feature3/tags')
|
|
|
|
.send(tag)
|
|
|
|
.expect(201);
|
2021-05-28 11:10:24 +02:00
|
|
|
await app.request
|
2021-02-08 16:22:15 +01:00
|
|
|
.get(`/api/admin/features?tag=${tag.type}:${tag.value}`)
|
2021-01-22 13:39:42 +01:00
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200)
|
2021-08-12 15:04:37 +02:00
|
|
|
.expect((res) => expect(res.body.features).toHaveLength(2));
|
2021-05-28 11:10:24 +02:00
|
|
|
await app.request
|
2021-02-08 16:22:15 +01:00
|
|
|
.get(`/api/admin/features?namePrefix=test&tag=${tag.type}:${tag.value}`)
|
2021-01-22 13:39:42 +01:00
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200)
|
2021-08-12 15:04:37 +02:00
|
|
|
.expect((res) => {
|
2021-07-07 10:46:50 +02:00
|
|
|
expect(res.body.features).toHaveLength(1);
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(res.body.features[0].name).toBe(feature1Name);
|
2021-01-22 13:39:42 +01:00
|
|
|
});
|
|
|
|
});
|
2021-02-08 16:22:15 +01:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('Tagging a feature with a tag it already has should return 409', async () => {
|
|
|
|
const feature1Name = `test.${faker.helpers.slugify(faker.lorem.words(3))}`;
|
|
|
|
await app.request.post('/api/admin/features').send({
|
|
|
|
name: feature1Name,
|
|
|
|
type: 'killswitch',
|
|
|
|
enabled: true,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
});
|
|
|
|
|
|
|
|
const tag = { value: faker.lorem.word(), type: 'simple' };
|
|
|
|
await app.request
|
|
|
|
.post(`/api/admin/features/${feature1Name}/tags`)
|
|
|
|
.send(tag)
|
|
|
|
.expect(201);
|
|
|
|
return app.request
|
|
|
|
.post(`/api/admin/features/${feature1Name}/tags`)
|
|
|
|
.send(tag)
|
|
|
|
.expect(409)
|
2021-08-12 15:04:37 +02:00
|
|
|
.expect((res) => {
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(res.body.details[0].message).toBe(
|
|
|
|
`${feature1Name} already had the tag: [${tag.type}:${tag.value}]`,
|
|
|
|
);
|
2021-02-08 16:22:15 +01:00
|
|
|
});
|
2021-05-28 11:10:24 +02:00
|
|
|
});
|
2021-02-08 16:22:15 +01:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('marks feature toggle as stale', async () => {
|
|
|
|
expect.assertions(1);
|
|
|
|
await app.request
|
2021-02-18 09:18:04 +01:00
|
|
|
.post('/api/admin/features/featureZ/stale/on')
|
|
|
|
.set('Content-Type', 'application/json');
|
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
return app.request.get('/api/admin/features/featureZ').expect((res) => {
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(res.body.stale).toBe(true);
|
2021-02-18 09:18:04 +01:00
|
|
|
});
|
|
|
|
});
|