From 8ff277d2a2b5e0240976a96646526e09c809392f Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 22 Mar 2026 19:09:57 -0700 Subject: [PATCH] test(msteams): cover poll and file-card helpers --- extensions/msteams/src/graph-chat.test.ts | 40 ++++++++++++ .../msteams/src/polls-store-memory.test.ts | 63 +++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 extensions/msteams/src/graph-chat.test.ts create mode 100644 extensions/msteams/src/polls-store-memory.test.ts diff --git a/extensions/msteams/src/graph-chat.test.ts b/extensions/msteams/src/graph-chat.test.ts new file mode 100644 index 00000000000..ba4c12ddd45 --- /dev/null +++ b/extensions/msteams/src/graph-chat.test.ts @@ -0,0 +1,40 @@ +import { describe, expect, it } from "vitest"; +import { buildTeamsFileInfoCard } from "./graph-chat.js"; + +describe("buildTeamsFileInfoCard", () => { + it("extracts a unique id from quoted etags and lowercases file extensions", () => { + expect( + buildTeamsFileInfoCard({ + eTag: '"{ABC-123},42"', + name: "Quarterly.Report.PDF", + webDavUrl: "https://sharepoint.example.com/file.pdf", + }), + ).toEqual({ + contentType: "application/vnd.microsoft.teams.card.file.info", + contentUrl: "https://sharepoint.example.com/file.pdf", + name: "Quarterly.Report.PDF", + content: { + uniqueId: "ABC-123", + fileType: "pdf", + }, + }); + }); + + it("keeps the raw etag when no version suffix exists and handles extensionless files", () => { + expect( + buildTeamsFileInfoCard({ + eTag: "plain-etag", + name: "README", + webDavUrl: "https://sharepoint.example.com/readme", + }), + ).toEqual({ + contentType: "application/vnd.microsoft.teams.card.file.info", + contentUrl: "https://sharepoint.example.com/readme", + name: "README", + content: { + uniqueId: "plain-etag", + fileType: "", + }, + }); + }); +}); diff --git a/extensions/msteams/src/polls-store-memory.test.ts b/extensions/msteams/src/polls-store-memory.test.ts new file mode 100644 index 00000000000..147956fd51f --- /dev/null +++ b/extensions/msteams/src/polls-store-memory.test.ts @@ -0,0 +1,63 @@ +import { describe, expect, it } from "vitest"; +import { createMSTeamsPollStoreMemory } from "./polls-store-memory.js"; + +describe("createMSTeamsPollStoreMemory", () => { + it("creates polls, reads them back, and records normalized votes", async () => { + const store = createMSTeamsPollStoreMemory([ + { + id: "poll-1", + question: "Pick one", + options: ["A", "B"], + maxSelections: 1, + votes: {}, + createdAt: "2026-03-22T00:00:00.000Z", + updatedAt: "2026-03-22T00:00:00.000Z", + }, + ]); + + await expect(store.getPoll("poll-1")).resolves.toEqual( + expect.objectContaining({ + id: "poll-1", + question: "Pick one", + }), + ); + + const originalUpdatedAt = "2026-03-22T00:00:00.000Z"; + await store.getPoll("poll-1"); + const result = await store.recordVote({ + pollId: "poll-1", + voterId: "user-1", + selections: ["1", "0", "missing"], + }); + + expect(result?.votes["user-1"]).toEqual(["1"]); + expect(result?.updatedAt).not.toBe(originalUpdatedAt); + + await store.createPoll({ + id: "poll-2", + question: "Pick many", + options: ["X", "Y"], + maxSelections: 2, + votes: {}, + createdAt: "2026-03-22T00:00:00.000Z", + updatedAt: "2026-03-22T00:00:00.000Z", + }); + + await expect( + store.recordVote({ + pollId: "poll-2", + voterId: "user-2", + selections: ["1", "0", "1"], + }), + ).resolves.toEqual( + expect.objectContaining({ + id: "poll-2", + votes: { + "user-2": ["1", "0"], + }, + }), + ); + + await expect(store.recordVote({ pollId: "missing", voterId: "nobody", selections: ["x"] })).resolves.toBeNull(); + }); +});