fix: use defaults for blank number ingredients
This commit is contained in:
parent
c56dd23358
commit
e73a83ac51
@ -244,7 +244,12 @@ class Operation {
|
|||||||
set ingValues(ingValues) {
|
set ingValues(ingValues) {
|
||||||
ingValues.forEach((val, i) => {
|
ingValues.forEach((val, i) => {
|
||||||
try {
|
try {
|
||||||
this._ingList[i].value = val;
|
const ingredient = this._ingList[i],
|
||||||
|
value = ingredient.type === "number" && Number.isNaN(val) ?
|
||||||
|
ingredient.defaultValue :
|
||||||
|
val;
|
||||||
|
|
||||||
|
ingredient.value = value;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new OperationError(`Failed to set value of ingredient '${this._ingList[i].name}': ${err}`);
|
throw new OperationError(`Failed to set value of ingredient '${this._ingList[i].name}': ${err}`);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,6 +21,7 @@ import "./tests/operations.mjs";
|
|||||||
import "./tests/PGP.mjs";
|
import "./tests/PGP.mjs";
|
||||||
import "./tests/File.mjs";
|
import "./tests/File.mjs";
|
||||||
import "./tests/Dish.mjs";
|
import "./tests/Dish.mjs";
|
||||||
|
import "./tests/Operation.mjs";
|
||||||
import "./tests/NodeDish.mjs";
|
import "./tests/NodeDish.mjs";
|
||||||
import "./tests/Utils.mjs";
|
import "./tests/Utils.mjs";
|
||||||
import "./tests/Categories.mjs";
|
import "./tests/Categories.mjs";
|
||||||
|
|||||||
32
tests/node/tests/Operation.mjs
Normal file
32
tests/node/tests/Operation.mjs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import TestRegister from "../../lib/TestRegister.mjs";
|
||||||
|
import Operation from "../../../src/core/Operation.mjs";
|
||||||
|
import it from "../../node/assertionHandler.mjs";
|
||||||
|
import assert from "assert";
|
||||||
|
|
||||||
|
TestRegister.addApiTests([
|
||||||
|
it("Operation - NaN number ingredients should use their default value", () => {
|
||||||
|
const operation = new Operation();
|
||||||
|
operation.args = [{
|
||||||
|
name: "Offset",
|
||||||
|
type: "number",
|
||||||
|
value: 0
|
||||||
|
}];
|
||||||
|
|
||||||
|
operation.ingValues = [NaN];
|
||||||
|
|
||||||
|
assert.deepStrictEqual(operation.ingValues, [0]);
|
||||||
|
}),
|
||||||
|
|
||||||
|
it("Operation - invalid number strings should still throw", () => {
|
||||||
|
const operation = new Operation();
|
||||||
|
operation.args = [{
|
||||||
|
name: "Offset",
|
||||||
|
type: "number",
|
||||||
|
value: 0
|
||||||
|
}];
|
||||||
|
|
||||||
|
assert.throws(() => {
|
||||||
|
operation.ingValues = ["NaN"];
|
||||||
|
}, /Invalid ingredient value\. Not a number: NaN/);
|
||||||
|
}),
|
||||||
|
]);
|
||||||
Loading…
x
Reference in New Issue
Block a user