mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
parent
ff261047df
commit
4999bb93cf
@ -51,6 +51,14 @@ class FeatureToggleStore {
|
||||
.then(this.rowToFeature);
|
||||
}
|
||||
|
||||
hasFeatureName(name) {
|
||||
return this.db
|
||||
.first('name')
|
||||
.from(TABLE)
|
||||
.where({ name })
|
||||
.then(n => !!n);
|
||||
}
|
||||
|
||||
getArchivedFeatures() {
|
||||
return this.db
|
||||
.select(FEATURE_COLUMNS)
|
||||
|
@ -97,12 +97,13 @@ module.exports.router = function(config) {
|
||||
|
||||
function validateUniqueName(req) {
|
||||
return new Promise((resolve, reject) => {
|
||||
featureToggleStore
|
||||
.getFeature(req.body.name)
|
||||
.then(() =>
|
||||
reject(new NameExistsError('Feature name already exist'))
|
||||
)
|
||||
.catch(() => resolve(req));
|
||||
featureToggleStore.hasFeatureName(req.body.name).then(hasName => {
|
||||
if (hasName) {
|
||||
reject(new NameExistsError('Feature name already exist'));
|
||||
} else {
|
||||
resolve(req);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -193,3 +193,18 @@ test.serial(
|
||||
.then(destroy);
|
||||
}
|
||||
);
|
||||
|
||||
test.serial('should not be possible to create archived toggle', async t => {
|
||||
t.plan(0);
|
||||
const { request, destroy } = await setupApp('feature_api_serial');
|
||||
return request
|
||||
.post('/api/admin/features')
|
||||
.send({
|
||||
name: 'featureArchivedX',
|
||||
enabled: false,
|
||||
strategies: [{ name: 'default' }],
|
||||
})
|
||||
.set('Content-Type', 'application/json')
|
||||
.expect(403)
|
||||
.then(destroy);
|
||||
});
|
||||
|
1
test/fixtures/fake-feature-toggle-store.js
vendored
1
test/fixtures/fake-feature-toggle-store.js
vendored
@ -12,6 +12,7 @@ module.exports = () => {
|
||||
}
|
||||
},
|
||||
getFeatures: () => Promise.resolve(_features),
|
||||
hasFeatureName: () => Promise.resolve(false),
|
||||
addFeature: feature => _features.push(feature),
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user