Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add project filter to feature-toggle-list-builder #5099

Merged
merged 2 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/lib/features/feature-toggle/feature-toggle-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ export default class FeatureToggleStore implements IFeatureToggleStore {
builder.addSelectColumn('df.enabled as parent_enabled');
}

if (featureQuery?.project) {
builder.forProject(featureQuery.project);
}

const rows = await builder.internalQuery.select(
builder.getSelectColumns(),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ export class FeatureToggleListBuilder {
userId,
);
});

return this;
}
}

forProject = (project: string[]) => {
this.internalQuery.whereIn('features.project', project);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import dbInit from '../../../../test/e2e/helpers/database-init';
import getLogger from '../../../../test/fixtures/no-logger';
import { FeatureToggleDTO, IFeatureToggleStore } from '../../../types';
import {
FeatureToggleDTO,
IFeatureToggleStore,
IProjectStore,
} from '../../../types';

let stores;
let db;
let featureToggleStore: IFeatureToggleStore;
let projectStore: IProjectStore;

beforeAll(async () => {
getLogger.setMuteError(true);
db = await dbInit('feature_toggle_store_serial', getLogger);
stores = db.stores;
featureToggleStore = stores.featureToggleStore;
projectStore = stores.projectStore;
});

afterAll(async () => {
Expand Down Expand Up @@ -301,5 +307,24 @@ describe('potentially_stale marking', () => {

expect(potentiallyStale).toBeFalsy();
});

test('it should filter projects for playground', async () => {
await projectStore.create({
id: 'MyProject',
name: 'MyProject',
description: 'MyProject',
});
await featureToggleStore.create('default', { name: 'featureA' });

await featureToggleStore.create('MyProject', { name: 'featureB' });

const playgroundFeatures =
await featureToggleStore.getPlaygroundFeatures({
project: ['MyProject'],
});

expect(playgroundFeatures).toHaveLength(1);
expect(playgroundFeatures[0].project).toBe('MyProject');
});
});
});
2 changes: 1 addition & 1 deletion src/lib/features/playground/playground-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class PlaygroundService {
): Promise<AdvancedPlaygroundFeatureEvaluationResult[]> {
const segments = await this.segmentService.getActive();

let filteredProjects: typeof projects;
let filteredProjects: typeof projects = projects;
if (this.flagResolver.isEnabled('privateProjects')) {
const projectAccess =
await this.privateProjectChecker.getUserAccessibleProjects(
Expand Down