66 lines
1.9 KiB
JavaScript
66 lines
1.9 KiB
JavaScript
"use strict";
|
|
|
|
const test = require("node:test");
|
|
const assert = require("node:assert/strict");
|
|
const { InMemoryDashboardStore } = require("../src/dashboardStore");
|
|
|
|
test("in-memory store persists watch, poll result, events and controls", async () => {
|
|
const store = new InMemoryDashboardStore();
|
|
await store.init();
|
|
|
|
await store.saveWatch({
|
|
id: "watch-1",
|
|
rawInput: "인천->마드리드",
|
|
searchParams: { segments: [{ from: "ICN", to: "MAD" }] },
|
|
alertRules: { targetPrice: 1300000, notifyOnPriceChange: true },
|
|
pollingEnabled: true,
|
|
alertsEnabled: true,
|
|
createdAt: "2026-02-19T00:00:00.000Z",
|
|
updatedAt: "2026-02-19T00:00:00.000Z",
|
|
lastSnapshot: null,
|
|
lastError: null,
|
|
});
|
|
|
|
await store.savePollResult("watch-1", {
|
|
snapshot: {
|
|
polledAt: "2026-02-19T00:01:00.000Z",
|
|
bestPrice: 1295000,
|
|
currency: "KRW",
|
|
bestOffer: { provider: "mock" },
|
|
offers: [{ provider: "mock", price: 1295000, currency: "KRW" }],
|
|
},
|
|
});
|
|
|
|
await store.saveEvent({
|
|
watchId: "watch-1",
|
|
eventType: "target_price",
|
|
observedAt: "2026-02-19T00:01:00.000Z",
|
|
payload: {
|
|
currentBestPrice: 1295000,
|
|
previousBestPrice: 1310000,
|
|
currency: "KRW",
|
|
},
|
|
});
|
|
|
|
const watches = await store.listWatches();
|
|
const events = await store.listEvents(5);
|
|
|
|
assert.equal(watches.length, 1);
|
|
assert.equal(watches[0].lastSnapshot.bestPrice, 1295000);
|
|
assert.equal(events.length, 1);
|
|
assert.equal(events[0].eventType, "target_price");
|
|
|
|
const controlsBefore = await store.getGlobalControls();
|
|
assert.equal(controlsBefore.crawlingEnabled, true);
|
|
assert.equal(controlsBefore.alertsEnabled, true);
|
|
|
|
await store.setGlobalControls({
|
|
crawlingEnabled: false,
|
|
alertsEnabled: false,
|
|
});
|
|
|
|
const controlsAfter = await store.getGlobalControls();
|
|
assert.equal(controlsAfter.crawlingEnabled, false);
|
|
assert.equal(controlsAfter.alertsEnabled, false);
|
|
});
|