Skip to content

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

2.1 KB
Raw Blame
import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, describe, expect, it } from "vitest";

import { createTeamPeople } from "./team-people.ts";

const dirs: string[] = [];
const dir = () => { const made = mkdtempSync(join(tmpdir(), "omb-team-people-")); dirs.push(made); return made; };
afterEach(() => { for (const made of dirs.splice(0)) rmSync(made, { recursive: true, force: true }); });

describe("the people a Team Cloud bot can report to", () => {
  it("are everyone the Admin paired, kept across a restart, by address", () => {
    const at = dir();
    const people = createTeamPeople(at);
    people.seen(" [email protected] ", "admin");
    people.seen("[email protected]", "member");
    expect(createTeamPeople(at).list().map((person) => [person.email, person.role])).toEqual([["[email protected]", "admin"], ["[email protected]", "member"]]);
    expect(people.has("[email protected]")).toBe(true);
    expect(people.has("[email protected]")).toBe(false);
  });

  it("stop offering someone the Admin said left, until they are paired again", () => {
    const at = dir();
    const people = createTeamPeople(at);
    people.seen("[email protected]", "member");
    people.left("[email protected]");
    const reread = createTeamPeople(at);
    expect(reread.list()).toEqual([]);
    expect([reread.has("[email protected]"), reread.gone("[email protected]")]).toEqual([false, true]);
    reread.seen("[email protected]", "member");
    expect([reread.has("[email protected]"), reread.gone("[email protected]")]).toEqual([true, false]);
  });

  it("say who joined, changed role or left, not each pairing", () => {
    const people = createTeamPeople(dir());
    const changes: string[] = [];
    people.onChange((email, change) => changes.push(`${email} ${change}`));
    people.seen("[email protected]", "member");
    people.seen("[email protected]", "member");
    people.seen("[email protected]", "admin");
    people.left("[email protected]");
    people.left("[email protected]");
    people.seen("[email protected]", "admin");
    expect(changes).toEqual(["[email protected] joined", "[email protected] role", "[email protected] left", "[email protected] joined"]);
  });
});