import { describe, it, expect } from "vitest"; import { createVPSListPages, DISCORD_EMBED_LIMITS } from "../src/utils/embeds.js"; import { VPS } from "../src/types/vps.js"; function generateMockVPSList(count: number): VPS[] { return Array.from({ length: count }, (_, i) => ({ id: `vps-${String(i + 1).padStart(3, "0")}`, name: `node-prod-${String(i + 1).padStart(3, "0")}`, provider: i % 2 === 0 ? "Vultr" : "DigitalOcean", region: "Singapore", environment: i % 3 === 0 ? "Production" : i % 3 === 1 ? "Staging" : "Development", cpu: 4, ramGB: 8, diskGB: 160, })); } describe("Embed Pagination for Large VPS Lists", () => { it("should return a single empty-state embed when inventory is empty", () => { const pages = createVPSListPages([]); expect(pages).toHaveLength(1); expect(pages[0].data.description).toContain("No VPS records found"); }); it("should split 100 VPS records into multiple pages respecting Discord Embed limits", () => { const servers = generateMockVPSList(100); const pages = createVPSListPages(servers); expect(pages.length).toBeGreaterThan(1); expect(pages).toHaveLength(10); // 100 items / 10 per page = 10 pages let totalFieldsAcrossPages = 0; for (const page of pages) { const json = page.toJSON(); const fieldCount = json.fields?.length ?? 0; totalFieldsAcrossPages += fieldCount; expect(fieldCount).toBeLessThanOrEqual(DISCORD_EMBED_LIMITS.MAX_FIELDS); expect(page.length).toBeLessThanOrEqual(DISCORD_EMBED_LIMITS.MAX_TOTAL_CHARS); } expect(totalFieldsAcrossPages).toBe(100); expect(pages[0].data.footer?.text).toBe("Page 1/10 • Total Servers: 100"); expect(pages[9].data.footer?.text).toBe("Page 10/10 • Total Servers: 100"); }); });