Skip to content

Commit

Permalink
fix: ft overview last seen at (#5212)
Browse files Browse the repository at this point in the history
Fixes an issue where the query in the feature toggle overview would
return excess rows
  • Loading branch information
FredrikOseberg authored Oct 30, 2023
1 parent b69f275 commit 28c72ec
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 7 deletions.
16 changes: 11 additions & 5 deletions src/lib/features/feature-toggle/feature-toggle-strategies-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,17 @@ class FeatureStrategiesStore implements IFeatureStrategiesStore {
let selectColumns = ['features_view.*'] as (string | Raw<any>)[];

if (this.flagResolver.isEnabled('useLastSeenRefactor')) {
query.leftJoin(
'last_seen_at_metrics',
'last_seen_at_metrics.environment',
'features_view.environment_name',
);
query.leftJoin('last_seen_at_metrics', function () {
this.on(
'last_seen_at_metrics.environment',
'=',
'features_view.environment_name',
).andOn(
'last_seen_at_metrics.feature_name',
'=',
'features_view.name',
);
});
// Override feature view for now
selectColumns.push(
'last_seen_at_metrics.last_seen_at as env_last_seen_at',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,53 @@ test('response should include last seen at per environment for multiple environm
expect(production.name).toBe('production');
expect(production.lastSeenAt).toEqual('2023-10-01T12:34:56.000Z');
});

test('response should include last seen at per environment correctly for a single toggle /api/admin/project/:projectId/features/:featureName', async () => {
const featureName = 'multiple-environment-last-seen-at-single-toggle';
await app.createFeature(featureName);
await setupLastSeenAtTest(`${featureName}1`);
await setupLastSeenAtTest(`${featureName}2`);
await setupLastSeenAtTest(`${featureName}3`);
await setupLastSeenAtTest(`${featureName}4`);
await setupLastSeenAtTest(`${featureName}5`);

await insertLastSeenAt(
featureName,
db.rawDatabase,
'default',
'2023-08-01 12:30:56',
);

await insertLastSeenAt(
featureName,
db.rawDatabase,
'development',
'2023-08-01 12:30:56',
);

await insertLastSeenAt(
featureName,
db.rawDatabase,
'production',
'2023-08-01 12:30:56',
);

const { body } = await app.request
.get(`/api/admin/projects/default/features/${featureName}`)
.expect(200);

expect(body.environments).toMatchObject([
{
name: 'default',
lastSeenAt: '2023-08-01T12:30:56.000Z',
},
{
name: 'development',
lastSeenAt: '2023-08-01T12:30:56.000Z',
},
{
name: 'production',
lastSeenAt: '2023-08-01T12:30:56.000Z',
},
]);
});
9 changes: 7 additions & 2 deletions src/test/e2e/helpers/test-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,15 @@ export const insertLastSeenAt = async (
environment: string = 'default',
date: string = '2023-10-01 12:34:56',
): Promise<string> => {
await db.raw(`INSERT INTO last_seen_at_metrics (feature_name, environment, last_seen_at)
try {
await db.raw(`INSERT INTO last_seen_at_metrics (feature_name, environment, last_seen_at)
VALUES ('${featureName}', '${environment}', '${date}');`);

return date;
return date;
} catch (err) {
console.log(err);
return Promise.resolve('');
}
};

export const insertFeatureEnvironmentsLastSeen = async (
Expand Down

0 comments on commit 28c72ec

Please sign in to comment.