import {
BranchProtectionSchema,
CreateIssueSchema,
CreatePullRequestSchema,
CreateRepositorySchema,
GeneralConfigSchema,
RegisterUserSchema,
StorageConfigSchema,
WebhookConfigSchema,
} from "@/lib/validation";
import { describe, expect, it } from "vitest";
describe("RegisterUserSchema", () => {
it("accepts a valid registration", () => {
const result = RegisterUserSchema.safeParse({
username: "testuser",
email: "test@example.com",
password: "StrongP@ss123",
displayName: "Test User",
});
expect(result.success).toBe(true);
});
it("rejects missing username", () => {
const result = RegisterUserSchema.safeParse({
email: "test@example.com",
password: "StrongP@ss123",
});
expect(result.success).toBe(false);
});
it("rejects invalid email", () => {
const result = RegisterUserSchema.safeParse({
username: "testuser",
email: "notanemail",
password: "StrongP@ss123",
});
expect(result.success).toBe(false);
});
it("rejects short password", () => {
const result = RegisterUserSchema.safeParse({
username: "testuser",
email: "test@example.com",
password: "abc",
});
expect(result.success).toBe(false);
});
it("rejects empty username", () => {
const result = RegisterUserSchema.safeParse({
username: "",
email: "test@example.com",
password: "StrongP@ss123",
});
expect(result.success).toBe(false);
});
});
describe("CreateRepositorySchema", () => {
it("accepts minimal valid repo", () => {
const result = CreateRepositorySchema.safeParse({
name: "my-repo",
});
expect(result.success).toBe(true);
});
it("accepts full valid repo", () => {
const result = CreateRepositorySchema.safeParse({
name: "my-repo",
description: "A test repository",
visibility: "public",
defaultBranch: "main",
});
expect(result.success).toBe(true);
});
it("rejects missing name", () => {
const result = CreateRepositorySchema.safeParse({
description: "A test repository",
});
expect(result.success).toBe(false);
});
it("rejects empty name", () => {
const result = CreateRepositorySchema.safeParse({ name: "" });
expect(result.success).toBe(false);
});
it("rejects invalid visibility", () => {
const result = CreateRepositorySchema.safeParse({
name: "my-repo",
visibility: "invalid-mode",
});
expect(result.success).toBe(false);
});
});
describe("CreateIssueSchema", () => {
it("accepts a valid issue", () => {
const result = CreateIssueSchema.safeParse({
title: "Bug report",
body: "Something is broken",
});
expect(result.success).toBe(true);
});
it("rejects empty title", () => {
const result = CreateIssueSchema.safeParse({
title: "",
body: "Something is broken",
});
expect(result.success).toBe(false);
});
it("rejects missing title", () => {
const result = CreateIssueSchema.safeParse({
body: "Something is broken",
});
expect(result.success).toBe(false);
});
it("sanitizes HTML in body", () => {
const result = CreateIssueSchema.safeParse({
title: "XSS test",
body: 'normal text',
});
expect(result.success).toBe(true);
if (result.success) {
expect(result.data.body).not.toContain("