mirror of
https://github.com/Unleash/unleash.git
synced 2025-04-01 01:18:10 +02:00
feat: detect grandchild dependency (#5094)
This commit is contained in:
parent
f22c15e5a1
commit
de237d844d
@ -96,18 +96,26 @@ export class DependentFeaturesService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const [children, parentExists, sameProject] = await Promise.all([
|
const [grandchildren, grandparents, parentExists, sameProject] =
|
||||||
this.dependentFeaturesReadModel.getChildren([child]),
|
await Promise.all([
|
||||||
this.featuresReadModel.featureExists(parent),
|
this.dependentFeaturesReadModel.getChildren([child]),
|
||||||
this.featuresReadModel.featuresInTheSameProject(child, parent),
|
this.dependentFeaturesReadModel.getParents(parent),
|
||||||
]);
|
this.featuresReadModel.featureExists(parent),
|
||||||
|
this.featuresReadModel.featuresInTheSameProject(child, parent),
|
||||||
|
]);
|
||||||
|
|
||||||
if (children.length > 0) {
|
if (grandchildren.length > 0) {
|
||||||
throw new InvalidOperationError(
|
throw new InvalidOperationError(
|
||||||
'Transitive dependency detected. Cannot add a dependency to the feature that other features depend on.',
|
'Transitive dependency detected. Cannot add a dependency to the feature that other features depend on.',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (grandparents.length > 0) {
|
||||||
|
throw new InvalidOperationError(
|
||||||
|
'Transitive dependency detected. Cannot add a dependency to the feature that has parent dependency.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (!parentExists) {
|
if (!parentExists) {
|
||||||
throw new InvalidOperationError(
|
throw new InvalidOperationError(
|
||||||
`No active feature ${parent} exists`,
|
`No active feature ${parent} exists`,
|
||||||
|
@ -138,7 +138,7 @@ test('should add and delete feature dependencies', async () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should not allow to add a parent dependency to a feature that already has children', async () => {
|
test('should not allow to add grandparent', async () => {
|
||||||
const grandparent = uuidv4();
|
const grandparent = uuidv4();
|
||||||
const parent = uuidv4();
|
const parent = uuidv4();
|
||||||
const child = uuidv4();
|
const child = uuidv4();
|
||||||
@ -158,8 +158,28 @@ test('should not allow to add a parent dependency to a feature that already has
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should not allow to add non-existent parent dependency', async () => {
|
test('should not allow to add grandchild', async () => {
|
||||||
const grandparent = uuidv4();
|
const grandparent = uuidv4();
|
||||||
|
const parent = uuidv4();
|
||||||
|
const child = uuidv4();
|
||||||
|
await app.createFeature(grandparent);
|
||||||
|
await app.createFeature(parent);
|
||||||
|
await app.createFeature(child);
|
||||||
|
|
||||||
|
await addFeatureDependency(parent, {
|
||||||
|
feature: grandparent,
|
||||||
|
});
|
||||||
|
|
||||||
|
await addFeatureDependency(
|
||||||
|
child,
|
||||||
|
{
|
||||||
|
feature: parent,
|
||||||
|
},
|
||||||
|
403,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should not allow to add non-existent parent dependency', async () => {
|
||||||
const parent = uuidv4();
|
const parent = uuidv4();
|
||||||
const child = uuidv4();
|
const child = uuidv4();
|
||||||
await app.createFeature(child);
|
await app.createFeature(child);
|
||||||
|
Loading…
Reference in New Issue
Block a user