Skip to content

Commit 55e0c63

Browse files
committed
test(msteams): cover store and live directory helpers
1 parent 6e9cf81 commit 55e0c63

File tree

2 files changed

+219
-0
lines changed

2 files changed

+219
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { describe, expect, it } from "vitest";
2+
import { createMSTeamsConversationStoreMemory } from "./conversation-store-memory.js";
3+
4+
describe("createMSTeamsConversationStoreMemory", () => {
5+
it("upserts, lists, removes, and resolves users by both AAD and Bot Framework ids", async () => {
6+
const store = createMSTeamsConversationStoreMemory([
7+
{
8+
conversationId: "conv-a",
9+
reference: {
10+
conversation: { id: "conv-a" },
11+
user: { id: "user-a", aadObjectId: "aad-a", name: "Alice" },
12+
},
13+
},
14+
]);
15+
16+
await store.upsert("conv-b", {
17+
conversation: { id: "conv-b" },
18+
user: { id: "user-b", aadObjectId: "aad-b", name: "Bob" },
19+
});
20+
21+
await expect(store.get("conv-a")).resolves.toEqual({
22+
conversation: { id: "conv-a" },
23+
user: { id: "user-a", aadObjectId: "aad-a", name: "Alice" },
24+
});
25+
26+
await expect(store.list()).resolves.toEqual([
27+
{
28+
conversationId: "conv-a",
29+
reference: {
30+
conversation: { id: "conv-a" },
31+
user: { id: "user-a", aadObjectId: "aad-a", name: "Alice" },
32+
},
33+
},
34+
{
35+
conversationId: "conv-b",
36+
reference: {
37+
conversation: { id: "conv-b" },
38+
user: { id: "user-b", aadObjectId: "aad-b", name: "Bob" },
39+
},
40+
},
41+
]);
42+
43+
await expect(store.findByUserId(" aad-b ")).resolves.toEqual({
44+
conversationId: "conv-b",
45+
reference: {
46+
conversation: { id: "conv-b" },
47+
user: { id: "user-b", aadObjectId: "aad-b", name: "Bob" },
48+
},
49+
});
50+
await expect(store.findByUserId("user-a")).resolves.toEqual({
51+
conversationId: "conv-a",
52+
reference: {
53+
conversation: { id: "conv-a" },
54+
user: { id: "user-a", aadObjectId: "aad-a", name: "Alice" },
55+
},
56+
});
57+
await expect(store.findByUserId(" ")).resolves.toBeNull();
58+
59+
await expect(store.remove("conv-a")).resolves.toBe(true);
60+
await expect(store.get("conv-a")).resolves.toBeNull();
61+
await expect(store.remove("missing")).resolves.toBe(false);
62+
});
63+
});
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
import { beforeEach, describe, expect, it, vi } from "vitest";
2+
3+
const {
4+
searchGraphUsersMock,
5+
listTeamsByNameMock,
6+
listChannelsForTeamMock,
7+
normalizeQueryMock,
8+
resolveGraphTokenMock,
9+
} = vi.hoisted(() => {
10+
return {
11+
searchGraphUsersMock: vi.fn(),
12+
listTeamsByNameMock: vi.fn(),
13+
listChannelsForTeamMock: vi.fn(),
14+
normalizeQueryMock: vi.fn((value?: string | null) => value?.trim() ?? ""),
15+
resolveGraphTokenMock: vi.fn(),
16+
};
17+
});
18+
19+
vi.mock("./graph-users.js", () => {
20+
return { searchGraphUsers: searchGraphUsersMock };
21+
});
22+
23+
vi.mock("./graph.js", () => {
24+
return {
25+
listTeamsByName: listTeamsByNameMock,
26+
listChannelsForTeam: listChannelsForTeamMock,
27+
normalizeQuery: normalizeQueryMock,
28+
resolveGraphToken: resolveGraphTokenMock,
29+
};
30+
});
31+
32+
import { listMSTeamsDirectoryGroupsLive, listMSTeamsDirectoryPeersLive } from "./directory-live.js";
33+
34+
describe("msteams directory live", () => {
35+
beforeEach(() => {
36+
vi.clearAllMocks();
37+
normalizeQueryMock.mockImplementation((value?: string | null) => value?.trim() ?? "");
38+
});
39+
40+
it("returns normalized peer entries and skips users without ids", async () => {
41+
resolveGraphTokenMock.mockResolvedValue("graph-token");
42+
searchGraphUsersMock.mockResolvedValue([
43+
{
44+
id: "user-1",
45+
displayName: "Alice",
46+
userPrincipalName: "[email protected]",
47+
},
48+
{
49+
id: "user-2",
50+
displayName: "Bob",
51+
52+
},
53+
{
54+
displayName: "Missing Id",
55+
},
56+
]);
57+
58+
await expect(
59+
listMSTeamsDirectoryPeersLive({
60+
cfg: {},
61+
query: " ali ",
62+
}),
63+
).resolves.toEqual([
64+
{
65+
kind: "user",
66+
id: "user:user-1",
67+
name: "Alice",
68+
handle: "@[email protected]",
69+
raw: {
70+
id: "user-1",
71+
displayName: "Alice",
72+
userPrincipalName: "[email protected]",
73+
},
74+
},
75+
{
76+
kind: "user",
77+
id: "user:user-2",
78+
name: "Bob",
79+
handle: "@[email protected]",
80+
raw: {
81+
id: "user-2",
82+
displayName: "Bob",
83+
84+
},
85+
},
86+
]);
87+
88+
expect(searchGraphUsersMock).toHaveBeenCalledWith({
89+
token: "graph-token",
90+
query: "ali",
91+
top: 20,
92+
});
93+
});
94+
95+
it("returns team entries without channel queries and honors limits", async () => {
96+
resolveGraphTokenMock.mockResolvedValue("graph-token");
97+
listTeamsByNameMock.mockResolvedValue([
98+
{ id: "team-1", displayName: "Platform" },
99+
{ id: "team-2", displayName: "Infra" },
100+
]);
101+
102+
await expect(
103+
listMSTeamsDirectoryGroupsLive({
104+
cfg: {},
105+
query: "platform",
106+
limit: 1,
107+
}),
108+
).resolves.toEqual([
109+
{
110+
kind: "group",
111+
id: "team:team-1",
112+
name: "Platform",
113+
handle: "#Platform",
114+
raw: { id: "team-1", displayName: "Platform" },
115+
},
116+
]);
117+
});
118+
119+
it("searches channels within matching teams when a team/channel query is used", async () => {
120+
resolveGraphTokenMock.mockResolvedValue("graph-token");
121+
listTeamsByNameMock.mockResolvedValue([
122+
{ id: "team-1", displayName: "Platform" },
123+
{ id: "team-2", displayName: "Infra" },
124+
]);
125+
listChannelsForTeamMock
126+
.mockResolvedValueOnce([
127+
{ id: "chan-1", displayName: "Deployments" },
128+
{ id: "chan-2", displayName: "General" },
129+
])
130+
.mockResolvedValueOnce([{ id: "chan-3", displayName: "Deployments-West" }]);
131+
132+
await expect(
133+
listMSTeamsDirectoryGroupsLive({
134+
cfg: {},
135+
query: "plat / deploy",
136+
}),
137+
).resolves.toEqual([
138+
{
139+
kind: "group",
140+
id: "conversation:chan-1",
141+
name: "Platform/Deployments",
142+
handle: "#Deployments",
143+
raw: { id: "chan-1", displayName: "Deployments" },
144+
},
145+
{
146+
kind: "group",
147+
id: "conversation:chan-3",
148+
name: "Infra/Deployments-West",
149+
handle: "#Deployments-West",
150+
raw: { id: "chan-3", displayName: "Deployments-West" },
151+
},
152+
]);
153+
154+
expect(listTeamsByNameMock).toHaveBeenCalledWith("graph-token", "plat");
155+
});
156+
});

0 commit comments

Comments
 (0)