zerobyte/app/server/lib/__tests__/username.test.ts
Nico dda7b9939f
Some checks failed
Release Workflow / determine-release-type (push) Has been cancelled
Release Workflow / checks (push) Has been cancelled
Release Workflow / e2e-tests (push) Has been cancelled
Release Workflow / build-images (push) Has been cancelled
Release Workflow / publish-release (push) Has been cancelled
refactor: allow more characters in usernames (#529)
2026-02-16 21:37:15 +01:00

21 lines
732 B
TypeScript

import { describe, expect, test } from "bun:test";
import { isValidUsername, normalizeUsername } from "~/lib/username";
describe("username helpers", () => {
test("normalizes usernames by trimming and lowercasing", () => {
expect(normalizeUsername(" Admin-User ")).toBe("admin-user");
});
test("accepts usernames containing a hyphen", () => {
expect(isValidUsername(normalizeUsername("Admin-User"))).toBe(true);
});
test("accepts letters, numbers, dots, and underscores", () => {
expect(isValidUsername("admin.user_01")).toBe(true);
});
test("rejects usernames with unsupported characters", () => {
expect(isValidUsername("admin user")).toBe(false);
expect(isValidUsername("admin@user")).toBe(false);
});
});