test(msteams): cover poll and file-card helpers

This commit is contained in:
Vincent Koc 2026-03-22 19:09:57 -07:00
parent 3ccf1bee2c
commit 8ff277d2a2
2 changed files with 103 additions and 0 deletions

View File

@ -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: "",
},
});
});
});

View File

@ -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();
});
});