Fix neutral model validation to consider kind
This fixes a bug where the validation of modeled methods would not consider the kind of the modeled method, and would therefore give an error when there was e.g. a neutral sink and a non-neutral summary.
This commit is contained in:
@@ -75,7 +75,7 @@ function canonicalizeModeledMethod(
|
|||||||
type: "neutral",
|
type: "neutral",
|
||||||
input: "",
|
input: "",
|
||||||
output: "",
|
output: "",
|
||||||
kind: "",
|
kind: modeledMethod.kind,
|
||||||
provenance: "manual",
|
provenance: "manual",
|
||||||
};
|
};
|
||||||
default:
|
default:
|
||||||
@@ -117,24 +117,40 @@ export function validateModeledMethods(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const neutralModeledMethod = consideredModeledMethods.find(
|
const neutralModeledMethods = consideredModeledMethods.filter(
|
||||||
(modeledMethod) => modeledMethod.type === "neutral",
|
(modeledMethod) => modeledMethod.type === "neutral",
|
||||||
);
|
);
|
||||||
const hasNonNeutralModeledMethod = consideredModeledMethods.some(
|
|
||||||
(modeledMethod) => modeledMethod.type !== "neutral",
|
|
||||||
);
|
|
||||||
|
|
||||||
// If there is a neutral model and any other model, that is an error
|
const neutralModeledMethodsByKind = new Map<string, ModeledMethod[]>();
|
||||||
if (neutralModeledMethod && hasNonNeutralModeledMethod) {
|
for (const neutralModeledMethod of neutralModeledMethods) {
|
||||||
// Another validation will validate that only one neutral method is present, so we only need
|
if (!neutralModeledMethodsByKind.has(neutralModeledMethod.kind)) {
|
||||||
// to return an error for the first one
|
neutralModeledMethodsByKind.set(neutralModeledMethod.kind, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
neutralModeledMethodsByKind
|
||||||
|
.get(neutralModeledMethod.kind)
|
||||||
|
?.push(neutralModeledMethod);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const [
|
||||||
|
neutralModeledMethodKind,
|
||||||
|
neutralModeledMethods,
|
||||||
|
] of neutralModeledMethodsByKind) {
|
||||||
|
const conflictingMethods = consideredModeledMethods.filter(
|
||||||
|
(method) => neutralModeledMethodKind === method.type,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (conflictingMethods.length < 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
result.push({
|
result.push({
|
||||||
title: "Conflicting classification",
|
title: "Conflicting classification",
|
||||||
message:
|
message: `This method has a neutral ${neutralModeledMethodKind} classification, which conflicts with other ${neutralModeledMethodKind} classifications.`,
|
||||||
"This method has a neutral classification, which conflicts with other classifications.",
|
|
||||||
actionText: "Modify or remove the neutral classification.",
|
actionText: "Modify or remove the neutral classification.",
|
||||||
index: modeledMethods.indexOf(neutralModeledMethod),
|
// Another validation will validate that only one neutral method is present, so we only need
|
||||||
|
// to return an error for the first one
|
||||||
|
index: modeledMethods.indexOf(neutralModeledMethods[0]),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -246,6 +246,7 @@ describe(validateModeledMethods.name, () => {
|
|||||||
}),
|
}),
|
||||||
createModeledMethod({
|
createModeledMethod({
|
||||||
type: "neutral",
|
type: "neutral",
|
||||||
|
kind: "sink",
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -261,16 +262,34 @@ describe(validateModeledMethods.name, () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should give an error with duplicate neutral combined with other models", () => {
|
it("should not give an error with other neutral combined with other models", () => {
|
||||||
const modeledMethods = [
|
const modeledMethods = [
|
||||||
createModeledMethod({
|
|
||||||
type: "neutral",
|
|
||||||
}),
|
|
||||||
createModeledMethod({
|
createModeledMethod({
|
||||||
type: "sink",
|
type: "sink",
|
||||||
}),
|
}),
|
||||||
createModeledMethod({
|
createModeledMethod({
|
||||||
type: "neutral",
|
type: "neutral",
|
||||||
|
kind: "summary",
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
|
||||||
|
const errors = validateModeledMethods(modeledMethods);
|
||||||
|
|
||||||
|
expect(errors).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should give an error with duplicate neutral combined with other models", () => {
|
||||||
|
const modeledMethods = [
|
||||||
|
createModeledMethod({
|
||||||
|
type: "neutral",
|
||||||
|
kind: "summary",
|
||||||
|
}),
|
||||||
|
createModeledMethod({
|
||||||
|
type: "summary",
|
||||||
|
}),
|
||||||
|
createModeledMethod({
|
||||||
|
type: "neutral",
|
||||||
|
kind: "summary",
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -299,12 +318,14 @@ describe(validateModeledMethods.name, () => {
|
|||||||
}),
|
}),
|
||||||
createModeledMethod({
|
createModeledMethod({
|
||||||
type: "neutral",
|
type: "neutral",
|
||||||
|
kind: "sink",
|
||||||
}),
|
}),
|
||||||
createModeledMethod({
|
createModeledMethod({
|
||||||
type: "sink",
|
type: "sink",
|
||||||
}),
|
}),
|
||||||
createModeledMethod({
|
createModeledMethod({
|
||||||
type: "neutral",
|
type: "neutral",
|
||||||
|
kind: "sink",
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user