Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

1.8 KB
Raw Blame
import { describe, expect, it } from "vitest";

import { normalizeReaction, reactionAnswer, REACTIONS } from "./reactions.ts";

describe("reactions", () => {
  it("reads πŸ‘ as yes and πŸ‘Ž as no, and nothing else as an answer", () => {
    expect(reactionAnswer("πŸ‘")).toBe("yes");
    expect(reactionAnswer("πŸ‘Ž")).toBe("no");
    for (const feeling of REACTIONS.filter((emoji) => emoji !== "πŸ‘" && emoji !== "πŸ‘Ž")) expect(reactionAnswer(feeling)).toBeNull();
    expect(reactionAnswer(undefined)).toBeNull();
    expect(reactionAnswer(null)).toBeNull();
  });

  it("takes each offered emoji as itself", () => {
    for (const emoji of REACTIONS) expect(normalizeReaction(emoji)).toBe(emoji);
  });

  it("takes the same emoji however a platform spells it", () => {
    expect(normalizeReaction("πŸ‘πŸ½")).toBe("πŸ‘");
    expect(normalizeReaction("πŸ‘ŽπŸΏ")).toBe("πŸ‘Ž");
    expect(normalizeReaction("❀")).toBe("❀️");
    expect(normalizeReaction(" πŸ‘€ ")).toBe("πŸ‘€");
  });

  it("takes Slack's names, with or without colons and skin tones", () => {
    expect(normalizeReaction("+1")).toBe("πŸ‘");
    expect(normalizeReaction(":thumbsup:")).toBe("πŸ‘");
    expect(normalizeReaction("+1::skin-tone-4")).toBe("πŸ‘");
    expect(normalizeReaction("-1")).toBe("πŸ‘Ž");
    expect(normalizeReaction("thumbsdown")).toBe("πŸ‘Ž");
    expect(normalizeReaction("heart")).toBe("❀️");
    expect(normalizeReaction("joy")).toBe("πŸ˜‚");
    expect(normalizeReaction("tada")).toBe("πŸŽ‰");
    expect(normalizeReaction("eyes")).toBe("πŸ‘€");
  });

  it("refuses anything outside the set", () => {
    for (const raw of ["πŸ”₯", "πŸ‘πŸ‘", "yes", "white_check_mark", "", "__proto__", "constructor", "toString", 1, null, undefined, {}, "πŸ‘".repeat(40)]) {
      expect(normalizeReaction(raw), String(raw)).toBeNull();
    }
  });
});