mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-26 23:01:05 +03:00
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { deriveSessionKey, resolveSessionKey } from "./sessions.js";
|
|
|
|
describe("sessions", () => {
|
|
it("returns normalized per-sender key", () => {
|
|
expect(deriveSessionKey("per-sender", { From: "whatsapp:+1555" })).toBe(
|
|
"+1555",
|
|
);
|
|
});
|
|
|
|
it("falls back to unknown when sender missing", () => {
|
|
expect(deriveSessionKey("per-sender", {})).toBe("unknown");
|
|
});
|
|
|
|
it("global scope returns global", () => {
|
|
expect(deriveSessionKey("global", { From: "+1" })).toBe("global");
|
|
});
|
|
|
|
it("keeps group chats distinct", () => {
|
|
expect(deriveSessionKey("per-sender", { From: "12345-678@g.us" })).toBe(
|
|
"group:12345-678@g.us",
|
|
);
|
|
});
|
|
|
|
it("maps direct chats to main key when provided", () => {
|
|
expect(
|
|
resolveSessionKey("per-sender", { From: "whatsapp:+1555" }, "main"),
|
|
).toBe("main");
|
|
});
|
|
|
|
it("leaves groups untouched even with main key", () => {
|
|
expect(
|
|
resolveSessionKey("per-sender", { From: "12345-678@g.us" }, "main"),
|
|
).toBe("group:12345-678@g.us");
|
|
});
|
|
});
|