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