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

vi.mock("next/headers", () => ({
  headers: vi.fn(),
}));

import { headers } from "next/headers";
import { getNonce } from "@/security/next/get-nonce";

describe("getNonce", () => {
  it("reads x-nonce from the request headers provided by next/headers", async () => {
    vi.mocked(headers).mockResolvedValue({
      get: (k: string) => (k === "x-nonce" ? "test-nonce-value" : null),
    } as unknown as Awaited<ReturnType<typeof headers>>);

    expect(await getNonce()).toBe("test-nonce-value");
  });

  it("returns empty string when x-nonce header is absent", async () => {
    vi.mocked(headers).mockResolvedValue({
      get: () => null,
    } as unknown as Awaited<ReturnType<typeof headers>>);

    expect(await getNonce()).toBe("");
  });
});
