initial commit

This commit is contained in:
chungyeong
2026-02-19 17:28:58 +09:00
commit 02970df6af
34 changed files with 5673 additions and 0 deletions

50
test/alertRules.test.js Normal file
View File

@@ -0,0 +1,50 @@
"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");
});