mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01: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([
|
||||
this.dependentFeaturesReadModel.getChildren([child]),
|
||||
this.featuresReadModel.featureExists(parent),
|
||||
this.featuresReadModel.featuresInTheSameProject(child, parent),
|
||||
]);
|
||||
const [grandchildren, grandparents, parentExists, sameProject] =
|
||||
await Promise.all([
|
||||
this.dependentFeaturesReadModel.getChildren([child]),
|
||||
this.dependentFeaturesReadModel.getParents(parent),
|
||||
this.featuresReadModel.featureExists(parent),
|
||||
this.featuresReadModel.featuresInTheSameProject(child, parent),
|
||||
]);
|
||||
|
||||
if (children.length > 0) {
|
||||
if (grandchildren.length > 0) {
|
||||
throw new InvalidOperationError(
|
||||
'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) {
|
||||
throw new InvalidOperationError(
|
||||
`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 parent = 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 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 child = uuidv4();
|
||||
await app.createFeature(child);
|
||||
|
Loading…
Reference in New Issue
Block a user