test: dedupe channel/web cases and tighten gateway e2e waits

This commit is contained in:
Peter Steinberger
2026-02-21 22:56:09 +00:00
parent c708a18b0f
commit 4a2ff03f49
4 changed files with 132 additions and 99 deletions

View File

@@ -88,62 +88,71 @@ describe("channel targets", () => {
});
describe("resolveConversationLabel", () => {
it("prefers ConversationLabel when present", () => {
const ctx: MsgContext = { ConversationLabel: "Pinned Label", ChatType: "group" };
expect(resolveConversationLabel(ctx)).toBe("Pinned Label");
});
const cases: Array<{ name: string; ctx: MsgContext; expected: string }> = [
{
name: "prefers ConversationLabel when present",
ctx: { ConversationLabel: "Pinned Label", ChatType: "group" },
expected: "Pinned Label",
},
{
name: "prefers ThreadLabel over derived chat labels",
ctx: {
ThreadLabel: "Thread Alpha",
ChatType: "group",
GroupSubject: "Ops",
From: "telegram:group:42",
},
expected: "Thread Alpha",
},
{
name: "uses SenderName for direct chats when available",
ctx: { ChatType: "direct", SenderName: "Ada", From: "telegram:99" },
expected: "Ada",
},
{
name: "falls back to From for direct chats when SenderName is missing",
ctx: { ChatType: "direct", From: "telegram:99" },
expected: "telegram:99",
},
{
name: "derives Telegram-like group labels with numeric id suffix",
ctx: { ChatType: "group", GroupSubject: "Ops", From: "telegram:group:42" },
expected: "Ops id:42",
},
{
name: "does not append ids for #rooms/channels",
ctx: {
ChatType: "channel",
GroupSubject: "#general",
From: "slack:channel:C123",
},
expected: "#general",
},
{
name: "does not append ids when the base already contains the id",
ctx: {
ChatType: "group",
GroupSubject: "Family id:123@g.us",
From: "whatsapp:group:123@g.us",
},
expected: "Family id:123@g.us",
},
{
name: "appends ids for WhatsApp-like group ids when a subject exists",
ctx: {
ChatType: "group",
GroupSubject: "Family",
From: "whatsapp:group:123@g.us",
},
expected: "Family id:123@g.us",
},
];
it("prefers ThreadLabel over derived chat labels", () => {
const ctx: MsgContext = {
ThreadLabel: "Thread Alpha",
ChatType: "group",
GroupSubject: "Ops",
From: "telegram:group:42",
};
expect(resolveConversationLabel(ctx)).toBe("Thread Alpha");
});
it("uses SenderName for direct chats when available", () => {
const ctx: MsgContext = { ChatType: "direct", SenderName: "Ada", From: "telegram:99" };
expect(resolveConversationLabel(ctx)).toBe("Ada");
});
it("falls back to From for direct chats when SenderName is missing", () => {
const ctx: MsgContext = { ChatType: "direct", From: "telegram:99" };
expect(resolveConversationLabel(ctx)).toBe("telegram:99");
});
it("derives Telegram-like group labels with numeric id suffix", () => {
const ctx: MsgContext = { ChatType: "group", GroupSubject: "Ops", From: "telegram:group:42" };
expect(resolveConversationLabel(ctx)).toBe("Ops id:42");
});
it("does not append ids for #rooms/channels", () => {
const ctx: MsgContext = {
ChatType: "channel",
GroupSubject: "#general",
From: "slack:channel:C123",
};
expect(resolveConversationLabel(ctx)).toBe("#general");
});
it("does not append ids when the base already contains the id", () => {
const ctx: MsgContext = {
ChatType: "group",
GroupSubject: "Family id:123@g.us",
From: "whatsapp:group:123@g.us",
};
expect(resolveConversationLabel(ctx)).toBe("Family id:123@g.us");
});
it("appends ids for WhatsApp-like group ids when a subject exists", () => {
const ctx: MsgContext = {
ChatType: "group",
GroupSubject: "Family",
From: "whatsapp:group:123@g.us",
};
expect(resolveConversationLabel(ctx)).toBe("Family id:123@g.us");
});
for (const testCase of cases) {
it(testCase.name, () => {
expect(resolveConversationLabel(testCase.ctx)).toBe(testCase.expected);
});
}
});
describe("createTypingCallbacks", () => {

View File

@@ -16,24 +16,26 @@ describe("channel-web barrel", () => {
});
describe("normalizeChatType", () => {
it("normalizes common inputs", () => {
expect(normalizeChatType("direct")).toBe("direct");
expect(normalizeChatType("dm")).toBe("direct");
expect(normalizeChatType("group")).toBe("group");
expect(normalizeChatType("channel")).toBe("channel");
});
const cases: Array<{ name: string; value: string | undefined; expected: string | undefined }> = [
{ name: "normalizes direct", value: "direct", expected: "direct" },
{ name: "normalizes dm alias", value: "dm", expected: "direct" },
{ name: "normalizes group", value: "group", expected: "group" },
{ name: "normalizes channel", value: "channel", expected: "channel" },
{ name: "returns undefined for undefined", value: undefined, expected: undefined },
{ name: "returns undefined for empty", value: "", expected: undefined },
{ name: "returns undefined for unknown value", value: "nope", expected: undefined },
{ name: "returns undefined for unsupported room", value: "room", expected: undefined },
];
it("returns undefined for empty/unknown values", () => {
expect(normalizeChatType(undefined)).toBeUndefined();
expect(normalizeChatType("")).toBeUndefined();
expect(normalizeChatType("nope")).toBeUndefined();
expect(normalizeChatType("room")).toBeUndefined();
});
for (const testCase of cases) {
it(testCase.name, () => {
expect(normalizeChatType(testCase.value)).toBe(testCase.expected);
});
}
describe("backward compatibility", () => {
it("accepts legacy 'dm' value and normalizes to 'direct'", () => {
// Legacy config/input may use "dm" - ensure smooth upgrade path
expect(normalizeChatType("dm")).toBe("direct");
it("accepts legacy 'dm' value shape variants and normalizes to 'direct'", () => {
// Legacy config/input may use "dm" with non-canonical casing/spacing.
expect(normalizeChatType("DM")).toBe("direct");
expect(normalizeChatType(" dm ")).toBe("direct");
});