Keep only the bot cookie for the last visited bot
CI / check (push) Canceled after 0s

A workspace conversation is never remembered, so /admin/bots always
reopens the bot's own chat.
This commit is contained in:
2026-10-22 13:39:36 +01:00
parent 133e6b87c9
commit 63a93a4262
13 changed files with 48 additions and 147 deletions
+5 -26
View File
@@ -2,27 +2,14 @@ import { describe, expect, test } from "bun:test";
import parseLastVisitedBot from "./parse-last-visited-bot";
describe("parseLastVisitedBot", () => {
test("a bot's own chat", () => {
expect(parseLastVisitedBot({ bot_id: "3" })).toEqual({ bot_id: 3, workspace_id: null });
expect(parseLastVisitedBot({ bot_id: 3, workspace_id: "" })).toEqual({
bot_id: 3,
workspace_id: null,
});
expect(parseLastVisitedBot({ bot_id: 3, workspace_id: null })).toEqual({
bot_id: 3,
workspace_id: null,
});
});
test("a workspace conversation", () => {
expect(parseLastVisitedBot({ bot_id: "3", workspace_id: "7" })).toEqual({
bot_id: 3,
workspace_id: 7,
});
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();
@@ -32,15 +19,7 @@ describe("parseLastVisitedBot", () => {
expect(parseLastVisitedBot({ bot_id: "99999999999999999999" })).toBeNull();
});
test("a bad workspace falls back to nothing, never to its own chat", () => {
expect(parseLastVisitedBot({ bot_id: "3", workspace_id: "abc" })).toBeNull();
expect(parseLastVisitedBot({ bot_id: "3", workspace_id: "0" })).toBeNull();
});
test("trims what a cookie header may carry", () => {
expect(parseLastVisitedBot({ bot_id: " 3 ", workspace_id: " 7 " })).toEqual({
bot_id: 3,
workspace_id: 7,
});
expect(parseLastVisitedBot({ bot_id: " 3 " })).toEqual({ bot_id: 3 });
});
});