@kodelyth/msteams 2026.5.42 → 2026.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/klaw.plugin.json +726 -2
  2. package/package.json +18 -6
  3. package/api.ts +0 -3
  4. package/channel-config-api.ts +0 -1
  5. package/channel-plugin-api.ts +0 -2
  6. package/config-api.ts +0 -4
  7. package/contract-api.ts +0 -4
  8. package/index.ts +0 -20
  9. package/runtime-api.ts +0 -66
  10. package/secret-contract-api.ts +0 -5
  11. package/setup-entry.ts +0 -13
  12. package/setup-plugin-api.ts +0 -3
  13. package/src/ai-entity.ts +0 -7
  14. package/src/approval-auth.ts +0 -44
  15. package/src/attachments/bot-framework.test.ts +0 -506
  16. package/src/attachments/bot-framework.ts +0 -348
  17. package/src/attachments/download.ts +0 -328
  18. package/src/attachments/graph.test.ts +0 -441
  19. package/src/attachments/graph.ts +0 -489
  20. package/src/attachments/html.ts +0 -122
  21. package/src/attachments/payload.ts +0 -14
  22. package/src/attachments/remote-media.test.ts +0 -187
  23. package/src/attachments/remote-media.ts +0 -86
  24. package/src/attachments/shared.test.ts +0 -547
  25. package/src/attachments/shared.ts +0 -655
  26. package/src/attachments/types.ts +0 -47
  27. package/src/attachments.graph.test.ts +0 -414
  28. package/src/attachments.helpers.test.ts +0 -245
  29. package/src/attachments.test-helpers.ts +0 -17
  30. package/src/attachments.test.ts +0 -754
  31. package/src/attachments.ts +0 -18
  32. package/src/block-streaming-config.test.ts +0 -61
  33. package/src/channel-api.ts +0 -1
  34. package/src/channel.actions.test.ts +0 -797
  35. package/src/channel.directory.test.ts +0 -176
  36. package/src/channel.message-adapter.test.ts +0 -227
  37. package/src/channel.runtime.ts +0 -56
  38. package/src/channel.setup.ts +0 -77
  39. package/src/channel.test.ts +0 -136
  40. package/src/channel.ts +0 -1176
  41. package/src/config-schema.ts +0 -6
  42. package/src/config-ui-hints.ts +0 -40
  43. package/src/conversation-store-fs.test.ts +0 -81
  44. package/src/conversation-store-fs.ts +0 -149
  45. package/src/conversation-store-helpers.test.ts +0 -202
  46. package/src/conversation-store-helpers.ts +0 -105
  47. package/src/conversation-store-memory.ts +0 -51
  48. package/src/conversation-store.shared.test.ts +0 -260
  49. package/src/conversation-store.ts +0 -71
  50. package/src/directory-live.test.ts +0 -156
  51. package/src/directory-live.ts +0 -111
  52. package/src/doctor.ts +0 -27
  53. package/src/errors.test.ts +0 -154
  54. package/src/errors.ts +0 -270
  55. package/src/feedback-reflection-prompt.ts +0 -117
  56. package/src/feedback-reflection-store.ts +0 -113
  57. package/src/feedback-reflection.test.ts +0 -237
  58. package/src/feedback-reflection.ts +0 -268
  59. package/src/file-consent-helpers.test.ts +0 -328
  60. package/src/file-consent-helpers.ts +0 -115
  61. package/src/file-consent-invoke.ts +0 -150
  62. package/src/file-consent.test.ts +0 -378
  63. package/src/file-consent.ts +0 -223
  64. package/src/graph-chat.ts +0 -36
  65. package/src/graph-group-management.test.ts +0 -332
  66. package/src/graph-group-management.ts +0 -168
  67. package/src/graph-members.test.ts +0 -89
  68. package/src/graph-members.ts +0 -48
  69. package/src/graph-messages.actions.test.ts +0 -253
  70. package/src/graph-messages.read.test.ts +0 -391
  71. package/src/graph-messages.search.test.ts +0 -227
  72. package/src/graph-messages.test-helpers.ts +0 -50
  73. package/src/graph-messages.ts +0 -534
  74. package/src/graph-teams.test.ts +0 -222
  75. package/src/graph-teams.ts +0 -114
  76. package/src/graph-thread.test.ts +0 -252
  77. package/src/graph-thread.ts +0 -146
  78. package/src/graph-upload.test.ts +0 -253
  79. package/src/graph-upload.ts +0 -531
  80. package/src/graph-users.ts +0 -29
  81. package/src/graph.test.ts +0 -540
  82. package/src/graph.ts +0 -308
  83. package/src/inbound.test.ts +0 -221
  84. package/src/inbound.ts +0 -148
  85. package/src/index.ts +0 -4
  86. package/src/media-helpers.test.ts +0 -220
  87. package/src/media-helpers.ts +0 -105
  88. package/src/mentions.test.ts +0 -254
  89. package/src/mentions.ts +0 -114
  90. package/src/messenger.test.ts +0 -961
  91. package/src/messenger.ts +0 -608
  92. package/src/monitor-handler/access.ts +0 -136
  93. package/src/monitor-handler/inbound-media.test.ts +0 -314
  94. package/src/monitor-handler/inbound-media.ts +0 -180
  95. package/src/monitor-handler/message-handler-mock-support.test-support.ts +0 -28
  96. package/src/monitor-handler/message-handler.authz.test.ts +0 -739
  97. package/src/monitor-handler/message-handler.dm-media.test.ts +0 -54
  98. package/src/monitor-handler/message-handler.test-support.ts +0 -99
  99. package/src/monitor-handler/message-handler.thread-parent.test.ts +0 -225
  100. package/src/monitor-handler/message-handler.thread-session.test.ts +0 -132
  101. package/src/monitor-handler/message-handler.ts +0 -1003
  102. package/src/monitor-handler/reaction-handler.test.ts +0 -325
  103. package/src/monitor-handler/reaction-handler.ts +0 -122
  104. package/src/monitor-handler/thread-session.ts +0 -30
  105. package/src/monitor-handler.adaptive-card.test.ts +0 -158
  106. package/src/monitor-handler.feedback-authz.test.ts +0 -357
  107. package/src/monitor-handler.file-consent.test.ts +0 -443
  108. package/src/monitor-handler.sso.test.ts +0 -576
  109. package/src/monitor-handler.test-helpers.ts +0 -181
  110. package/src/monitor-handler.ts +0 -538
  111. package/src/monitor-handler.types.ts +0 -27
  112. package/src/monitor-types.ts +0 -6
  113. package/src/monitor.lifecycle.test.ts +0 -457
  114. package/src/monitor.test.ts +0 -119
  115. package/src/monitor.ts +0 -476
  116. package/src/oauth.flow.ts +0 -77
  117. package/src/oauth.shared.ts +0 -37
  118. package/src/oauth.test.ts +0 -350
  119. package/src/oauth.token.ts +0 -162
  120. package/src/oauth.ts +0 -130
  121. package/src/outbound.test.ts +0 -400
  122. package/src/outbound.ts +0 -198
  123. package/src/pending-uploads-fs.test.ts +0 -261
  124. package/src/pending-uploads-fs.ts +0 -235
  125. package/src/pending-uploads.test.ts +0 -186
  126. package/src/pending-uploads.ts +0 -121
  127. package/src/policy.test.ts +0 -156
  128. package/src/policy.ts +0 -245
  129. package/src/polls-store-memory.ts +0 -32
  130. package/src/polls.test.ts +0 -169
  131. package/src/polls.ts +0 -312
  132. package/src/presentation.ts +0 -93
  133. package/src/probe.test.ts +0 -79
  134. package/src/probe.ts +0 -132
  135. package/src/reply-dispatcher.test.ts +0 -543
  136. package/src/reply-dispatcher.ts +0 -523
  137. package/src/reply-stream-controller.test.ts +0 -424
  138. package/src/reply-stream-controller.ts +0 -334
  139. package/src/resolve-allowlist.test.ts +0 -253
  140. package/src/resolve-allowlist.ts +0 -309
  141. package/src/revoked-context.ts +0 -17
  142. package/src/runtime.ts +0 -12
  143. package/src/sdk-types.ts +0 -59
  144. package/src/sdk.test.ts +0 -727
  145. package/src/sdk.ts +0 -916
  146. package/src/secret-contract.ts +0 -49
  147. package/src/secret-input.ts +0 -7
  148. package/src/send-context.test.ts +0 -93
  149. package/src/send-context.ts +0 -269
  150. package/src/send.test.ts +0 -588
  151. package/src/send.ts +0 -697
  152. package/src/sent-message-cache.test.ts +0 -106
  153. package/src/sent-message-cache.ts +0 -174
  154. package/src/session-route.ts +0 -40
  155. package/src/setup-core.ts +0 -162
  156. package/src/setup-surface.test.ts +0 -175
  157. package/src/setup-surface.ts +0 -319
  158. package/src/sso-token-store.test.ts +0 -74
  159. package/src/sso-token-store.ts +0 -166
  160. package/src/sso.ts +0 -300
  161. package/src/storage.ts +0 -25
  162. package/src/store-fs.ts +0 -42
  163. package/src/streaming-message.test.ts +0 -323
  164. package/src/streaming-message.ts +0 -327
  165. package/src/test-runtime.ts +0 -16
  166. package/src/thread-parent-context.test.ts +0 -224
  167. package/src/thread-parent-context.ts +0 -159
  168. package/src/token-response.ts +0 -11
  169. package/src/token.test.ts +0 -268
  170. package/src/token.ts +0 -194
  171. package/src/user-agent.test.ts +0 -121
  172. package/src/user-agent.ts +0 -53
  173. package/src/webhook-timeouts.ts +0 -27
  174. package/src/welcome-card.test.ts +0 -104
  175. package/src/welcome-card.ts +0 -57
  176. package/test-api.ts +0 -1
  177. package/tsconfig.json +0 -16
