mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
feat: check toggle limit on import (#4665)
This commit is contained in:
parent
0cd0d2f153
commit
4dcbb4b997
@ -370,29 +370,26 @@ export default class ExportImportService {
|
|||||||
private async createOrUpdateToggles(dto: ImportTogglesSchema, user: User) {
|
private async createOrUpdateToggles(dto: ImportTogglesSchema, user: User) {
|
||||||
const existingFeatures = await this.getExistingProjectFeatures(dto);
|
const existingFeatures = await this.getExistingProjectFeatures(dto);
|
||||||
const username = extractUsernameFromUser(user);
|
const username = extractUsernameFromUser(user);
|
||||||
await Promise.all(
|
|
||||||
dto.data.features.map((feature) => {
|
for (const feature of dto.data.features) {
|
||||||
if (existingFeatures.includes(feature.name)) {
|
if (existingFeatures.includes(feature.name)) {
|
||||||
const { archivedAt, createdAt, ...rest } = feature;
|
const { archivedAt, createdAt, ...rest } = feature;
|
||||||
return this.featureToggleService.updateFeatureToggle(
|
await this.featureToggleService.updateFeatureToggle(
|
||||||
dto.project,
|
dto.project,
|
||||||
rest as FeatureToggleDTO,
|
rest as FeatureToggleDTO,
|
||||||
username,
|
username,
|
||||||
feature.name,
|
feature.name,
|
||||||
);
|
);
|
||||||
}
|
} else {
|
||||||
return this.featureToggleService
|
await this.featureToggleService.validateName(feature.name);
|
||||||
.validateName(feature.name)
|
const { archivedAt, createdAt, ...rest } = feature;
|
||||||
.then(() => {
|
await this.featureToggleService.createFeatureToggle(
|
||||||
const { archivedAt, createdAt, ...rest } = feature;
|
dto.project,
|
||||||
return this.featureToggleService.createFeatureToggle(
|
rest as FeatureToggleDTO,
|
||||||
dto.project,
|
username,
|
||||||
rest as FeatureToggleDTO,
|
);
|
||||||
extractUsernameFromUser(user),
|
}
|
||||||
);
|
}
|
||||||
});
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async verifyContextFields(dto: ImportTogglesSchema) {
|
private async verifyContextFields(dto: ImportTogglesSchema) {
|
||||||
|
@ -104,7 +104,10 @@ const createVariants = async (feature: string, variants: IVariant[]) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const createProjects = async (projects: string[] = [DEFAULT_PROJECT]) => {
|
const createProjects = async (
|
||||||
|
projects: string[] = [DEFAULT_PROJECT],
|
||||||
|
featureLimit = 2,
|
||||||
|
) => {
|
||||||
await db.stores.environmentStore.create({
|
await db.stores.environmentStore.create({
|
||||||
name: DEFAULT_ENV,
|
name: DEFAULT_ENV,
|
||||||
type: 'production',
|
type: 'production',
|
||||||
@ -115,6 +118,7 @@ const createProjects = async (projects: string[] = [DEFAULT_PROJECT]) => {
|
|||||||
description: '',
|
description: '',
|
||||||
id: project,
|
id: project,
|
||||||
mode: 'open' as const,
|
mode: 'open' as const,
|
||||||
|
featureLimit,
|
||||||
});
|
});
|
||||||
await app.linkProjectToEnvironment(project, DEFAULT_ENV);
|
await app.linkProjectToEnvironment(project, DEFAULT_ENV);
|
||||||
}
|
}
|
||||||
@ -725,6 +729,13 @@ test('import multiple features with same tag', async () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('import too many feature exceeding limit', async () => {
|
||||||
|
const featureLimit = 1;
|
||||||
|
await createProjects([DEFAULT_PROJECT], featureLimit);
|
||||||
|
|
||||||
|
await app.importToggles(importWithMultipleFeatures, 403);
|
||||||
|
});
|
||||||
|
|
||||||
test('can update toggles on subsequent import', async () => {
|
test('can update toggles on subsequent import', async () => {
|
||||||
await createProjects();
|
await createProjects();
|
||||||
await app.importToggles(defaultImportPayload);
|
await app.importToggles(defaultImportPayload);
|
||||||
@ -828,7 +839,7 @@ test('reject import with duplicate features', async () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(body.details[0].description).toBe(
|
expect(body.details[0].description).toBe(
|
||||||
'Feature first_feature already exists',
|
'A toggle with that name already exists',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user