Skip to content

Open-source status page, incident response and uptime monitoring

1.1 KB
Raw Blame
import { describe, expect, test } from "vitest";

import { toAgentUser, toAttributedUserDetail } from "../attribution";

const row = {
  id: 7,
  name: null,
  firstName: "Ada",
  lastName: "Lovelace",
  email: "[email protected]",
  photoUrl: "",
};

describe("attribution projections", () => {
  test("detail carries email and normalizes an empty photo to null", () => {
    expect(toAttributedUserDetail(row)).toEqual({
      id: 7,
      name: "Ada Lovelace",
      email: "[email protected]",
      photoUrl: null,
    });
  });

  test("soft-deleted user exposes no contact details", () => {
    expect(toAttributedUserDetail({ ...row, deletedAt: new Date() })).toEqual({
      id: 7,
      name: "Deleted user",
      email: null,
      photoUrl: null,
    });
  });

  test("agent projection drops email and photo", () => {
    const detail = toAttributedUserDetail({
      ...row,
      photoUrl: "https://example.com/ada.png",
    });
    expect(detail?.photoUrl).toBe("https://example.com/ada.png");
    expect(toAgentUser(detail)).toEqual({ id: 7, name: "Ada Lovelace" });
    expect(toAgentUser(null)).toBeNull();
  });
});