1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

fix: remove fields from /api/client/features respnse (#692)

This commit is contained in:
Ivar Conradi Østhus 2021-01-22 13:09:26 +01:00 committed by GitHub
parent f850986b9c
commit f5aa5b577c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 59 additions and 3 deletions

View File

@ -1,5 +1,9 @@
# Changelog
## 3.10.1
- fix: remove fields from /api/client/features respnse (#692)
## 3.10.0
- feat: add tags (#655)
@ -11,7 +15,6 @@
- fix: Updated docs about event-types (#684)
- fix: Add application-created event (#595)
## 3.9.0
- fix: stateService undefined

View File

@ -18,6 +18,15 @@ const FEATURE_COLUMNS = [
];
const TABLE = 'features';
const FEATURE_COLUMNS_CLIENT = [
'name',
'type',
'enabled',
'stale',
'strategies',
'variants',
];
class FeatureToggleStore {
constructor(db, eventBus, getLogger) {
this.db = db;
@ -43,6 +52,34 @@ class FeatureToggleStore {
return rows.map(this.rowToFeature);
}
async getFeaturesClient() {
const stopTimer = this.timer('getAllClient');
const rows = await this.db
.select(FEATURE_COLUMNS_CLIENT)
.from(TABLE)
.where({ archived: 0 })
.orderBy('name', 'asc');
stopTimer();
return rows.map(this.rowToFeature);
}
async getClientFeatures() {
const stopTimer = this.timer('getAll');
const rows = await this.db
.select(FEATURE_COLUMNS)
.from(TABLE)
.where({ archived: 0 })
.orderBy('name', 'asc');
stopTimer();
return rows.map(this.rowToFeature);
}
async getFeaturesBy(fields) {
const rows = await this.db
.select(FEATURE_COLUMNS)

View File

@ -17,7 +17,7 @@ class FeatureController extends Controller {
async getAll(req, res) {
const nameFilter = filter('name', req.query.namePrefix);
const allFeatureToggles = await this.toggleService.getFeatures();
const allFeatureToggles = await this.toggleService.getFeaturesClient();
const features = nameFilter(allFeatureToggles);
res.json({ version, features });

View File

@ -27,6 +27,10 @@ class FeatureToggleService {
return this.featureToggleStore.getFeatures();
}
async getFeaturesClient() {
return this.featureToggleStore.getFeaturesClient();
}
async getArchivedFeatures() {
return this.featureToggleStore.getArchivedFeatures();
}

View File

@ -23,7 +23,18 @@ test.serial('returns four feature toggles', async t => {
.expect('Content-Type', /json/)
.expect(200)
.expect(res => {
t.true(res.body.features.length === 4);
t.is(res.body.features.length, 4);
});
});
test.serial('returns four feature toggles without createdAt', async t => {
const request = await setupApp(stores);
return request
.get('/api/client/features')
.expect('Content-Type', /json/)
.expect(200)
.expect(res => {
t.falsy(res.body.features[0].createdAt);
});
});

View File

@ -30,6 +30,7 @@ module.exports = () => {
_features.push(updatedFeature);
},
getFeatures: () => Promise.resolve(_features),
getFeaturesClient: () => Promise.resolve(_features),
createFeature: feature => _features.push(feature),
getArchivedFeatures: () => Promise.resolve(_archive),
addArchivedFeature: feature => _archive.push(feature),