refactor: complete i18n rename recipients to people, finalize tests
This commit is contained in:
@@ -5,7 +5,7 @@ import { signInSchema } from "@/schemas/auth.schema"
|
||||
import { createCategorySchema } from "@/schemas/category.schema"
|
||||
import { createItemSchema, updateItemSchema } from "@/schemas/item.schema"
|
||||
import { createMovementSchema } from "@/schemas/movement.schema"
|
||||
import { createRecipientSchema } from "@/schemas/recipient.schema"
|
||||
import { createPersonSchema } from "@/schemas/person.schema"
|
||||
import { createUserSchema, updateUserSchema } from "@/schemas/user.schema"
|
||||
|
||||
describe("core schemas", () => {
|
||||
@@ -120,32 +120,29 @@ describe("core schemas", () => {
|
||||
).toBe(false)
|
||||
})
|
||||
|
||||
it("validates recipient email only when present", () => {
|
||||
it("validates person email only when present", () => {
|
||||
expect(
|
||||
createRecipientSchema.safeParse({
|
||||
username: "recipient",
|
||||
firstName: "Rec",
|
||||
lastName: "Ipient",
|
||||
createPersonSchema.safeParse({
|
||||
firstName: "Per",
|
||||
lastName: "Son",
|
||||
department: "IT",
|
||||
email: "recipient@example.test",
|
||||
email: "person@example.test",
|
||||
}).success,
|
||||
).toBe(true)
|
||||
|
||||
expect(
|
||||
createRecipientSchema.safeParse({
|
||||
username: "recipient",
|
||||
firstName: "Rec",
|
||||
lastName: "Ipient",
|
||||
createPersonSchema.safeParse({
|
||||
firstName: "Per",
|
||||
lastName: "Son",
|
||||
department: "IT",
|
||||
email: "not-an-email",
|
||||
}).success,
|
||||
).toBe(false)
|
||||
|
||||
expect(
|
||||
createRecipientSchema.safeParse({
|
||||
username: "recipient",
|
||||
firstName: "Rec",
|
||||
lastName: "Ipient",
|
||||
createPersonSchema.safeParse({
|
||||
firstName: "Per",
|
||||
lastName: "Son",
|
||||
department: "IT",
|
||||
email: "",
|
||||
}).success,
|
||||
|
||||
+42
-16
@@ -1,23 +1,22 @@
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
import {
|
||||
buildCreateRecipientSchema,
|
||||
buildUpdateRecipientSchema,
|
||||
} from "@/schemas/recipient.schema"
|
||||
buildCreatePersonSchema,
|
||||
buildUpdatePersonSchema,
|
||||
} from "@/schemas/person.schema"
|
||||
|
||||
const schemaCopy = {
|
||||
usernameRequired: "El usuario es obligatorio",
|
||||
firstNameRequired: "El nombre es obligatorio",
|
||||
lastNameRequired: "El apellido es obligatorio",
|
||||
departmentRequired: "El departamento es obligatorio",
|
||||
emailInvalid: "El correo electrónico no es válido",
|
||||
idRequired: "El ID es obligatorio",
|
||||
userIdInvalid: "El ID de usuario debe ser un UUID válido",
|
||||
}
|
||||
|
||||
describe("recipient schema localization", () => {
|
||||
it("uses localized required-field validation messages for create", () => {
|
||||
const result = buildCreateRecipientSchema(schemaCopy).safeParse({
|
||||
username: "",
|
||||
describe("person schema validation", () => {
|
||||
it("uses localized required-field validation messages for create (no username)", () => {
|
||||
const result = buildCreatePersonSchema(schemaCopy).safeParse({
|
||||
firstName: "",
|
||||
lastName: "",
|
||||
department: "",
|
||||
@@ -27,7 +26,6 @@ describe("recipient schema localization", () => {
|
||||
if (!result.success) {
|
||||
const errors = result.error.flatten().fieldErrors
|
||||
|
||||
expect(errors.username).toContain(schemaCopy.usernameRequired)
|
||||
expect(errors.firstName).toContain(schemaCopy.firstNameRequired)
|
||||
expect(errors.lastName).toContain(schemaCopy.lastNameRequired)
|
||||
expect(errors.department).toContain(schemaCopy.departmentRequired)
|
||||
@@ -35,8 +33,7 @@ describe("recipient schema localization", () => {
|
||||
})
|
||||
|
||||
it("uses a localized invalid email message for create", () => {
|
||||
const result = buildCreateRecipientSchema(schemaCopy).safeParse({
|
||||
username: "ada",
|
||||
const result = buildCreatePersonSchema(schemaCopy).safeParse({
|
||||
firstName: "Ada",
|
||||
lastName: "Lovelace",
|
||||
department: "ENGINEERING",
|
||||
@@ -51,10 +48,25 @@ describe("recipient schema localization", () => {
|
||||
}
|
||||
})
|
||||
|
||||
it("uses a localized invalid userId message for create with non-UUID", () => {
|
||||
const result = buildCreatePersonSchema(schemaCopy).safeParse({
|
||||
firstName: "Ada",
|
||||
lastName: "Lovelace",
|
||||
department: "ENGINEERING",
|
||||
userId: "not-a-uuid",
|
||||
})
|
||||
|
||||
expect(result.success).toBe(false)
|
||||
if (!result.success) {
|
||||
expect(result.error.flatten().fieldErrors.userId).toContain(
|
||||
schemaCopy.userIdInvalid,
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it("uses localized update identifier validation messages", () => {
|
||||
const result = buildUpdateRecipientSchema(schemaCopy).safeParse({
|
||||
const result = buildUpdatePersonSchema(schemaCopy).safeParse({
|
||||
id: "",
|
||||
username: "ada",
|
||||
firstName: "Ada",
|
||||
lastName: "Lovelace",
|
||||
department: "ENGINEERING",
|
||||
@@ -69,19 +81,33 @@ describe("recipient schema localization", () => {
|
||||
}
|
||||
})
|
||||
|
||||
it("preserves canonical department values and optional empty email semantics", () => {
|
||||
const result = buildCreateRecipientSchema(schemaCopy).safeParse({
|
||||
username: "ada",
|
||||
it("preserves canonical department values and accepts optional userId UUID", () => {
|
||||
const result = buildCreatePersonSchema(schemaCopy).safeParse({
|
||||
firstName: "Ada",
|
||||
lastName: "Lovelace",
|
||||
department: "ENGINEERING",
|
||||
email: "",
|
||||
userId: "550e8400-e29b-41d4-a716-446655440000",
|
||||
})
|
||||
|
||||
expect(result.success).toBe(true)
|
||||
if (result.success) {
|
||||
expect(result.data.department).toBe("ENGINEERING")
|
||||
expect(result.data.email).toBe("")
|
||||
expect(result.data.userId).toBe("550e8400-e29b-41d4-a716-446655440000")
|
||||
}
|
||||
})
|
||||
|
||||
it("accepts create without username field (removed from schema)", () => {
|
||||
const result = buildCreatePersonSchema(schemaCopy).safeParse({
|
||||
firstName: "Ada",
|
||||
lastName: "Lovelace",
|
||||
department: "ENGINEERING",
|
||||
})
|
||||
|
||||
expect(result.success).toBe(true)
|
||||
if (result.success) {
|
||||
expect("username" in result.data).toBe(false)
|
||||
}
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user