|
1 | 1 | // Msteams tests cover mentions plugin behavior. |
2 | 2 | import { describe, expect, it } from "vitest"; |
3 | | -import { buildMentionEntities, formatMentionText, parseMentions } from "./mentions.js"; |
| 3 | +import { |
| 4 | + buildMentionEntities, |
| 5 | + formatMentionText, |
| 6 | + isMSTeamsKeywordMention, |
| 7 | + parseMentions, |
| 8 | +} from "./mentions.js"; |
4 | 9 |
|
5 | 10 | function requireFirstEntity(result: ReturnType<typeof parseMentions>) { |
6 | 11 | const entity = result.entities[0]; |
@@ -253,3 +258,49 @@ describe("formatMentionText", () => { |
253 | 258 | expect(result).toBe("Hey <at>John(Test)</at> and <at>Alice.Smith</at>"); |
254 | 259 | }); |
255 | 260 | }); |
| 261 | + |
| 262 | +describe("isMSTeamsKeywordMention", () => { |
| 263 | + const regexes = [/\bradar\b/i]; |
| 264 | + const base = { |
| 265 | + isDirectMessage: false, |
| 266 | + alreadyMentioned: false, |
| 267 | + text: "hey radar, you there?", |
| 268 | + fromId: "29:user", |
| 269 | + recipientId: "28:bot", |
| 270 | + mentionRegexes: regexes, |
| 271 | + }; |
| 272 | + |
| 273 | + it("treats a keyword match in a channel message as an implicit mention", () => { |
| 274 | + expect(isMSTeamsKeywordMention(base)).toBe(true); |
| 275 | + }); |
| 276 | + |
| 277 | + it("is case-insensitive (regex carries the flag)", () => { |
| 278 | + expect(isMSTeamsKeywordMention({ ...base, text: "RADAR, status?" })).toBe(true); |
| 279 | + }); |
| 280 | + |
| 281 | + it("does not trigger when the keyword is absent", () => { |
| 282 | + expect(isMSTeamsKeywordMention({ ...base, text: "the weather is nice today" })).toBe(false); |
| 283 | + }); |
| 284 | + |
| 285 | + it("does not trigger on the bot's own posts (self-echo guard)", () => { |
| 286 | + expect(isMSTeamsKeywordMention({ ...base, fromId: "28:bot", recipientId: "28:bot" })).toBe( |
| 287 | + false, |
| 288 | + ); |
| 289 | + }); |
| 290 | + |
| 291 | + it("skips direct messages (handled by the normal DM path)", () => { |
| 292 | + expect(isMSTeamsKeywordMention({ ...base, isDirectMessage: true })).toBe(false); |
| 293 | + }); |
| 294 | + |
| 295 | + it("skips messages already @mentioned (handled normally)", () => { |
| 296 | + expect(isMSTeamsKeywordMention({ ...base, alreadyMentioned: true })).toBe(false); |
| 297 | + }); |
| 298 | + |
| 299 | + it("no-ops when no patterns are configured", () => { |
| 300 | + expect(isMSTeamsKeywordMention({ ...base, mentionRegexes: [] })).toBe(false); |
| 301 | + }); |
| 302 | + |
| 303 | + it("no-ops on empty text", () => { |
| 304 | + expect(isMSTeamsKeywordMention({ ...base, text: undefined })).toBe(false); |
| 305 | + }); |
| 306 | +}); |
0 commit comments