fix: validate saved plan confidence

This commit is contained in:
ik
2026-09-21 18:23:19 +07:00
parent b0421c11f5
commit f3eb54083f
3 changed files with 10 additions and 2 deletions
+3 -1
View File
@@ -19,7 +19,9 @@ import Layout from "../layouts/Layout.astro";
const seen = new Set<string>();
return value.filter(item => item && typeof item === "object" && typeof item.key === "string" && item.key.startsWith("/spots/")).map(item => {
const source = item as Record<string, unknown>;
return Object.fromEntries(["key", "waterbody", "coordinates", "baits", "method", "retrieve", "risk", "freshness", "confidence"].map(key => [key, planText(key, source[key])]));
const entry = Object.fromEntries(["key", "waterbody", "coordinates", "baits", "method", "retrieve", "risk", "freshness", "confidence"].map(key => [key, planText(key, source[key])]));
if (!/^\d{1,3}$/.test(entry.confidence) || Number(entry.confidence) > 100) entry.confidence = "";
return entry;
}).filter(item => {
if (seen.has(item.key)) return false;
seen.add(item.key);
+6
View File
@@ -67,6 +67,11 @@ test("plan preserves a real zero confidence and bounds imported text", async ({
method: "Спиннинг",
retrieve: "равномерная",
oversized: "x".repeat(5000),
}, {
key: "/spots/vyunok-7450x7451",
waterbody: "Вьюнок",
coordinates: "7450:7451",
confidence: "999",
}])));
await page.reload();
@@ -74,6 +79,7 @@ test("plan preserves a real zero confidence and bounds imported text", async ({
const stored = await page.evaluate(() => JSON.parse(localStorage.getItem("rf4spotter:fishing-plan") || "[]"));
expect(stored[0].key.length).toBeLessThanOrEqual(512);
expect(stored[0].confidence).toBe("0");
expect(stored[1].confidence).toBe("");
expect(stored[0].oversized).toBeUndefined();
});