Skip to content

Commit

Permalink
fix: should not import archived child and parent (#5912)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew committed Jan 16, 2024
1 parent 9989688 commit af4c3a8
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
Expand Up @@ -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(
{
Expand Down
62 changes: 62 additions & 0 deletions src/lib/features/export-import-toggles/export-import.e2e.test.ts
Expand Up @@ -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,
Expand Down

0 comments on commit af4c3a8

Please sign in to comment.