Skip to content

Open-source AI coworkers that each get a computer of their own: a browser, files and tools, with every action decided before it happens and recorded after. Bring any AG-UI agent.

2.1 KB
Raw Blame
import { describe, expect, test } from "bun:test";
import { linkedNotice, visibleLinkedNotice } from "./linked-notice";

describe("linkedNotice", () => {
  test("reports a linked GitHub account", () => {
    expect(linkedNotice("github")).toEqual({
      tone: "success",
      text: "Your GitHub account is linked.",
    });
  });

  test("reports a failed link", () => {
    expect(linkedNotice("failed")).toEqual({
      tone: "error",
      text: "Couldn't link your GitHub account. Try again.",
    });
  });

  test("tells the person the GitHub account belongs to another user, as an alert", () => {
    expect(linkedNotice("github-taken")).toEqual({
      tone: "error",
      text: "That GitHub account is linked to someone else in OpenBot. Sign in to GitHub with another account and try again, or ask an admin.",
    });
  });

  test.each([undefined, "", "slack", "__proto__"])(
    "says nothing for %p",
    (value) => {
      expect(linkedNotice(value)).toBeNull();
    },
  );
});

describe("visibleLinkedNotice", () => {
  const success = linkedNotice("github");
  const github = { provider: "github" as const };
  const slack = { provider: "slack" as const };

  test("shows the success notice while a GitHub link exists", () => {
    expect(visibleLinkedNotice(success, [slack, github])).toEqual(success);
  });

  test("hides the success notice once the GitHub link is gone", () => {
    expect(visibleLinkedNotice(success, [slack])).toBeNull();
    expect(visibleLinkedNotice(success, [])).toBeNull();
  });

  test("hides the success notice until the links have loaded", () => {
    expect(visibleLinkedNotice(success, undefined)).toBeNull();
  });

  test.each(["failed", "github-taken"])(
    "leaves the %s error notice alone whatever the links say",
    (value) => {
      const notice = linkedNotice(value);
      expect(visibleLinkedNotice(notice, [])).toEqual(notice);
      expect(visibleLinkedNotice(notice, undefined)).toEqual(notice);
    },
  );

  test("passes no notice through as none", () => {
    expect(visibleLinkedNotice(null, [github])).toBeNull();
  });
});