1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-04-15 01:16:22 +02:00

Some tweaks to favorites (#2563)

This is follow up PR to https://github.com/Unleash/unleash/pull/2550,
which addresses the issues that came up from reviews.
This commit is contained in:
sjaanus 2022-11-30 08:47:57 +01:00 committed by GitHub
parent 9ac6b945be
commit 0d58371f11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 38 deletions

View File

@ -259,14 +259,16 @@ class FeatureStrategiesStore implements IFeatureStrategiesStore {
let selectColumns = ['features_view.*'];
if (userId && this.flagResolver.isEnabled('favorites')) {
query = query.leftJoin(`favorite_features as ff`, function () {
this.on('ff.feature', 'features_view.name').andOnVal(
'ff.user_id',
'=',
userId,
);
query = query.leftJoin(`favorite_features`, function () {
this.on(
'favorite_features.feature',
'features_view.name',
).andOnVal('favorite_features.user_id', '=', userId);
});
selectColumns = [...selectColumns, 'ff.feature as favorite'];
selectColumns = [
...selectColumns,
'favorite_features.feature as favorite',
];
}
const rows = await query.select(selectColumns);
stopTimer();

View File

@ -20,8 +20,6 @@ const createFeature = async (featureName: string) => {
})
.set('Content-Type', 'application/json')
.expect(201);
// await projectService.addEnvironmentToProject('default', environment);
};
const loginRegularUser = () =>
@ -39,6 +37,20 @@ const createUserEditorAccess = async (name, email) => {
return user;
};
const favoriteFeature = async (featureName: string) => {
await app.request
.post(`/api/admin/projects/default/features/${featureName}/favorites`)
.set('Content-Type', 'application/json')
.expect(200);
};
const unfavoriteFeature = async (featureName: string) => {
await app.request
.delete(`/api/admin/projects/default/features/${featureName}/favorites`)
.set('Content-Type', 'application/json')
.expect(200);
};
beforeAll(async () => {
db = await dbInit('favorites_api_serial', getLogger);
app = await setupAppWithAuth(db.stores);
@ -67,14 +79,10 @@ beforeEach(async () => {
await loginRegularUser();
});
test('should have favorites true in project endpoint', async () => {
test('should be favorited in project endpoint', async () => {
const featureName = 'test-feature';
await createFeature(featureName);
await app.request
.post(`/api/admin/projects/default/features/${featureName}/favorites`)
.set('Content-Type', 'application/json')
.expect(200);
await favoriteFeature(featureName);
const { body } = await app.request
.get(`/api/admin/projects/default/features`)
@ -88,7 +96,7 @@ test('should have favorites true in project endpoint', async () => {
});
});
test('should have favorites false by default', async () => {
test('feature should not be favorited by default', async () => {
const featureName = 'test-feature';
await createFeature(featureName);
@ -104,14 +112,10 @@ test('should have favorites false by default', async () => {
});
});
test('should have favorites true in admin endpoint', async () => {
test('should be favorited in admin endpoint', async () => {
const featureName = 'test-feature';
await createFeature(featureName);
await app.request
.post(`/api/admin/projects/default/features/${featureName}/favorites`)
.set('Content-Type', 'application/json')
.expect(200);
await favoriteFeature(featureName);
const { body } = await app.request
.get(`/api/admin/features`)
@ -125,14 +129,10 @@ test('should have favorites true in admin endpoint', async () => {
});
});
test('should have favorites true in project single feature endpoint', async () => {
test('should be favorited in project single feature endpoint', async () => {
const featureName = 'test-feature';
await createFeature(featureName);
await app.request
.post(`/api/admin/projects/default/features/${featureName}/favorites`)
.set('Content-Type', 'application/json')
.expect(200);
await favoriteFeature(featureName);
const { body } = await app.request
.get(`/api/admin/projects/default/features/${featureName}`)
@ -145,19 +145,12 @@ test('should have favorites true in project single feature endpoint', async () =
});
});
test('should have favorites false after deleting favorite', async () => {
test('should be able to unfavorite feature', async () => {
const featureName = 'test-feature';
await createFeature(featureName);
await app.request
.post(`/api/admin/projects/default/features/${featureName}/favorites`)
.set('Content-Type', 'application/json')
.expect(200);
await app.request
.delete(`/api/admin/projects/default/features/${featureName}/favorites`)
.set('Content-Type', 'application/json')
.expect(200);
await favoriteFeature(featureName);
await unfavoriteFeature(featureName);
const { body } = await app.request
.get(`/api/admin/projects/default/features/${featureName}`)