test(people): update tests for teamId and add people e2e spec
This commit is contained in:
@@ -125,7 +125,7 @@ describe("core schemas", () => {
|
||||
createPersonSchema.safeParse({
|
||||
firstName: "Per",
|
||||
lastName: "Son",
|
||||
department: "IT",
|
||||
teamId: null,
|
||||
email: "person@example.test",
|
||||
}).success,
|
||||
).toBe(true)
|
||||
@@ -134,7 +134,7 @@ describe("core schemas", () => {
|
||||
createPersonSchema.safeParse({
|
||||
firstName: "Per",
|
||||
lastName: "Son",
|
||||
department: "IT",
|
||||
teamId: null,
|
||||
email: "not-an-email",
|
||||
}).success,
|
||||
).toBe(false)
|
||||
@@ -143,7 +143,7 @@ describe("core schemas", () => {
|
||||
createPersonSchema.safeParse({
|
||||
firstName: "Per",
|
||||
lastName: "Son",
|
||||
department: "IT",
|
||||
teamId: null,
|
||||
email: "",
|
||||
}).success,
|
||||
).toBe(true)
|
||||
|
||||
@@ -8,18 +8,20 @@ import {
|
||||
const schemaCopy = {
|
||||
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",
|
||||
teamIdInvalid: "El equipo debe ser un id válido",
|
||||
}
|
||||
|
||||
const validTeamId = "550e8400-e29b-41d4-a716-446655440000"
|
||||
|
||||
describe("person schema validation", () => {
|
||||
it("uses localized required-field validation messages for create (no username)", () => {
|
||||
const result = buildCreatePersonSchema(schemaCopy).safeParse({
|
||||
firstName: "",
|
||||
lastName: "",
|
||||
department: "",
|
||||
teamId: null,
|
||||
})
|
||||
|
||||
expect(result.success).toBe(false)
|
||||
@@ -28,7 +30,6 @@ describe("person schema validation", () => {
|
||||
|
||||
expect(errors.firstName).toContain(schemaCopy.firstNameRequired)
|
||||
expect(errors.lastName).toContain(schemaCopy.lastNameRequired)
|
||||
expect(errors.department).toContain(schemaCopy.departmentRequired)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -36,7 +37,7 @@ describe("person schema validation", () => {
|
||||
const result = buildCreatePersonSchema(schemaCopy).safeParse({
|
||||
firstName: "Ada",
|
||||
lastName: "Lovelace",
|
||||
department: "ENGINEERING",
|
||||
teamId: null,
|
||||
email: "not-an-email",
|
||||
})
|
||||
|
||||
@@ -52,7 +53,7 @@ describe("person schema validation", () => {
|
||||
const result = buildCreatePersonSchema(schemaCopy).safeParse({
|
||||
firstName: "Ada",
|
||||
lastName: "Lovelace",
|
||||
department: "ENGINEERING",
|
||||
teamId: null,
|
||||
userId: "not-a-uuid",
|
||||
})
|
||||
|
||||
@@ -64,12 +65,27 @@ describe("person schema validation", () => {
|
||||
}
|
||||
})
|
||||
|
||||
it("rejects an invalid teamId", () => {
|
||||
const result = buildCreatePersonSchema(schemaCopy).safeParse({
|
||||
firstName: "Ada",
|
||||
lastName: "Lovelace",
|
||||
teamId: "not-a-uuid",
|
||||
})
|
||||
|
||||
expect(result.success).toBe(false)
|
||||
if (!result.success) {
|
||||
expect(result.error.flatten().fieldErrors.teamId).toContain(
|
||||
schemaCopy.teamIdInvalid,
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it("uses localized update identifier validation messages", () => {
|
||||
const result = buildUpdatePersonSchema(schemaCopy).safeParse({
|
||||
id: "",
|
||||
firstName: "Ada",
|
||||
lastName: "Lovelace",
|
||||
department: "ENGINEERING",
|
||||
teamId: null,
|
||||
email: "ada@example.test",
|
||||
})
|
||||
|
||||
@@ -81,20 +97,20 @@ describe("person schema validation", () => {
|
||||
}
|
||||
})
|
||||
|
||||
it("preserves canonical department values and accepts optional userId UUID", () => {
|
||||
it("accepts a valid teamId UUID and optional userId UUID", () => {
|
||||
const result = buildCreatePersonSchema(schemaCopy).safeParse({
|
||||
firstName: "Ada",
|
||||
lastName: "Lovelace",
|
||||
department: "ENGINEERING",
|
||||
teamId: validTeamId,
|
||||
email: "",
|
||||
userId: "550e8400-e29b-41d4-a716-446655440000",
|
||||
userId: validTeamId,
|
||||
})
|
||||
|
||||
expect(result.success).toBe(true)
|
||||
if (result.success) {
|
||||
expect(result.data.department).toBe("ENGINEERING")
|
||||
expect(result.data.teamId).toBe(validTeamId)
|
||||
expect(result.data.email).toBe("")
|
||||
expect(result.data.userId).toBe("550e8400-e29b-41d4-a716-446655440000")
|
||||
expect(result.data.userId).toBe(validTeamId)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -102,7 +118,7 @@ describe("person schema validation", () => {
|
||||
const result = buildCreatePersonSchema(schemaCopy).safeParse({
|
||||
firstName: "Ada",
|
||||
lastName: "Lovelace",
|
||||
department: "ENGINEERING",
|
||||
teamId: null,
|
||||
})
|
||||
|
||||
expect(result.success).toBe(true)
|
||||
|
||||
@@ -6,34 +6,36 @@ import {
|
||||
unifiedFormRoleSchema,
|
||||
} from "@/schemas/user.schema"
|
||||
|
||||
const validTeamId = "550e8400-e29b-41d4-a716-446655440000"
|
||||
|
||||
const enCopy: UnifiedSchemaCopy = {
|
||||
firstNameRequired: "First name is required",
|
||||
lastNameRequired: "Last name is required",
|
||||
departmentRequired: "Department is required",
|
||||
emailInvalid: "Invalid email",
|
||||
passwordMinLength: "Password must be at least 8 characters",
|
||||
nameRequired: "Name is required",
|
||||
userIdRequired: "User id is required",
|
||||
idRequired: "ID is required",
|
||||
userIdInvalid: "User ID must be a valid UUID",
|
||||
teamIdInvalid: "Team must be a valid id",
|
||||
}
|
||||
|
||||
const esCopy: UnifiedSchemaCopy = {
|
||||
firstNameRequired: "El nombre es obligatorio",
|
||||
lastNameRequired: "El apellido es obligatorio",
|
||||
departmentRequired: "El departamento es obligatorio",
|
||||
emailInvalid: "Correo electrónico no válido",
|
||||
passwordMinLength: "La contraseña debe tener al menos 8 caracteres",
|
||||
nameRequired: "El nombre es obligatorio",
|
||||
userIdRequired: "El ID de usuario es obligatorio",
|
||||
idRequired: "El ID es obligatorio",
|
||||
userIdInvalid: "El ID de usuario debe ser un UUID válido",
|
||||
teamIdInvalid: "El equipo debe ser un id válido",
|
||||
}
|
||||
|
||||
const validPersonOnlyData = {
|
||||
firstName: "John",
|
||||
lastName: "Doe",
|
||||
department: "IT",
|
||||
teamId: null,
|
||||
email: "john@example.test",
|
||||
phone: null,
|
||||
role: "NO_USER" as const,
|
||||
@@ -44,7 +46,7 @@ const validPersonOnlyData = {
|
||||
const validPersonWithUserData = {
|
||||
firstName: "Jane",
|
||||
lastName: "Smith",
|
||||
department: "ENGINEERING",
|
||||
teamId: validTeamId,
|
||||
email: "jane@example.test",
|
||||
phone: "1234567890",
|
||||
role: "ADMIN" as const,
|
||||
@@ -96,7 +98,7 @@ describe("buildUnifiedCreateSchema", () => {
|
||||
const result = schema.safeParse({
|
||||
firstName: "",
|
||||
lastName: "",
|
||||
department: "",
|
||||
teamId: "not-a-uuid",
|
||||
email: "not-an-email",
|
||||
role: "NO_USER",
|
||||
phone: null,
|
||||
@@ -108,7 +110,7 @@ describe("buildUnifiedCreateSchema", () => {
|
||||
const errors = result.error.flatten().fieldErrors
|
||||
expect(errors.firstName).toContain(esCopy.firstNameRequired)
|
||||
expect(errors.lastName).toContain(esCopy.lastNameRequired)
|
||||
expect(errors.department).toContain(esCopy.departmentRequired)
|
||||
expect(errors.teamId).toContain(esCopy.teamIdInvalid)
|
||||
expect(errors.email).toContain(esCopy.emailInvalid)
|
||||
}
|
||||
})
|
||||
@@ -185,7 +187,7 @@ describe("buildUnifiedCreateSchema", () => {
|
||||
const result = schema.safeParse({
|
||||
firstName: "Jane",
|
||||
lastName: "Smith",
|
||||
department: "ENGINEERING",
|
||||
teamId: validTeamId,
|
||||
email: "jane@example.test",
|
||||
role: "ADMIN",
|
||||
password: "corta",
|
||||
@@ -228,36 +230,35 @@ describe("buildUnifiedCreateSchema", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("department validation", () => {
|
||||
it("rejects invalid department", () => {
|
||||
describe("teamId validation", () => {
|
||||
it("rejects invalid teamId", () => {
|
||||
const schema = buildUnifiedCreateSchema(enCopy)
|
||||
const result = schema.safeParse({
|
||||
...validPersonOnlyData,
|
||||
department: "INVALID_DEPT",
|
||||
teamId: "INVALID_TEAM",
|
||||
})
|
||||
|
||||
expect(result.success).toBe(false)
|
||||
})
|
||||
|
||||
it("accepts valid departments", () => {
|
||||
it("accepts null teamId", () => {
|
||||
const schema = buildUnifiedCreateSchema(enCopy)
|
||||
const validDepartments = [
|
||||
"IT",
|
||||
"ENGINEERING",
|
||||
"TRAFFIC",
|
||||
"DRIVER",
|
||||
"LOGISTICS",
|
||||
"ADMINISTRATION",
|
||||
"SALES",
|
||||
"OTHER",
|
||||
]
|
||||
for (const dept of validDepartments) {
|
||||
const result = schema.safeParse({
|
||||
...validPersonOnlyData,
|
||||
department: dept,
|
||||
})
|
||||
expect(result.success).toBe(true)
|
||||
}
|
||||
const result = schema.safeParse({
|
||||
...validPersonOnlyData,
|
||||
teamId: null,
|
||||
})
|
||||
|
||||
expect(result.success).toBe(true)
|
||||
})
|
||||
|
||||
it("accepts a valid teamId UUID", () => {
|
||||
const schema = buildUnifiedCreateSchema(enCopy)
|
||||
const result = schema.safeParse({
|
||||
...validPersonOnlyData,
|
||||
teamId: validTeamId,
|
||||
})
|
||||
|
||||
expect(result.success).toBe(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -5,35 +5,37 @@ import {
|
||||
type UnifiedSchemaCopy,
|
||||
} from "@/schemas/user.schema"
|
||||
|
||||
const validTeamId = "550e8400-e29b-41d4-a716-446655440000"
|
||||
|
||||
const enCopy: UnifiedSchemaCopy = {
|
||||
firstNameRequired: "First name is required",
|
||||
lastNameRequired: "Last name is required",
|
||||
departmentRequired: "Department is required",
|
||||
emailInvalid: "Invalid email",
|
||||
passwordMinLength: "Password must be at least 8 characters",
|
||||
nameRequired: "Name is required",
|
||||
userIdRequired: "User id is required",
|
||||
idRequired: "ID is required",
|
||||
userIdInvalid: "User ID must be a valid UUID",
|
||||
teamIdInvalid: "Team must be a valid id",
|
||||
}
|
||||
|
||||
const esCopy: UnifiedSchemaCopy = {
|
||||
firstNameRequired: "El nombre es obligatorio",
|
||||
lastNameRequired: "El apellido es obligatorio",
|
||||
departmentRequired: "El departamento es obligatorio",
|
||||
emailInvalid: "Correo electrónico no válido",
|
||||
passwordMinLength: "La contraseña debe tener al menos 8 caracteres",
|
||||
nameRequired: "El nombre es obligatorio",
|
||||
userIdRequired: "El ID de usuario es obligatorio",
|
||||
idRequired: "El ID es obligatorio",
|
||||
userIdInvalid: "El ID de usuario debe ser un UUID válido",
|
||||
teamIdInvalid: "El equipo debe ser un id válido",
|
||||
}
|
||||
|
||||
const validPersonOnly = {
|
||||
id: "person-1",
|
||||
firstName: "John",
|
||||
lastName: "Doe",
|
||||
department: "IT",
|
||||
teamId: null,
|
||||
email: "john@example.test",
|
||||
phone: null,
|
||||
}
|
||||
@@ -73,7 +75,7 @@ describe("buildUnifiedUpdateSchema", () => {
|
||||
id: "",
|
||||
firstName: "John",
|
||||
lastName: "Doe",
|
||||
department: "IT",
|
||||
teamId: null,
|
||||
email: "john@example.test",
|
||||
phone: null,
|
||||
})
|
||||
@@ -85,6 +87,31 @@ describe("buildUnifiedUpdateSchema", () => {
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it("rejects invalid teamId", () => {
|
||||
const schema = buildUnifiedUpdateSchema(enCopy)
|
||||
const result = schema.safeParse({
|
||||
...validPersonOnly,
|
||||
teamId: "not-a-uuid",
|
||||
})
|
||||
|
||||
expect(result.success).toBe(false)
|
||||
if (!result.success) {
|
||||
expect(result.error.flatten().fieldErrors.teamId).toContain(
|
||||
enCopy.teamIdInvalid,
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it("accepts a valid teamId UUID", () => {
|
||||
const schema = buildUnifiedUpdateSchema(enCopy)
|
||||
const result = schema.safeParse({
|
||||
...validPersonOnly,
|
||||
teamId: validTeamId,
|
||||
})
|
||||
|
||||
expect(result.success).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe("person+user update (when person has User linked)", () => {
|
||||
|
||||
Reference in New Issue
Block a user