mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-03 20:00:25 +00:00
60 lines
1.7 KiB
TypeScript
60 lines
1.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { resolveConversationIdFromTargets } from "./conversation-id.js";
|
|
|
|
describe("resolveConversationIdFromTargets", () => {
|
|
it.each([
|
|
{
|
|
name: "prefers explicit thread id strings",
|
|
params: { threadId: "123456789", targets: ["channel:987654321"] },
|
|
expected: "123456789",
|
|
},
|
|
{
|
|
name: "normalizes numeric thread ids",
|
|
params: { threadId: 123456789, targets: ["channel:987654321"] },
|
|
expected: "123456789",
|
|
},
|
|
{
|
|
name: "falls back when the thread id is blank",
|
|
params: { threadId: " ", targets: ["channel:987654321"] },
|
|
expected: "987654321",
|
|
},
|
|
])("$name", ({ params, expected }) => {
|
|
expect(resolveConversationIdFromTargets(params)).toBe(expected);
|
|
});
|
|
|
|
it.each([
|
|
{
|
|
name: "extracts channel ids from channel targets",
|
|
targets: ["channel:987654321"],
|
|
expected: "987654321",
|
|
},
|
|
{
|
|
name: "trims channel target ids",
|
|
targets: ["channel: 987654321 "],
|
|
expected: "987654321",
|
|
},
|
|
{
|
|
name: "extracts ids from Discord channel mentions",
|
|
targets: ["<#1475250310120214812>"],
|
|
expected: "1475250310120214812",
|
|
},
|
|
{
|
|
name: "accepts raw numeric ids",
|
|
targets: ["1475250310120214812"],
|
|
expected: "1475250310120214812",
|
|
},
|
|
{
|
|
name: "returns undefined for non-channel targets",
|
|
targets: ["user:alice", "general"],
|
|
expected: undefined,
|
|
},
|
|
{
|
|
name: "skips blank and malformed targets",
|
|
targets: [undefined, null, " ", "channel: ", "<#not-a-number>"],
|
|
expected: undefined,
|
|
},
|
|
])("$name", ({ targets, expected }) => {
|
|
expect(resolveConversationIdFromTargets({ targets })).toBe(expected);
|
|
});
|
|
});
|