this repo has no description
at main 1.7 kB view raw
1import { describe, expect, test } from "bun:test"; 2import { convertIrcMentionsToSlack } from "./mentions"; 3import { userMappings } from "./db"; 4 5describe("convertIrcMentionsToSlack", () => { 6 test("converts @mention when user mapping exists", () => { 7 // Setup test data 8 userMappings.create("U123", "testuser"); 9 10 const result = convertIrcMentionsToSlack("Hey @testuser how are you?"); 11 expect(result).toBe("Hey <@U123> how are you?"); 12 13 // Cleanup 14 userMappings.delete("U123"); 15 }); 16 17 test("leaves @mention unchanged when no mapping exists", () => { 18 const result = convertIrcMentionsToSlack("Hey @unknownuser"); 19 expect(result).toBe("Hey @unknownuser"); 20 }); 21 22 test("converts nick: mention when user mapping exists", () => { 23 userMappings.create("U456", "alice"); 24 25 const result = convertIrcMentionsToSlack("alice: hello"); 26 expect(result).toBe("<@U456>: hello"); 27 28 userMappings.delete("U456"); 29 }); 30 31 test("leaves nick: unchanged when no mapping exists", () => { 32 const result = convertIrcMentionsToSlack("bob: hello"); 33 expect(result).toBe("bob: hello"); 34 }); 35 36 test("handles multiple mentions", () => { 37 userMappings.create("U123", "alice"); 38 userMappings.create("U456", "bob"); 39 40 const result = convertIrcMentionsToSlack("@alice and bob: hello!"); 41 expect(result).toBe("<@U123> and <@U456>: hello!"); 42 43 userMappings.delete("U123"); 44 userMappings.delete("U456"); 45 }); 46 47 test("handles mixed mapped and unmapped mentions", () => { 48 userMappings.create("U123", "alice"); 49 50 const result = convertIrcMentionsToSlack("@alice and @unknown user"); 51 expect(result).toContain("<@U123>"); 52 expect(result).toContain("@unknown"); 53 54 userMappings.delete("U123"); 55 }); 56});