1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

Fix error and add test (#1825)

Co-authored-by: sjaanus <sellinjaanus@gmail.com>
This commit is contained in:
sellinjaanus 2022-07-18 07:30:04 +00:00 committed by GitHub
parent d89d8c0d0e
commit 9e7f05fb35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 6 deletions

View File

@ -100,7 +100,7 @@ export default class FeatureToggleClientStore
'fe.feature_name',
'features.name',
)
.fullOuterJoin(
.leftJoin(
'feature_strategy_segment as fss',
`fss.feature_strategy_id`,
`fs.id`,

View File

@ -4,10 +4,21 @@ import dbInit from '../helpers/database-init';
import { DEFAULT_ENV } from '../../../lib/util/constants';
import { SegmentService } from '../../../lib/services/segment-service';
import { FeatureStrategySchema } from '../../../lib/openapi/spec/feature-strategy-schema';
import User from '../../../lib/types/user';
import { IConstraint } from '../../../lib/types/model';
let stores;
let db;
let service: FeatureToggleService;
let segmentService: SegmentService;
const mockConstraints = (): IConstraint[] => {
return Array.from({ length: 5 }).map(() => ({
values: ['x', 'y', 'z'],
operator: 'IN',
contextName: 'a',
}));
};
beforeAll(async () => {
const config = createTestConfig();
@ -16,11 +27,8 @@ beforeAll(async () => {
config.getLogger,
);
stores = db.stores;
service = new FeatureToggleService(
stores,
config,
new SegmentService(stores, config),
);
segmentService = new SegmentService(stores, config);
service = new FeatureToggleService(stores, config, segmentService);
});
afterAll(async () => {
@ -152,3 +160,40 @@ test('should ignore name in the body when updating feature toggle', async () =>
expect(featureOne.description).toBe(`I'm changed`);
expect(featureTwo.description).toBe('Second toggle');
});
test('should not get empty rows as features', async () => {
const projectId = 'default';
const userName = 'strategy';
await service.createFeatureToggle(
projectId,
{
name: 'linked-with-segment',
description: 'First toggle',
},
userName,
);
await service.createFeatureToggle(
projectId,
{
name: 'not-linked-with-segment',
description: 'Second toggle',
},
userName,
);
const user = { email: 'test@example.com' } as User;
const postData = {
name: 'Unlinked segment',
constraints: mockConstraints(),
};
await segmentService.create(postData, user);
const features = await service.getClientFeatures();
const namelessFeature = features.find((p) => !p.name);
expect(features.length).toBe(7);
expect(namelessFeature).toBeUndefined();
});