|
| 1 | +import { describe, expect, test } from "bun:test"; |
| 2 | +import { |
| 3 | + getReactionCountForEmoji, |
| 4 | + getThresholdReactionCount, |
| 5 | + matchesConfiguredEmoji, |
| 6 | +} from "./starboard.reaction-utils.js"; |
| 7 | +import { createMessageWithReactions } from "./starboard.test-utils.js"; |
| 8 | + |
| 9 | +describe("matchesConfiguredEmoji", () => { |
| 10 | + test("matches unicode emoji with and without variation selector", () => { |
| 11 | + expect(matchesConfiguredEmoji("⭐", null, "⭐️")).toBe(true); |
| 12 | + }); |
| 13 | + |
| 14 | + test("matches custom emoji by id when config uses Discord emoji syntax", () => { |
| 15 | + expect( |
| 16 | + matchesConfiguredEmoji("star", "1234567890", "<:star:1234567890>"), |
| 17 | + ).toBe(true); |
| 18 | + }); |
| 19 | +}); |
| 20 | + |
| 21 | +describe("getReactionCountForEmoji", () => { |
| 22 | + test("matches unicode emoji with and without variation selector", () => { |
| 23 | + const message = createMessageWithReactions([ |
| 24 | + { |
| 25 | + emoji: { |
| 26 | + name: "⭐", |
| 27 | + id: null, |
| 28 | + }, |
| 29 | + count: 3, |
| 30 | + }, |
| 31 | + ]); |
| 32 | + |
| 33 | + expect(getReactionCountForEmoji(message, "⭐️")).toBe(3); |
| 34 | + }); |
| 35 | + |
| 36 | + test("matches custom emoji when configured as <:name:id>", () => { |
| 37 | + const message = createMessageWithReactions([ |
| 38 | + { |
| 39 | + emoji: { |
| 40 | + name: "star", |
| 41 | + id: "1234567890", |
| 42 | + }, |
| 43 | + count: 4, |
| 44 | + }, |
| 45 | + ]); |
| 46 | + |
| 47 | + expect(getReactionCountForEmoji(message, "<:star:1234567890>")).toBe(4); |
| 48 | + }); |
| 49 | +}); |
| 50 | + |
| 51 | +describe("getThresholdReactionCount", () => { |
| 52 | + test("uses message reaction count when event count is missing", () => { |
| 53 | + const message = createMessageWithReactions([ |
| 54 | + { |
| 55 | + emoji: { |
| 56 | + name: "⭐", |
| 57 | + id: null, |
| 58 | + }, |
| 59 | + count: 2, |
| 60 | + }, |
| 61 | + ]); |
| 62 | + |
| 63 | + expect(getThresholdReactionCount(message, "⭐", null)).toBe(2); |
| 64 | + }); |
| 65 | + |
| 66 | + test("falls back to event reaction count when message cache has no match", () => { |
| 67 | + const message = createMessageWithReactions([]); |
| 68 | + |
| 69 | + expect(getThresholdReactionCount(message, "⭐", 2)).toBe(2); |
| 70 | + }); |
| 71 | +}); |
0 commit comments