2021-08-12 15:04:37 +02:00
|
|
|
import { setupApp } from '../../helpers/test-helper';
|
|
|
|
import dbInit from '../../helpers/database-init';
|
|
|
|
import getLogger from '../../../fixtures/no-logger';
|
2019-10-03 15:01:33 +02:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
let app;
|
2021-03-19 22:25:21 +01:00
|
|
|
let db;
|
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('archive_serial', getLogger);
|
2021-05-28 11:10:24 +02:00
|
|
|
app = await setupApp(db.stores);
|
2021-07-07 10:46:50 +02:00
|
|
|
await app.services.featureToggleServiceV2.createFeatureToggle(
|
|
|
|
'default',
|
|
|
|
{
|
|
|
|
name: 'featureX',
|
|
|
|
description: 'the #1 feature',
|
|
|
|
},
|
|
|
|
'test',
|
|
|
|
);
|
|
|
|
await app.services.featureToggleServiceV2.createFeatureToggle(
|
|
|
|
'default',
|
|
|
|
{
|
|
|
|
name: 'featureY',
|
|
|
|
description: 'soon to be the #1 feature',
|
|
|
|
},
|
|
|
|
'test',
|
|
|
|
);
|
|
|
|
await app.services.featureToggleServiceV2.createFeatureToggle(
|
|
|
|
'default',
|
|
|
|
{
|
|
|
|
name: 'featureZ',
|
|
|
|
description: 'terrible feature',
|
|
|
|
},
|
|
|
|
'test',
|
|
|
|
);
|
|
|
|
await app.services.featureToggleServiceV2.createFeatureToggle(
|
|
|
|
'default',
|
|
|
|
{
|
|
|
|
name: 'featureArchivedX',
|
|
|
|
description: 'the #1 feature',
|
|
|
|
},
|
|
|
|
'test',
|
|
|
|
);
|
|
|
|
await app.services.featureToggleServiceV2.archiveToggle(
|
|
|
|
'featureArchivedX',
|
|
|
|
'test',
|
|
|
|
);
|
|
|
|
await app.services.featureToggleServiceV2.createFeatureToggle(
|
|
|
|
'default',
|
|
|
|
{
|
|
|
|
name: 'featureArchivedY',
|
|
|
|
description: 'soon to be the #1 feature',
|
|
|
|
},
|
|
|
|
'test',
|
|
|
|
);
|
|
|
|
await app.services.featureToggleServiceV2.archiveToggle(
|
|
|
|
'featureArchivedY',
|
|
|
|
'test',
|
|
|
|
);
|
|
|
|
await app.services.featureToggleServiceV2.createFeatureToggle(
|
|
|
|
'default',
|
|
|
|
{
|
|
|
|
name: 'featureArchivedZ',
|
|
|
|
description: 'terrible feature',
|
|
|
|
},
|
|
|
|
'test',
|
|
|
|
);
|
|
|
|
await app.services.featureToggleServiceV2.archiveToggle(
|
|
|
|
'featureArchivedZ',
|
|
|
|
'test',
|
|
|
|
);
|
|
|
|
await app.services.featureToggleServiceV2.createFeatureToggle(
|
|
|
|
'default',
|
|
|
|
{
|
|
|
|
name: 'feature.with.variants',
|
|
|
|
description: 'A feature toggle with variants',
|
|
|
|
variants: [
|
|
|
|
{ name: 'control', weight: 50 },
|
|
|
|
{ name: 'new', weight: 50 },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
'test',
|
|
|
|
);
|
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
|
|
|
});
|
2014-12-17 21:56:27 +01:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('returns three archived toggles', async () => {
|
|
|
|
expect.assertions(1);
|
|
|
|
return app.request
|
2017-06-28 10:20:22 +02:00
|
|
|
.get('/api/admin/archive/features')
|
2016-11-13 15:41:35 +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.features.length === 3).toBe(true);
|
2019-10-03 15:01:33 +02:00
|
|
|
});
|
2016-11-13 15:41:35 +01:00
|
|
|
});
|
2014-12-17 21:56:27 +01:00
|
|
|
|
2021-07-07 10:46:50 +02:00
|
|
|
test.skip('revives a feature by name', async () => {
|
2021-05-28 11:10:24 +02:00
|
|
|
expect.assertions(0);
|
|
|
|
return app.request
|
2017-06-28 10:20:22 +02:00
|
|
|
.post('/api/admin/archive/revive/featureArchivedX')
|
2016-11-13 15:41:35 +01:00
|
|
|
.set('Content-Type', 'application/json')
|
2019-10-03 15:01:33 +02:00
|
|
|
.expect(200);
|
2016-11-13 15:41:35 +01:00
|
|
|
});
|
2014-12-17 21:56:27 +01:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('archived feature is not accessible via /features/:featureName', async () => {
|
|
|
|
expect.assertions(0);
|
2017-06-28 17:44:14 +02:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
return app.request
|
|
|
|
.get('/api/admin/features/featureArchivedZ')
|
|
|
|
.set('Content-Type', 'application/json')
|
|
|
|
.expect(404);
|
|
|
|
});
|
2017-06-28 17:44:14 +02:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('must set name when reviving toggle', async () => {
|
|
|
|
expect.assertions(0);
|
|
|
|
return app.request.post('/api/admin/archive/revive/').expect(404);
|
2016-04-24 22:41:37 +02:00
|
|
|
});
|
2021-05-06 14:11:56 +02:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('should be allowed to reuse deleted toggle name', async () => {
|
2021-07-07 10:46:50 +02:00
|
|
|
expect.assertions(2);
|
2021-05-28 11:10:24 +02:00
|
|
|
await app.request
|
2021-05-06 14:11:56 +02:00
|
|
|
.post('/api/admin/features')
|
|
|
|
.send({
|
|
|
|
name: 'really.delete.feature',
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
})
|
|
|
|
.set('Content-Type', 'application/json')
|
|
|
|
.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('really.delete.feature');
|
|
|
|
expect(res.body.createdAt).toBeTruthy();
|
2021-05-06 14:11:56 +02:00
|
|
|
});
|
2021-05-28 11:10:24 +02:00
|
|
|
await app.request
|
2021-08-12 15:04:37 +02:00
|
|
|
.delete('/api/admin/features/really.delete.feature')
|
2021-05-06 14:11:56 +02:00
|
|
|
.expect(200);
|
2021-05-28 11:10:24 +02:00
|
|
|
await app.request
|
2021-08-12 15:04:37 +02:00
|
|
|
.delete('/api/admin/archive/really.delete.feature')
|
2021-05-06 14:11:56 +02:00
|
|
|
.expect(200);
|
2021-05-28 11:10:24 +02:00
|
|
|
return app.request
|
2021-08-12 15:04:37 +02:00
|
|
|
.post('/api/admin/features/validate')
|
2021-05-06 14:11:56 +02:00
|
|
|
.send({ name: 'really.delete.feature' })
|
|
|
|
.set('Content-Type', 'application/json')
|
|
|
|
.expect(200);
|
|
|
|
});
|
2021-05-28 11:10:24 +02:00
|
|
|
test('Deleting an unarchived toggle should not take effect', async () => {
|
2021-07-07 10:46:50 +02:00
|
|
|
expect.assertions(2);
|
2021-05-28 11:10:24 +02:00
|
|
|
await app.request
|
2021-05-06 14:11:56 +02:00
|
|
|
.post('/api/admin/features')
|
|
|
|
.send({
|
|
|
|
name: 'really.delete.feature',
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
})
|
|
|
|
.set('Content-Type', 'application/json')
|
|
|
|
.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('really.delete.feature');
|
|
|
|
expect(res.body.createdAt).toBeTruthy();
|
2021-05-06 14:11:56 +02:00
|
|
|
});
|
2021-05-28 11:10:24 +02:00
|
|
|
await app.request
|
2021-08-12 15:04:37 +02:00
|
|
|
.delete('/api/admin/archive/really.delete.feature')
|
2021-05-06 14:11:56 +02:00
|
|
|
.expect(200);
|
2021-05-28 11:10:24 +02:00
|
|
|
return app.request
|
2021-08-12 15:04:37 +02:00
|
|
|
.post('/api/admin/features/validate')
|
2021-05-06 14:11:56 +02:00
|
|
|
.send({ name: 'really.delete.feature' })
|
|
|
|
.set('Content-Type', 'application/json')
|
|
|
|
.expect(409); // because it still exists
|
|
|
|
});
|