mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
feat/return feature on create (#742)
* feat: return feature on create * refactor: change test to verify returning object * fix: return undefined instead of null
This commit is contained in:
parent
ec3d6e95bc
commit
8e0bae7352
@ -169,10 +169,15 @@ class FeatureToggleStore {
|
|||||||
|
|
||||||
async createFeature(data) {
|
async createFeature(data) {
|
||||||
try {
|
try {
|
||||||
await this.db(TABLE).insert(this.eventDataToRow(data));
|
const row = await this.db(TABLE)
|
||||||
|
.insert(this.eventDataToRow(data))
|
||||||
|
.returning(FEATURE_COLUMNS);
|
||||||
|
|
||||||
|
return this.rowToFeature(row[0]);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.error('Could not insert feature, error: ', err);
|
this.logger.error('Could not insert feature, error: ', err);
|
||||||
}
|
}
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateFeature(data) {
|
async updateFeature(data) {
|
||||||
|
@ -126,8 +126,11 @@ class FeatureController extends Controller {
|
|||||||
const userName = extractUser(req);
|
const userName = extractUser(req);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.featureService.createFeatureToggle(req.body, userName);
|
const createdFeature = await this.featureService.createFeatureToggle(
|
||||||
res.status(201).end();
|
req.body,
|
||||||
|
userName,
|
||||||
|
);
|
||||||
|
res.status(201).json(createdFeature);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleErrors(res, this.logger, error);
|
handleErrors(res, this.logger, error);
|
||||||
}
|
}
|
||||||
|
@ -64,13 +64,16 @@ class FeatureToggleService {
|
|||||||
|
|
||||||
async createFeatureToggle(value, userName) {
|
async createFeatureToggle(value, userName) {
|
||||||
await this.validateName(value);
|
await this.validateName(value);
|
||||||
const feature = await featureSchema.validateAsync(value);
|
const featureData = await featureSchema.validateAsync(value);
|
||||||
await this.featureToggleStore.createFeature(feature);
|
const feature = await this.featureToggleStore.createFeature(
|
||||||
|
featureData,
|
||||||
|
);
|
||||||
await this.eventStore.store({
|
await this.eventStore.store({
|
||||||
type: FEATURE_CREATED,
|
type: FEATURE_CREATED,
|
||||||
createdBy: userName,
|
createdBy: userName,
|
||||||
data: feature,
|
data: featureData,
|
||||||
});
|
});
|
||||||
|
return feature;
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateToggle(updatedFeature, userName) {
|
async updateToggle(updatedFeature, userName) {
|
||||||
|
@ -47,7 +47,7 @@ test.serial('cant get feature that dose not exist', async t => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test.serial('creates new feature toggle', async t => {
|
test.serial('creates new feature toggle', async t => {
|
||||||
t.plan(0);
|
t.plan(3);
|
||||||
const request = await setupApp(stores);
|
const request = await setupApp(stores);
|
||||||
return request
|
return request
|
||||||
.post('/api/admin/features')
|
.post('/api/admin/features')
|
||||||
@ -57,7 +57,12 @@ test.serial('creates new feature toggle', async t => {
|
|||||||
strategies: [{ name: 'default' }],
|
strategies: [{ name: 'default' }],
|
||||||
})
|
})
|
||||||
.set('Content-Type', 'application/json')
|
.set('Content-Type', 'application/json')
|
||||||
.expect(201);
|
.expect(201)
|
||||||
|
.expect(res => {
|
||||||
|
t.is(res.body.name, 'com.test.feature');
|
||||||
|
t.is(res.body.enabled, false);
|
||||||
|
t.truthy(res.body.createdAt);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test.serial('creates new feature toggle with variants', async t => {
|
test.serial('creates new feature toggle with variants', async t => {
|
||||||
|
Loading…
Reference in New Issue
Block a user