test: speed up telegram suites

This commit is contained in:
Peter Steinberger
2026-02-01 22:21:26 +00:00
parent bcde2fca5a
commit 9d2784cdb9
17 changed files with 426 additions and 471 deletions

View File

@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
import {
buildTelegramThreadParams,
buildTypingThreadParams,
expandTextLinks,
normalizeForwardedContext,
resolveTelegramForumThreadId,
} from "./helpers.js";
@@ -120,3 +121,53 @@ describe("normalizeForwardedContext", () => {
expect(ctx?.date).toBe(111);
});
});
describe("expandTextLinks", () => {
it("returns text unchanged when no entities are provided", () => {
expect(expandTextLinks("Hello world")).toBe("Hello world");
expect(expandTextLinks("Hello world", null)).toBe("Hello world");
expect(expandTextLinks("Hello world", [])).toBe("Hello world");
});
it("returns text unchanged when there are no text_link entities", () => {
const entities = [
{ type: "mention", offset: 0, length: 5 },
{ type: "bold", offset: 6, length: 5 },
];
expect(expandTextLinks("@user hello", entities)).toBe("@user hello");
});
it("expands a single text_link entity", () => {
const text = "Check this link for details";
const entities = [{ type: "text_link", offset: 11, length: 4, url: "https://example.com" }];
expect(expandTextLinks(text, entities)).toBe(
"Check this [link](https://example.com) for details",
);
});
it("expands multiple text_link entities", () => {
const text = "Visit Google or GitHub for more";
const entities = [
{ type: "text_link", offset: 6, length: 6, url: "https://google.com" },
{ type: "text_link", offset: 16, length: 6, url: "https://github.com" },
];
expect(expandTextLinks(text, entities)).toBe(
"Visit [Google](https://google.com) or [GitHub](https://github.com) for more",
);
});
it("handles adjacent text_link entities", () => {
const text = "AB";
const entities = [
{ type: "text_link", offset: 0, length: 1, url: "https://a.example" },
{ type: "text_link", offset: 1, length: 1, url: "https://b.example" },
];
expect(expandTextLinks(text, entities)).toBe("[A](https://a.example)[B](https://b.example)");
});
it("preserves offsets from the original string", () => {
const text = " Hello world";
const entities = [{ type: "text_link", offset: 1, length: 5, url: "https://example.com" }];
expect(expandTextLinks(text, entities)).toBe(" [Hello](https://example.com) world");
});
});