import { describe, expect, it } from "vitest";
import { NoopAnalytics } from "@/noop-analytics";

describe("NoopAnalytics", () => {
  it("track() does not throw with event name only", () => {
    const analytics = new NoopAnalytics();
    expect(() => analytics.track("page_viewed")).not.toThrow();
  });

  it("track() does not throw with event name and attributes", () => {
    const analytics = new NoopAnalytics();
    expect(() =>
      analytics.track("button_clicked", {
        label: "signup",
        count: 1,
        active: true,
      }),
    ).not.toThrow();
  });

  it("identify() does not throw with user only", () => {
    const analytics = new NoopAnalytics();
    expect(() => analytics.identify({ id: "user-123" })).not.toThrow();
  });

  it("identify() does not throw with user and attributes", () => {
    const analytics = new NoopAnalytics();
    expect(() =>
      analytics.identify({ id: "user-123" }, { plan: "pro", trial: false }),
    ).not.toThrow();
  });

  it("pageView() does not throw with path only", () => {
    const analytics = new NoopAnalytics();
    expect(() => analytics.pageView("/dashboard")).not.toThrow();
  });

  it("pageView() does not throw with path and attributes", () => {
    const analytics = new NoopAnalytics();
    expect(() =>
      analytics.pageView("/dashboard", { referrer: "/home", duration: 120 }),
    ).not.toThrow();
  });

  it("flush() resolves without throwing", async () => {
    const analytics = new NoopAnalytics();
    await expect(analytics.flush()).resolves.toBeUndefined();
  });

  it("flush() returns a Promise", () => {
    const analytics = new NoopAnalytics();
    expect(analytics.flush()).toBeInstanceOf(Promise);
  });
});
