diff --git a/lib/routes/admin-api/feature.test.js b/lib/routes/admin-api/feature.test.js index 0a78ec6407..4c6590e079 100644 --- a/lib/routes/admin-api/feature.test.js +++ b/lib/routes/admin-api/feature.test.js @@ -238,3 +238,37 @@ test('invalid feature names should have error msg', t => { ); }); }); + +test('should not allow variants with same name when creating feature flag', t => { + t.plan(0); + const { request, base } = getSetup(); + + return request + .post(`${base}/api/admin/features`) + .send({ + name: 'ts', + strategies: [{ name: 'default' }], + variants: [{ name: 'variant1' }, { name: 'variant1' }], + }) + .set('Content-Type', 'application/json') + .expect(403); +}); + +test('should not allow variants with same name when updating feature flag', t => { + t.plan(0); + const { request, featureToggleStore, base } = getSetup(); + featureToggleStore.addFeature({ + name: 'ts', + strategies: [{ name: 'default' }], + }); + + return request + .put(`${base}/api/admin/features/ts`) + .send({ + name: 'ts', + strategies: [{ name: 'default' }], + variants: [{ name: 'variant1' }, { name: 'variant1' }], + }) + .set('Content-Type', 'application/json') + .expect(403); +}); diff --git a/test/e2e/api/admin/feature.e2e.test.js b/test/e2e/api/admin/feature.e2e.test.js index 357b54fe33..e8d2cf8298 100644 --- a/test/e2e/api/admin/feature.e2e.test.js +++ b/test/e2e/api/admin/feature.e2e.test.js @@ -3,14 +3,14 @@ const test = require('ava'); const { setupApp } = require('./../../helpers/test-helper'); -test.serial('returns three feature toggles', async t => { +test.serial('returns list of feature toggles', async t => { const { request, destroy } = await setupApp('feature_api_serial'); return request .get('/api/admin/features') .expect('Content-Type', /json/) .expect(200) .expect(res => { - t.true(res.body.features.length === 3); + t.true(res.body.features.length === 4); }) .then(destroy); }); @@ -51,9 +51,9 @@ test.serial('creates new feature toggle', async t => { }); test.serial('creates new feature toggle with variants', async t => { - t.plan(1); + t.plan(0); const { request, destroy } = await setupApp('feature_api_serial'); - await request + return request .post('/api/admin/features') .send({ name: 'com.test.variants', @@ -61,9 +61,16 @@ test.serial('creates new feature toggle with variants', async t => { strategies: [{ name: 'default' }], variants: [{ name: 'variant1' }, { name: 'variant2' }], }) - .set('Content-Type', 'application/json'); - await request - .get('/api/admin/features/com.test.variants') + .set('Content-Type', 'application/json') + .expect(201) + .then(destroy); +}); + +test.serial('fetch feature toggle with variants', async t => { + t.plan(1); + const { request, destroy } = await setupApp('feature_api_serial'); + return request + .get('/api/admin/features/feature.with.variants') .expect(res => { t.true(res.body.variants.length === 2); }) diff --git a/test/e2e/api/client/feature.e2e.test.js b/test/e2e/api/client/feature.e2e.test.js index 42650c881f..e27ca5e640 100644 --- a/test/e2e/api/client/feature.e2e.test.js +++ b/test/e2e/api/client/feature.e2e.test.js @@ -3,14 +3,14 @@ const test = require('ava'); const { setupApp } = require('./../../helpers/test-helper'); -test.serial('returns three feature toggles', async t => { +test.serial('returns four feature toggles', async t => { const { request, destroy } = await setupApp('feature_api_client'); return request .get('/api/client/features') .expect('Content-Type', /json/) .expect(200) .expect(res => { - t.true(res.body.features.length === 3); + t.true(res.body.features.length === 4); }) .then(destroy); }); diff --git a/test/e2e/helpers/database.json b/test/e2e/helpers/database.json index 45e849968a..d9560b9de6 100644 --- a/test/e2e/helpers/database.json +++ b/test/e2e/helpers/database.json @@ -120,6 +120,14 @@ } } ] + }, + { + "name": "feature.with.variants", + "description": "A feature toggle with watiants", + "enabled": true, + "archived": false, + "strategies": [{ "name": "default" }], + "variants": [{ "name": "control" }, { "name": "new" }] } ] }