this repo has no description
at main 3.2 kB view raw
1import { describe, expect, test, beforeEach } from "bun:test"; 2import { channelMappings, userMappings } from "./lib/db"; 3 4describe("channel mappings uniqueness", () => { 5 beforeEach(() => { 6 // Clean up mappings before each test 7 const channels = channelMappings.getAll(); 8 for (const channel of channels) { 9 channelMappings.delete(channel.slack_channel_id); 10 } 11 }); 12 13 test("prevents duplicate IRC channel mappings", () => { 14 channelMappings.create("C001", "#test"); 15 16 const existing = channelMappings.getByIrcChannel("#test"); 17 expect(existing).not.toBeNull(); 18 expect(existing?.slack_channel_id).toBe("C001"); 19 20 // Trying to map a different Slack channel to the same IRC channel should be prevented 21 const duplicate = channelMappings.getByIrcChannel("#test"); 22 expect(duplicate).not.toBeNull(); 23 expect(duplicate?.slack_channel_id).toBe("C001"); 24 }); 25 26 test("prevents duplicate Slack channel mappings", () => { 27 channelMappings.create("C001", "#test"); 28 29 const existing = channelMappings.getBySlackChannel("C001"); 30 expect(existing).not.toBeNull(); 31 expect(existing?.irc_channel).toBe("#test"); 32 33 // The same Slack channel should keep its original mapping 34 channelMappings.create("C001", "#new"); 35 const updated = channelMappings.getBySlackChannel("C001"); 36 expect(updated?.irc_channel).toBe("#new"); 37 }); 38 39 test("allows different channels to map to different IRC channels", () => { 40 channelMappings.create("C001", "#test1"); 41 channelMappings.create("C002", "#test2"); 42 43 const mapping1 = channelMappings.getBySlackChannel("C001"); 44 const mapping2 = channelMappings.getBySlackChannel("C002"); 45 46 expect(mapping1?.irc_channel).toBe("#test1"); 47 expect(mapping2?.irc_channel).toBe("#test2"); 48 }); 49}); 50 51describe("user mappings uniqueness", () => { 52 beforeEach(() => { 53 // Clean up mappings before each test 54 const users = userMappings.getAll(); 55 for (const user of users) { 56 userMappings.delete(user.slack_user_id); 57 } 58 }); 59 60 test("prevents duplicate IRC nick mappings", () => { 61 userMappings.create("U001", "testnick"); 62 63 const existing = userMappings.getByIrcNick("testnick"); 64 expect(existing).not.toBeNull(); 65 expect(existing?.slack_user_id).toBe("U001"); 66 67 // Trying to map a different Slack user to the same IRC nick should be prevented 68 const duplicate = userMappings.getByIrcNick("testnick"); 69 expect(duplicate).not.toBeNull(); 70 expect(duplicate?.slack_user_id).toBe("U001"); 71 }); 72 73 test("prevents duplicate Slack user mappings", () => { 74 userMappings.create("U001", "testnick"); 75 76 const existing = userMappings.getBySlackUser("U001"); 77 expect(existing).not.toBeNull(); 78 expect(existing?.irc_nick).toBe("testnick"); 79 80 // The same Slack user should keep its original mapping 81 userMappings.create("U001", "newnick"); 82 const updated = userMappings.getBySlackUser("U001"); 83 expect(updated?.irc_nick).toBe("newnick"); 84 }); 85 86 test("allows different users to map to different IRC nicks", () => { 87 userMappings.create("U001", "nick1"); 88 userMappings.create("U002", "nick2"); 89 90 const mapping1 = userMappings.getBySlackUser("U001"); 91 const mapping2 = userMappings.getBySlackUser("U002"); 92 93 expect(mapping1?.irc_nick).toBe("nick1"); 94 expect(mapping2?.irc_nick).toBe("nick2"); 95 }); 96});