Files
cobble/src/utils/parse-last-visited-bot.test.ts
T
tben 63a93a4262
CI / check (push) Canceled after 0s
Keep only the bot cookie for the last visited bot
A workspace conversation is never remembered, so /admin/bots always
reopens the bot's own chat.
2026-10-22 13:39:36 +01:00

26 lines
1.2 KiB
TypeScript

import { describe, expect, test } from "bun:test";
import parseLastVisitedBot from "./parse-last-visited-bot";
describe("parseLastVisitedBot", () => {
test("a bot id becomes the bot", () => {
expect(parseLastVisitedBot({ bot_id: "3" })).toEqual({ bot_id: 3 });
expect(parseLastVisitedBot({ bot_id: 3 })).toEqual({ bot_id: 3 });
});
test("rejects ids that aren't positive whole numbers", () => {
expect(parseLastVisitedBot({})).toBeNull();
expect(parseLastVisitedBot({ bot_id: null })).toBeNull();
expect(parseLastVisitedBot({ bot_id: "" })).toBeNull();
expect(parseLastVisitedBot({ bot_id: "0" })).toBeNull();
expect(parseLastVisitedBot({ bot_id: "-1" })).toBeNull();
expect(parseLastVisitedBot({ bot_id: "1.5" })).toBeNull();
expect(parseLastVisitedBot({ bot_id: "abc" })).toBeNull();
expect(parseLastVisitedBot({ bot_id: "1 OR 1=1" })).toBeNull();
expect(parseLastVisitedBot({ bot_id: "99999999999999999999" })).toBeNull();
});
test("trims what a cookie header may carry", () => {
expect(parseLastVisitedBot({ bot_id: " 3 " })).toEqual({ bot_id: 3 });
});
});