import { describe, expect, test } from "bun:test";
import { isValidUsername } from "./username-policy";

describe("username-policy", () => {
  test("accepts alphanumeric, underscore and dot handles", () => {
    expect(isValidUsername("bastien")).toBe(true);
    expect(isValidUsername("bastien_99")).toBe(true);
    expect(isValidUsername("eleva.seo")).toBe(true);
    expect(isValidUsername("ABC")).toBe(true);
  });

  test("rejects disallowed characters (mirrors plugin default regex)", () => {
    expect(isValidUsername("with space")).toBe(false);
    expect(isValidUsername("dash-handle")).toBe(false);
    expect(isValidUsername("with@at")).toBe(false);
    expect(isValidUsername("é")).toBe(false);
    expect(isValidUsername("")).toBe(false);
  });

  test("rejects reserved handles case-insensitively", () => {
    expect(isValidUsername("admin")).toBe(false);
    expect(isValidUsername("Admin")).toBe(false);
    expect(isValidUsername("ROOT")).toBe(false);
    expect(isValidUsername("support")).toBe(false);
    expect(isValidUsername("seoinsight")).toBe(false);
  });
});
