import { beforeEach, describe, expect, it, vi } from "vitest";

const init = vi.fn();

vi.mock("@datadog/browser-rum", () => ({
  datadogRum: {
    init,
  },
}));

vi.mock("@datadog/browser-rum-react", () => ({
  reactPlugin: () => "react-plugin",
}));

describe("rum config", () => {
  beforeEach(() => {
    init.mockReset();
    vi.resetModules();
  });

  it("sets the Datadog release version from VITE_APP_VERSION", async () => {
    vi.stubEnv("VITE_APP_VERSION", "test-sha");
    vi.stubEnv("MODE", "production");

    await import("./rum");

    expect(init).toHaveBeenCalledWith(
      expect.objectContaining({
        service: "xtablo-ui",
        env: "production",
        version: "test-sha",
      })
    );
  });
});
