Skip to content

Commit

Permalink
fix: fix bulk removal of tags (#3651)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjaanus committed Apr 28, 2023
1 parent 10fee99 commit 2a6cfc4
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/lib/db/feature-tag-store.ts
Expand Up @@ -187,13 +187,15 @@ class FeatureTagStore implements IFeatureTagStore {
}

async tagFeatures(featureTags: IFeatureTag[]): Promise<IFeatureAndTag[]> {
const rows = await this.db(TABLE)
.insert(featureTags.map(this.featureTagToRow))
.returning(COLUMNS)
.onConflict(COLUMNS)
.ignore();
if (rows) {
return rows.map(this.rowToFeatureAndTag);
if (featureTags.length !== 0) {
const rows = await this.db(TABLE)
.insert(featureTags.map(this.featureTagToRow))
.returning(COLUMNS)
.onConflict(COLUMNS)
.ignore();
if (rows) {
return rows.map(this.rowToFeatureAndTag);
}
}
return [];
}
Expand Down
45 changes: 45 additions & 0 deletions src/test/e2e/api/admin/tags.e2e.test.ts
Expand Up @@ -161,3 +161,48 @@ test('Can tag features', async () => {
expect(res.body).toMatchObject({ tags: [addedTag] });
expect(res2.body).toMatchObject({ tags: [addedTag] });
});

test('Can bulk remove tags', async () => {
const featureName = 'test.feature3';
const featureName2 = 'test.feature4';
const addedTag = {
value: 'TeamRed',
type: 'simple',
};

await app.request.post('/api/admin/projects/default/features').send({
name: featureName,
type: 'killswitch',
enabled: true,
strategies: [{ name: 'default' }],
});

await app.request.post('/api/admin/projects/default/features').send({
name: featureName2,
type: 'killswitch',
enabled: true,
strategies: [{ name: 'default' }],
});

await app.request
.put('/api/admin/tags/features')
.send({
features: [featureName, featureName2],
tags: {
addedTags: [addedTag],
removedTags: [],
},
})
.expect(200);

await app.request
.put('/api/admin/tags/features')
.send({
features: [featureName, featureName2],
tags: {
addedTags: [],
removedTags: [addedTag],
},
})
.expect(200);
});

1 comment on commit 2a6cfc4

@vercel
Copy link

@vercel vercel bot commented on 2a6cfc4 Apr 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.