test: table-drive telegram thread param cases

This commit is contained in:
Peter Steinberger
2026-02-18 23:22:26 +00:00
parent c25a18493e
commit 03241498f9

View File

@@ -17,62 +17,38 @@ describe("resolveTelegramForumThreadId", () => {
expect(resolveTelegramForumThreadId(params)).toBeUndefined(); expect(resolveTelegramForumThreadId(params)).toBeUndefined();
}); });
it("returns General topic (1) for forum groups without messageThreadId", () => { it.each([
expect(resolveTelegramForumThreadId({ isForum: true, messageThreadId: undefined })).toBe(1); { isForum: true, messageThreadId: undefined, expected: 1 },
expect(resolveTelegramForumThreadId({ isForum: true, messageThreadId: null })).toBe(1); { isForum: true, messageThreadId: null, expected: 1 },
}); { isForum: true, messageThreadId: 99, expected: 99 },
])("resolves forum topic ids", ({ expected, ...params }) => {
it("returns the topic id for forum groups with messageThreadId", () => { expect(resolveTelegramForumThreadId(params)).toBe(expected);
expect(resolveTelegramForumThreadId({ isForum: true, messageThreadId: 99 })).toBe(99);
}); });
}); });
describe("buildTelegramThreadParams", () => { describe("buildTelegramThreadParams", () => {
it("omits General topic thread id for message sends", () => { it.each([
expect(buildTelegramThreadParams({ id: 1, scope: "forum" })).toBeUndefined(); { input: { id: 1, scope: "forum" as const }, expected: undefined },
}); { input: { id: 99, scope: "forum" as const }, expected: { message_thread_id: 99 } },
{ input: { id: 1, scope: "dm" as const }, expected: { message_thread_id: 1 } },
it("includes non-General topic thread ids", () => { { input: { id: 2, scope: "dm" as const }, expected: { message_thread_id: 2 } },
expect(buildTelegramThreadParams({ id: 99, scope: "forum" })).toEqual({ { input: { id: 0, scope: "dm" as const }, expected: undefined },
message_thread_id: 99, { input: { id: -1, scope: "dm" as const }, expected: undefined },
}); { input: { id: 1.9, scope: "dm" as const }, expected: { message_thread_id: 1 } },
});
it("includes thread id for dm topics", () => {
expect(buildTelegramThreadParams({ id: 1, scope: "dm" })).toEqual({
message_thread_id: 1,
});
expect(buildTelegramThreadParams({ id: 2, scope: "dm" })).toEqual({
message_thread_id: 2,
});
});
it("normalizes dm thread ids and skips non-positive values", () => {
expect(buildTelegramThreadParams({ id: 0, scope: "dm" })).toBeUndefined();
expect(buildTelegramThreadParams({ id: -1, scope: "dm" })).toBeUndefined();
expect(buildTelegramThreadParams({ id: 1.9, scope: "dm" })).toEqual({
message_thread_id: 1,
});
});
it("handles thread id 0 for non-dm scopes", () => {
// id=0 should be included for forum and none scopes (not falsy) // id=0 should be included for forum and none scopes (not falsy)
expect(buildTelegramThreadParams({ id: 0, scope: "forum" })).toEqual({ { input: { id: 0, scope: "forum" as const }, expected: { message_thread_id: 0 } },
message_thread_id: 0, { input: { id: 0, scope: "none" as const }, expected: { message_thread_id: 0 } },
}); ])("builds thread params", ({ input, expected }) => {
expect(buildTelegramThreadParams({ id: 0, scope: "none" })).toEqual({ expect(buildTelegramThreadParams(input)).toEqual(expected);
message_thread_id: 0,
});
}); });
}); });
describe("buildTypingThreadParams", () => { describe("buildTypingThreadParams", () => {
it("returns undefined when no thread id is provided", () => { it.each([
expect(buildTypingThreadParams(undefined)).toBeUndefined(); { input: undefined, expected: undefined },
}); { input: 1, expected: { message_thread_id: 1 } },
])("builds typing params", ({ input, expected }) => {
it("includes General topic thread id for typing indicators", () => { expect(buildTypingThreadParams(input)).toEqual(expected);
expect(buildTypingThreadParams(1)).toEqual({ message_thread_id: 1 });
}); });
}); });