81 lines
2.0 KiB
TypeScript
81 lines
2.0 KiB
TypeScript
import { describe, expect, it } from "vitest"
|
|
|
|
import {
|
|
buildCreateTeamSchema,
|
|
buildUpdateTeamSchema,
|
|
} from "@/schemas/team.schema"
|
|
|
|
const schemaCopy = {
|
|
nameRequired: "El nombre del equipo es obligatorio",
|
|
nameMaxLength: "El nombre del equipo no puede superar los 80 caracteres",
|
|
idRequired: "El ID es obligatorio",
|
|
}
|
|
|
|
describe("team schema", () => {
|
|
it("rejects blank names", () => {
|
|
const result = buildCreateTeamSchema(schemaCopy).safeParse({ name: "" })
|
|
|
|
expect(result.success).toBe(false)
|
|
if (!result.success) {
|
|
expect(result.error.flatten().fieldErrors.name).toContain(
|
|
schemaCopy.nameRequired,
|
|
)
|
|
}
|
|
})
|
|
|
|
it("rejects whitespace-only names", () => {
|
|
const result = buildCreateTeamSchema(schemaCopy).safeParse({ name: " " })
|
|
|
|
expect(result.success).toBe(false)
|
|
if (!result.success) {
|
|
expect(result.error.flatten().fieldErrors.name).toContain(
|
|
schemaCopy.nameRequired,
|
|
)
|
|
}
|
|
})
|
|
|
|
it("rejects names longer than 80 characters", () => {
|
|
const result = buildCreateTeamSchema(schemaCopy).safeParse({
|
|
name: "a".repeat(81),
|
|
})
|
|
|
|
expect(result.success).toBe(false)
|
|
if (!result.success) {
|
|
expect(result.error.flatten().fieldErrors.name).toContain(
|
|
schemaCopy.nameMaxLength,
|
|
)
|
|
}
|
|
})
|
|
|
|
it("accepts valid create input", () => {
|
|
const result = buildCreateTeamSchema(schemaCopy).safeParse({
|
|
name: "Engineering",
|
|
})
|
|
|
|
expect(result.success).toBe(true)
|
|
})
|
|
|
|
it("rejects update with empty id", () => {
|
|
const result = buildUpdateTeamSchema(schemaCopy).safeParse({
|
|
id: "",
|
|
name: "Engineering",
|
|
})
|
|
|
|
expect(result.success).toBe(false)
|
|
if (!result.success) {
|
|
expect(result.error.flatten().fieldErrors.id).toContain(
|
|
schemaCopy.idRequired,
|
|
)
|
|
}
|
|
})
|
|
|
|
it("accepts valid update input", () => {
|
|
const result = buildUpdateTeamSchema(schemaCopy).safeParse({
|
|
id: "some-id",
|
|
name: "Engineering",
|
|
})
|
|
|
|
expect(result.success).toBe(true)
|
|
})
|
|
})
|