51 lines
1.5 KiB
JavaScript
51 lines
1.5 KiB
JavaScript
"use strict";
|
|
|
|
const test = require("node:test");
|
|
const assert = require("node:assert/strict");
|
|
const {
|
|
buildAlertRules,
|
|
inferAlertOn,
|
|
normalizeAlertOn,
|
|
parseTargetPrice,
|
|
} = require("../src/alertRules");
|
|
|
|
test("buildAlertRules builds both mode with integer target", () => {
|
|
const result = buildAlertRules({
|
|
targetPrice: "1200000",
|
|
alertOn: "both",
|
|
});
|
|
|
|
assert.deepEqual(result, {
|
|
targetPrice: 1200000,
|
|
notifyOnPriceChange: true,
|
|
notifyOnFirstResult: false,
|
|
});
|
|
});
|
|
|
|
test("buildAlertRules validates threshold mode target", () => {
|
|
assert.throws(
|
|
() =>
|
|
buildAlertRules({
|
|
targetPrice: null,
|
|
alertOn: "threshold",
|
|
}),
|
|
(error) => error.message.includes("targetPrice가 필요합니다.")
|
|
);
|
|
});
|
|
|
|
test("normalizeAlertOn validates allowed modes", () => {
|
|
assert.equal(normalizeAlertOn(" change "), "change");
|
|
assert.throws(() => normalizeAlertOn("invalid"), (error) => error.statusCode === 400);
|
|
});
|
|
|
|
test("parseTargetPrice handles undefined and allowUndefined option", () => {
|
|
assert.equal(parseTargetPrice(undefined), null);
|
|
assert.equal(parseTargetPrice(undefined, { allowUndefined: true }), undefined);
|
|
});
|
|
|
|
test("inferAlertOn reflects rule combinations", () => {
|
|
assert.equal(inferAlertOn({ targetPrice: 1000, notifyOnPriceChange: true }), "both");
|
|
assert.equal(inferAlertOn({ targetPrice: 1000, notifyOnPriceChange: false }), "threshold");
|
|
assert.equal(inferAlertOn({ targetPrice: null, notifyOnPriceChange: true }), "change");
|
|
});
|