@@ -1,253 +0,0 @@
1
- import { beforeAll, describe, expect, it } from "vitest";
2
- import type { KlawConfig } from "../runtime-api.js";
3
- import {
4
- CHANNEL_TO,
5
- CHAT_ID,
6
- TOKEN,
7
- type GraphMessagesTestModule,
8
- getGraphMessagesMockState,
9
- installGraphMessagesMockDefaults,
10
- loadGraphMessagesTestModule,
11
- } from "./graph-messages.test-helpers.js";
12
-
13
- const mockState = getGraphMessagesMockState();
14
- installGraphMessagesMockDefaults();
15
- let pinMessageMSTeams: GraphMessagesTestModule["pinMessageMSTeams"];
16
- let reactMessageMSTeams: GraphMessagesTestModule["reactMessageMSTeams"];
17
- let unpinMessageMSTeams: GraphMessagesTestModule["unpinMessageMSTeams"];
18
- let unreactMessageMSTeams: GraphMessagesTestModule["unreactMessageMSTeams"];
19
-
20
- beforeAll(async () => {
21
- ({ pinMessageMSTeams, reactMessageMSTeams, unpinMessageMSTeams, unreactMessageMSTeams } =
22
- await loadGraphMessagesTestModule());
23
- });
24
-
25
- const emptyReactionCases: Array<{
26
- name: string;
27
- invoke: () => Promise<unknown>;
28
- }> = [
29
- {
30
- name: "reactMessageMSTeams",
31
- invoke: () =>
32
- reactMessageMSTeams({
33
- cfg: {} as KlawConfig,
34
- to: CHAT_ID,
35
- messageId: "msg-1",
36
- reactionType: " ",
37
- }),
38
- },
39
- {
40
- name: "unreactMessageMSTeams",
41
- invoke: () =>
42
- unreactMessageMSTeams({
43
- cfg: {} as KlawConfig,
44
- to: CHAT_ID,
45
- messageId: "msg-1",
46
- reactionType: "",
47
- }),
48
- },
49
- ];
50
-
51
- describe("MSTeams reaction validation", () => {
52
- it.each(emptyReactionCases)("$name rejects empty reaction type", async ({ invoke }) => {
53
- await expect(invoke()).rejects.toThrow(/Reaction type is required/);
54
- });
55
- });
56
-
57
- describe("pinMessageMSTeams", () => {
58
- it("pins a message in a chat via message@odata.bind body", async () => {
59
- mockState.postGraphJson.mockResolvedValue({ id: "pinned-1" });
60
-
61
- const result = await pinMessageMSTeams({
62
- cfg: {} as KlawConfig,
63
- to: CHAT_ID,
64
- messageId: "msg-1",
65
- });
66
-
67
- expect(result).toEqual({ ok: true, pinnedMessageId: "pinned-1" });
68
- expect(mockState.postGraphJson).toHaveBeenCalledWith({
69
- token: TOKEN,
70
- path: `/chats/${encodeURIComponent(CHAT_ID)}/pinnedMessages`,
71
- body: {
72
- "message@odata.bind": `https://graph.microsoft.com/v1.0/chats/${encodeURIComponent(
73
- CHAT_ID,
74
- )}/messages/${encodeURIComponent("msg-1")}`,
75
- },
76
- });
77
- });
78
-
79
- it("rejects pinning a message in a channel on Graph v1.0", async () => {
80
- await expect(
81
- pinMessageMSTeams({
82
- cfg: {} as KlawConfig,
83
- to: CHANNEL_TO,
84
- messageId: "msg-2",
85
- }),
86
- ).rejects.toThrow(/Pin\/unpin is not supported for channel messages/);
87
- expect(mockState.postGraphJson).not.toHaveBeenCalled();
88
- });
89
- });
90
-
91
- describe("unpinMessageMSTeams", () => {
92
- it("unpins a message from a chat", async () => {
93
- mockState.deleteGraphRequest.mockResolvedValue(undefined);
94
-
95
- const result = await unpinMessageMSTeams({
96
- cfg: {} as KlawConfig,
97
- to: CHAT_ID,
98
- pinnedMessageId: "pinned-1",
99
- });
100
-
101
- expect(result).toEqual({ ok: true });
102
- expect(mockState.deleteGraphRequest).toHaveBeenCalledWith({
103
- token: TOKEN,
104
- path: `/chats/${encodeURIComponent(CHAT_ID)}/pinnedMessages/${encodeURIComponent("pinned-1")}`,
105
- });
106
- });
107
-
108
- it("rejects unpinning a message from a channel on Graph v1.0", async () => {
109
- await expect(
110
- unpinMessageMSTeams({
111
- cfg: {} as KlawConfig,
112
- to: CHANNEL_TO,
113
- pinnedMessageId: "pinned-2",
114
- }),
115
- ).rejects.toThrow(/Pin\/unpin is not supported for channel messages/);
116
- expect(mockState.deleteGraphRequest).not.toHaveBeenCalled();
117
- });
118
- });
119
-
120
- describe("reactMessageMSTeams", () => {
121
- it("sets a like reaction on a chat message", async () => {
122
- mockState.postGraphBetaJson.mockResolvedValue(undefined);
123
-
124
- const result = await reactMessageMSTeams({
125
- cfg: {} as KlawConfig,
126
- to: CHAT_ID,
127
- messageId: "msg-1",
128
- reactionType: "like",
129
- });
130
-
131
- expect(result).toEqual({ ok: true });
132
- expect(mockState.postGraphBetaJson).toHaveBeenCalledWith({
133
- token: TOKEN,
134
- path: `/chats/${encodeURIComponent(CHAT_ID)}/messages/msg-1/setReaction`,
135
- body: { reactionType: "like" },
136
- });
137
- });
138
-
139
- it("sets a reaction on a channel message", async () => {
140
- mockState.postGraphBetaJson.mockResolvedValue(undefined);
141
-
142
- const result = await reactMessageMSTeams({
143
- cfg: {} as KlawConfig,
144
- to: CHANNEL_TO,
145
- messageId: "msg-2",
146
- reactionType: "heart",
147
- });
148
-
149
- expect(result).toEqual({ ok: true });
150
- expect(mockState.postGraphBetaJson).toHaveBeenCalledWith({
151
- token: TOKEN,
152
- path: "/teams/team-id-1/channels/channel-id-1/messages/msg-2/setReaction",
153
- body: { reactionType: "heart" },
154
- });
155
- });
156
-
157
- it("normalizes reaction type to lowercase", async () => {
158
- mockState.postGraphBetaJson.mockResolvedValue(undefined);
159
-
160
- await reactMessageMSTeams({
161
- cfg: {} as KlawConfig,
162
- to: CHAT_ID,
163
- messageId: "msg-1",
164
- reactionType: "LAUGH",
165
- });
166
-
167
- expect(mockState.postGraphBetaJson).toHaveBeenCalledWith({
168
- token: TOKEN,
169
- path: `/chats/${encodeURIComponent(CHAT_ID)}/messages/msg-1/setReaction`,
170
- body: { reactionType: "laugh" },
171
- });
172
- });
173
-
174
- it("passes through non-well-known reaction types (e.g. Unicode emoji)", async () => {
175
- // Graph setReaction accepts arbitrary Unicode emoji plus the legacy
176
- // well-known types; normalizeReactionType only lowercases the legacy set
177
- // and lets any other non-empty value through unchanged.
178
- mockState.postGraphBetaJson.mockResolvedValue(undefined);
179
-
180
- await reactMessageMSTeams({
181
- cfg: {} as KlawConfig,
182
- to: CHAT_ID,
183
- messageId: "msg-1",
184
- reactionType: "🎉",
185
- });
186
-
187
- expect(mockState.postGraphBetaJson).toHaveBeenCalledWith({
188
- token: TOKEN,
189
- path: `/chats/${encodeURIComponent(CHAT_ID)}/messages/msg-1/setReaction`,
190
- body: { reactionType: "🎉" },
191
- });
192
- });
193
-
194
- it("resolves user: target through conversation store", async () => {
195
- mockState.findPreferredDmByUserId.mockResolvedValue({
196
- conversationId: "a:bot-id",
197
- reference: { graphChatId: "19:dm-chat@thread.tacv2" },
198
- });
199
- mockState.postGraphBetaJson.mockResolvedValue(undefined);
200
-
201
- await reactMessageMSTeams({
202
- cfg: {} as KlawConfig,
203
- to: "user:aad-user-1",
204
- messageId: "msg-1",
205
- reactionType: "like",
206
- });
207
-
208
- expect(mockState.findPreferredDmByUserId).toHaveBeenCalledWith("aad-user-1");
209
- expect(mockState.postGraphBetaJson).toHaveBeenCalledWith({
210
- token: TOKEN,
211
- path: `/chats/${encodeURIComponent("19:dm-chat@thread.tacv2")}/messages/msg-1/setReaction`,
212
- body: { reactionType: "like" },
213
- });
214
- });
215
- });
216
-
217
- describe("unreactMessageMSTeams", () => {
218
- it("removes a reaction from a chat message", async () => {
219
- mockState.postGraphBetaJson.mockResolvedValue(undefined);
220
-
221
- const result = await unreactMessageMSTeams({
222
- cfg: {} as KlawConfig,
223
- to: CHAT_ID,
224
- messageId: "msg-1",
225
- reactionType: "sad",
226
- });
227
-
228
- expect(result).toEqual({ ok: true });
229
- expect(mockState.postGraphBetaJson).toHaveBeenCalledWith({
230
- token: TOKEN,
231
- path: `/chats/${encodeURIComponent(CHAT_ID)}/messages/msg-1/unsetReaction`,
232
- body: { reactionType: "sad" },
233
- });
234
- });
235
-
236
- it("removes a reaction from a channel message", async () => {
237
- mockState.postGraphBetaJson.mockResolvedValue(undefined);
238
-
239
- const result = await unreactMessageMSTeams({
240
- cfg: {} as KlawConfig,
241
- to: CHANNEL_TO,
242
- messageId: "msg-2",
243
- reactionType: "angry",
244
- });
245
-
246
- expect(result).toEqual({ ok: true });
247
- expect(mockState.postGraphBetaJson).toHaveBeenCalledWith({
248
- token: TOKEN,
249
- path: "/teams/team-id-1/channels/channel-id-1/messages/msg-2/unsetReaction",
250
- body: { reactionType: "angry" },
251
- });
252
- });
253
- });
@@ -1,391 +0,0 @@
1
- import { beforeAll, describe, expect, it } from "vitest";
2
- import type { KlawConfig } from "../runtime-api.js";
3
- import {
4
- CHANNEL_TO,
5
- CHAT_ID,
6
- TOKEN,
7
- type GraphMessagesTestModule,
8
- getGraphMessagesMockState,
9
- installGraphMessagesMockDefaults,
10
- loadGraphMessagesTestModule,
11
- } from "./graph-messages.test-helpers.js";
12
-
13
- const mockState = getGraphMessagesMockState();
14
- installGraphMessagesMockDefaults();
15
- let getMessageMSTeams: GraphMessagesTestModule["getMessageMSTeams"];
16
- let listPinsMSTeams: GraphMessagesTestModule["listPinsMSTeams"];
17
- let listReactionsMSTeams: GraphMessagesTestModule["listReactionsMSTeams"];
18
-
19
- beforeAll(async () => {
20
- ({ getMessageMSTeams, listPinsMSTeams, listReactionsMSTeams } =
21
- await loadGraphMessagesTestModule());
22
- });
23
-
24
- describe("getMessageMSTeams", () => {
25
- it("resolves user: target using graphChatId from store", async () => {
26
- mockState.findPreferredDmByUserId.mockResolvedValue({
27
- conversationId: "a:bot-framework-dm-id",
28
- reference: { graphChatId: "19:graph-native-chat@thread.tacv2" },
29
- });
30
- mockState.fetchGraphJson.mockResolvedValue({
31
- id: "msg-1",
32
- body: { content: "From user DM" },
33
- createdDateTime: "2026-03-23T12:00:00Z",
34
- });
35
-
36
- await getMessageMSTeams({
37
- cfg: {} as KlawConfig,
38
- to: "user:aad-object-id-123",
39
- messageId: "msg-1",
40
- });
41
-
42
- expect(mockState.findPreferredDmByUserId).toHaveBeenCalledWith("aad-object-id-123");
43
- expect(mockState.fetchGraphJson).toHaveBeenCalledWith({
44
- token: TOKEN,
45
- path: `/chats/${encodeURIComponent("19:graph-native-chat@thread.tacv2")}/messages/msg-1`,
46
- });
47
- });
48
-
49
- it("falls back to conversationId when it starts with 19:", async () => {
50
- mockState.findPreferredDmByUserId.mockResolvedValue({
51
- conversationId: "19:resolved-chat@thread.tacv2",
52
- reference: {},
53
- });
54
- mockState.fetchGraphJson.mockResolvedValue({
55
- id: "msg-1",
56
- body: { content: "Hello" },
57
- createdDateTime: "2026-03-23T10:00:00Z",
58
- });
59
-
60
- await getMessageMSTeams({
61
- cfg: {} as KlawConfig,
62
- to: "user:aad-id",
63
- messageId: "msg-1",
64
- });
65
-
66
- expect(mockState.fetchGraphJson).toHaveBeenCalledWith({
67
- token: TOKEN,
68
- path: `/chats/${encodeURIComponent("19:resolved-chat@thread.tacv2")}/messages/msg-1`,
69
- });
70
- });
71
-
72
- it("throws when user: target has no stored conversation", async () => {
73
- mockState.findPreferredDmByUserId.mockResolvedValue(null);
74
-
75
- await expect(
76
- getMessageMSTeams({
77
- cfg: {} as KlawConfig,
78
- to: "user:unknown-user",
79
- messageId: "msg-1",
80
- }),
81
- ).rejects.toThrow("No conversation found for user:unknown-user");
82
- });
83
-
84
- it("throws when user: target has Bot Framework ID and no graphChatId", async () => {
85
- mockState.findPreferredDmByUserId.mockResolvedValue({
86
- conversationId: "a:bot-framework-dm-id",
87
- reference: {},
88
- });
89
-
90
- await expect(
91
- getMessageMSTeams({
92
- cfg: {} as KlawConfig,
93
- to: "user:some-user",
94
- messageId: "msg-1",
95
- }),
96
- ).rejects.toThrow("Bot Framework ID");
97
- });
98
-
99
- it("strips conversation: prefix from target", async () => {
100
- mockState.fetchGraphJson.mockResolvedValue({
101
- id: "msg-1",
102
- body: { content: "Hello" },
103
- from: undefined,
104
- createdDateTime: "2026-03-23T10:00:00Z",
105
- });
106
-
107
- await getMessageMSTeams({
108
- cfg: {} as KlawConfig,
109
- to: `conversation:${CHAT_ID}`,
110
- messageId: "msg-1",
111
- });
112
-
113
- expect(mockState.fetchGraphJson).toHaveBeenCalledWith({
114
- token: TOKEN,
115
- path: `/chats/${encodeURIComponent(CHAT_ID)}/messages/msg-1`,
116
- });
117
- });
118
-
119
- it("reads a message from a chat conversation", async () => {
120
- mockState.fetchGraphJson.mockResolvedValue({
121
- id: "msg-1",
122
- body: { content: "Hello world", contentType: "text" },
123
- from: { user: { id: "user-1", displayName: "Alice" } },
124
- createdDateTime: "2026-03-23T10:00:00Z",
125
- });
126
-
127
- const result = await getMessageMSTeams({
128
- cfg: {} as KlawConfig,
129
- to: CHAT_ID,
130
- messageId: "msg-1",
131
- });
132
-
133
- expect(result).toEqual({
134
- id: "msg-1",
135
- text: "Hello world",
136
- from: { user: { id: "user-1", displayName: "Alice" } },
137
- createdAt: "2026-03-23T10:00:00Z",
138
- });
139
- expect(mockState.fetchGraphJson).toHaveBeenCalledWith({
140
- token: TOKEN,
141
- path: `/chats/${encodeURIComponent(CHAT_ID)}/messages/msg-1`,
142
- });
143
- });
144
-
145
- it("reads a message from a channel conversation", async () => {
146
- mockState.fetchGraphJson.mockResolvedValue({
147
- id: "msg-2",
148
- body: { content: "Channel message" },
149
- from: { application: { id: "app-1", displayName: "Bot" } },
150
- createdDateTime: "2026-03-23T11:00:00Z",
151
- });
152
-
153
- const result = await getMessageMSTeams({
154
- cfg: {} as KlawConfig,
155
- to: CHANNEL_TO,
156
- messageId: "msg-2",
157
- });
158
-
159
- expect(result).toEqual({
160
- id: "msg-2",
161
- text: "Channel message",
162
- from: { application: { id: "app-1", displayName: "Bot" } },
163
- createdAt: "2026-03-23T11:00:00Z",
164
- });
165
- expect(mockState.fetchGraphJson).toHaveBeenCalledWith({
166
- token: TOKEN,
167
- path: "/teams/team-id-1/channels/channel-id-1/messages/msg-2",
168
- });
169
- });
170
- });
171
-
172
- describe("listPinsMSTeams", () => {
173
- it("lists pinned messages in a chat", async () => {
174
- mockState.fetchGraphJson.mockResolvedValue({
175
- value: [
176
- {
177
- id: "pinned-1",
178
- message: { id: "msg-1", body: { content: "Pinned msg" } },
179
- },
180
- {
181
- id: "pinned-2",
182
- message: { id: "msg-2", body: { content: "Another pin" } },
183
- },
184
- ],
185
- });
186
-
187
- const result = await listPinsMSTeams({
188
- cfg: {} as KlawConfig,
189
- to: CHAT_ID,
190
- });
191
-
192
- expect(result.pins).toEqual([
193
- { id: "pinned-1", pinnedMessageId: "pinned-1", messageId: "msg-1", text: "Pinned msg" },
194
- { id: "pinned-2", pinnedMessageId: "pinned-2", messageId: "msg-2", text: "Another pin" },
195
- ]);
196
- expect(mockState.fetchGraphJson).toHaveBeenCalledWith({
197
- token: TOKEN,
198
- path: `/chats/${encodeURIComponent(CHAT_ID)}/pinnedMessages?$expand=message`,
199
- });
200
- });
201
-
202
- it("returns empty array when no pins exist", async () => {
203
- mockState.fetchGraphJson.mockResolvedValue({ value: [] });
204
-
205
- const result = await listPinsMSTeams({
206
- cfg: {} as KlawConfig,
207
- to: CHAT_ID,
208
- });
209
-
210
- expect(result.pins).toStrictEqual([]);
211
- });
212
-
213
- it("follows @odata.nextLink pagination", async () => {
214
- mockState.fetchGraphJson.mockResolvedValue({
215
- value: [{ id: "pinned-1", message: { id: "msg-1", body: { content: "First page" } } }],
216
- "@odata.nextLink":
217
- "https://graph.microsoft.com/v1.0/chats/19%3Aabc%40thread.tacv2/pinnedMessages?$expand=message&$skiptoken=page2",
218
- });
219
- mockState.fetchGraphAbsoluteUrl.mockResolvedValue({
220
- value: [{ id: "pinned-2", message: { id: "msg-2", body: { content: "Second page" } } }],
221
- });
222
-
223
- const result = await listPinsMSTeams({
224
- cfg: {} as KlawConfig,
225
- to: CHAT_ID,
226
- });
227
-
228
- expect(result.pins).toEqual([
229
- { id: "pinned-1", pinnedMessageId: "pinned-1", messageId: "msg-1", text: "First page" },
230
- { id: "pinned-2", pinnedMessageId: "pinned-2", messageId: "msg-2", text: "Second page" },
231
- ]);
232
- expect(mockState.fetchGraphAbsoluteUrl).toHaveBeenCalledWith({
233
- token: TOKEN,
234
- url: "https://graph.microsoft.com/v1.0/chats/19%3Aabc%40thread.tacv2/pinnedMessages?$expand=message&$skiptoken=page2",
235
- });
236
- });
237
-
238
- it("stops paginating after max pages", async () => {
239
- const makePageResponse = (pageNum: number) => ({
240
- value: [
241
- {
242
- id: `pinned-${pageNum}`,
243
- message: { id: `msg-${pageNum}`, body: { content: `Page ${pageNum}` } },
244
- },
245
- ],
246
- "@odata.nextLink": `https://graph.microsoft.com/v1.0/next?page=${pageNum + 1}`,
247
- });
248
-
249
- mockState.fetchGraphJson.mockResolvedValue(makePageResponse(1));
250
- for (let i = 2; i <= 10; i++) {
251
- mockState.fetchGraphAbsoluteUrl.mockResolvedValueOnce(makePageResponse(i));
252
- }
253
-
254
- const result = await listPinsMSTeams({
255
- cfg: {} as KlawConfig,
256
- to: CHAT_ID,
257
- });
258
-
259
- expect(result.pins).toHaveLength(10);
260
- expect(mockState.fetchGraphAbsoluteUrl).toHaveBeenCalledTimes(9);
261
- });
262
-
263
- it("throws for channel list-pins (not supported on Graph v1.0)", async () => {
264
- await expect(
265
- listPinsMSTeams({
266
- cfg: {} as KlawConfig,
267
- to: CHANNEL_TO,
268
- }),
269
- ).rejects.toThrow("not supported for channels");
270
- });
271
- });
272
-
273
- describe("listReactionsMSTeams", () => {
274
- it("lists reactions grouped by type with user details", async () => {
275
- mockState.fetchGraphJson.mockResolvedValue({
276
- id: "msg-1",
277
- body: { content: "Hello" },
278
- reactions: [
279
- { reactionType: "like", user: { id: "u1", displayName: "Alice" } },
280
- { reactionType: "like", user: { id: "u2", displayName: "Bob" } },
281
- { reactionType: "heart", user: { id: "u1", displayName: "Alice" } },
282
- ],
283
- });
284
-
285
- const result = await listReactionsMSTeams({
286
- cfg: {} as KlawConfig,
287
- to: CHAT_ID,
288
- messageId: "msg-1",
289
- });
290
-
291
- expect(result.reactions).toEqual([
292
- {
293
- reactionType: "like",
294
- name: "like",
295
- emoji: "\u{1F44D}",
296
- count: 2,
297
- users: [
298
- { id: "u1", displayName: "Alice" },
299
- { id: "u2", displayName: "Bob" },
300
- ],
301
- },
302
- {
303
- reactionType: "heart",
304
- name: "heart",
305
- emoji: "\u2764\uFE0F",
306
- count: 1,
307
- users: [{ id: "u1", displayName: "Alice" }],
308
- },
309
- ]);
310
- });
311
-
312
- it("returns empty array when message has no reactions", async () => {
313
- mockState.fetchGraphJson.mockResolvedValue({
314
- id: "msg-1",
315
- body: { content: "No reactions" },
316
- });
317
-
318
- const result = await listReactionsMSTeams({
319
- cfg: {} as KlawConfig,
320
- to: CHAT_ID,
321
- messageId: "msg-1",
322
- });
323
-
324
- expect(result.reactions).toStrictEqual([]);
325
- });
326
-
327
- it("counts reactions from users without an ID", async () => {
328
- mockState.fetchGraphJson.mockResolvedValue({
329
- id: "msg-1",
330
- body: { content: "Hello" },
331
- reactions: [
332
- { reactionType: "like", user: { id: "u1", displayName: "Alice" } },
333
- { reactionType: "like", user: { displayName: "Deleted User" } },
334
- { reactionType: "like", user: undefined },
335
- { reactionType: "like" },
336
- { reactionType: "heart", user: { id: "u2", displayName: "Bob" } },
337
- ],
338
- });
339
-
340
- const result = await listReactionsMSTeams({
341
- cfg: {} as KlawConfig,
342
- to: CHAT_ID,
343
- messageId: "msg-1",
344
- });
345
-
346
- expect(result.reactions).toEqual([
347
- {
348
- reactionType: "like",
349
- name: "like",
350
- emoji: "\u{1F44D}",
351
- count: 4,
352
- users: [{ id: "u1", displayName: "Alice" }],
353
- },
354
- {
355
- reactionType: "heart",
356
- name: "heart",
357
- emoji: "\u2764\uFE0F",
358
- count: 1,
359
- users: [{ id: "u2", displayName: "Bob" }],
360
- },
361
- ]);
362
- });
363
-
364
- it("fetches from channel path for channel targets", async () => {
365
- mockState.fetchGraphJson.mockResolvedValue({
366
- id: "msg-2",
367
- body: { content: "Channel msg" },
368
- reactions: [{ reactionType: "surprised", user: { id: "u3", displayName: "Carol" } }],
369
- });
370
-
371
- const result = await listReactionsMSTeams({
372
- cfg: {} as KlawConfig,
373
- to: CHANNEL_TO,
374
- messageId: "msg-2",
375
- });
376
-
377
- expect(result.reactions).toEqual([
378
- {
379
- reactionType: "surprised",
380
- name: "surprised",
381
- emoji: "\u{1F62E}",
382
- count: 1,
383
- users: [{ id: "u3", displayName: "Carol" }],
384
- },
385
- ]);
386
- expect(mockState.fetchGraphJson).toHaveBeenCalledWith({
387
- token: TOKEN,
388
- path: "/teams/team-id-1/channels/channel-id-1/messages/msg-2",
389
- });
390
- });
391
- });