Skip to content

armgit / crm

Public Imported from GitHub
0

Comp AI CRM is an open source, CRM designed for AI agents. Agentic-first CRM.

TypeScript
1.2 KB
Raw Blame
import { describe, expect, it } from "bun:test";
import { notifySignedIn, onSignedIn } from "../src/signed-in";

const USER = { id: "u1", email: "[email protected]" };

describe("the signed-in registry", () => {
	it("hands the user to everything registered", async () => {
		const seen: string[] = [];
		onSignedIn((user) => {
			seen.push(`a:${user.email}`);
		});
		onSignedIn((user) => {
			seen.push(`b:${user.id}`);
		});

		await notifySignedIn(USER);

		expect(seen).toEqual(["a:[email protected]", "b:u1"]);
	});

	it("does not let a failing handler fail the sign-in", async () => {
		const after: string[] = [];
		onSignedIn(() => {
			throw new Error("backfill exploded");
		});
		onSignedIn(() => {
			after.push("still ran");
		});

		await expect(notifySignedIn(USER)).resolves.toBeUndefined();
		expect(after).toEqual(["still ran"]);
	});

	it("waits for handlers in registration order", async () => {
		const order: string[] = [];
		onSignedIn(async () => {
			await new Promise((resolve) => setTimeout(resolve, 5));
			order.push("first");
		});
		onSignedIn(() => {
			order.push("second");
		});

		await notifySignedIn(USER);

		expect(order).toEqual(["first", "second"]);
	});
});