mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-24 08:21:39 +00:00
test(msteams): cover poll and file-card helpers
This commit is contained in:
40
extensions/msteams/src/graph-chat.test.ts
Normal file
40
extensions/msteams/src/graph-chat.test.ts
Normal 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: "",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
63
extensions/msteams/src/polls-store-memory.test.ts
Normal file
63
extensions/msteams/src/polls-store-memory.test.ts
Normal 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();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user