import { describe, expect, it } from "vitest";
import { generateUuid, uuidV4Fallback } from "./uuid";

const UUID_V4 = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;

describe("generateUuid", () => {
  it("возвращает валидный UUID v4", () => {
    expect(generateUuid()).toMatch(UUID_V4);
  });
});

describe("uuidV4Fallback (insecure context)", () => {
  it("даёт валидный UUID v4 без crypto.randomUUID", () => {
    expect(uuidV4Fallback()).toMatch(UUID_V4);
  });

  it("генерирует разные значения", () => {
    expect(uuidV4Fallback()).not.toBe(uuidV4Fallback());
  });
});
