1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-05-03 01:18:43 +02:00

fix: should not import archived child and parent (#5912)

This commit is contained in:
Mateusz Kwasniewski 2024-01-16 13:42:25 +01:00 committed by GitHub
parent 9989688d36
commit af4c3a86d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 69 additions and 2 deletions

View File

@ -305,9 +305,14 @@ export default class ExportImportService
private async importDependencies(dto: ImportTogglesSchema, user: IUser) {
await Promise.all(
(dto.data.dependencies || []).flatMap((dependency) => {
const projectId = dto.data.features.find(
const feature = dto.data.features.find(
(feature) => feature.name === dependency.feature,
)!.project!;
);
if (!feature || !feature.project) {
return [];
}
const projectId = feature!.project!;
return dependency.dependencies.map((parentDependency) =>
this.dependentFeaturesService.upsertFeatureDependency(
{

View File

@ -1179,6 +1179,68 @@ test('should not import archived features tags', async () => {
});
});
test('should not import archived parent', async () => {
await createProjects();
await app.createFeature('parent');
await app.archiveFeature('parent');
await app.importToggles({
data: {
features: [{ name: 'child' }, { name: 'parent' }],
dependencies: [
{
feature: 'child',
dependencies: [
{
feature: 'parent',
},
],
},
],
featureStrategies: [],
featureEnvironments: [],
featureTags: [],
tagTypes: [],
contextFields: [],
segments: [],
},
project: DEFAULT_PROJECT,
environment: DEFAULT_ENV,
});
const { body } = await app.getProjectFeatures(DEFAULT_PROJECT);
expect(body).toMatchObject({ features: [{ name: 'child' }] });
});
test('should not import archived child', async () => {
await createProjects();
await app.createFeature('child');
await app.archiveFeature('child');
await app.importToggles({
data: {
features: [{ name: 'child' }, { name: 'parent' }],
dependencies: [
{
feature: 'child',
dependencies: [
{
feature: 'parent',
},
],
},
],
featureStrategies: [],
featureEnvironments: [],
featureTags: [],
tagTypes: [],
contextFields: [],
segments: [],
},
project: DEFAULT_PROJECT,
environment: DEFAULT_ENV,
});
const { body } = await app.getProjectFeatures(DEFAULT_PROJECT);
expect(body).toMatchObject({ features: [{ name: 'parent' }] });
});
test(`should give errors with flag names if the flags don't match the project pattern`, async () => {
await db.stores.environmentStore.create({
name: DEFAULT_ENV,