import { expect, test } from "bun:test";
import { publicKeyCreationOptions, publicKeyRequestOptions } from "../src/passkeys/index.ts";

test("passkey option conversion accepts canonical Base64URL values", () => {
  const creation = publicKeyCreationOptions({
    challenge: "AQID",
    rp: { id: "example.test", name: "Example" },
    user: { id: "BAUG", name: "user", displayName: "User" },
    timeout: 60_000,
    attestation: "none",
  });
  expect(Array.from(creation.challenge as Uint8Array)).toEqual([1, 2, 3]);

  const request = publicKeyRequestOptions({
    challenge: "BAUG",
    rpId: "example.test",
    timeout: 60_000,
    userVerification: "preferred",
  });
  expect(Array.from(request.challenge as Uint8Array)).toEqual([4, 5, 6]);
});

test("passkey option conversion rejects malformed Base64URL values", () => {
  expect(() =>
    publicKeyRequestOptions({
      challenge: "AQID=",
      rpId: "example.test",
      timeout: 60_000,
      userVerification: "required",
    }),
  ).toThrow("canonical Base64URL");
});
