A workspace conversation is never remembered, so /admin/bots always reopens the bot's own chat.
This commit is contained in:
@@ -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 });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user