feat(teams): add Team entity and cutover Person.department to Person.teamId

Co-authored-by: Asis Ferrer <aferrer@aferrer.dev>
Co-committed-by: Asis Ferrer <aferrer@aferrer.dev>
This commit was merged in pull request #5.
This commit is contained in:
2026-06-26 00:29:09 +00:00
committed by Asis ferrer
parent cd38621f8b
commit 428dd0482d
52 changed files with 836 additions and 488 deletions
+8 -5
View File
@@ -25,6 +25,8 @@ vi.mock("@/use-cases/person.use-cases", () => ({
import { createNewPerson, updatePerson } from "@/actions/person.actions"
const validTeamId = "550e8400-e29b-41d4-a716-446655440000"
describe("person actions localization", () => {
beforeEach(() => {
vi.clearAllMocks()
@@ -35,7 +37,7 @@ describe("person actions localization", () => {
const result = await createNewPerson({
firstName: "",
lastName: "",
department: "",
teamId: "not-a-uuid",
email: "not-an-email",
} as unknown as Parameters<typeof createNewPerson>[0])
@@ -46,7 +48,8 @@ describe("person actions localization", () => {
errors: {
firstName: [es.inventory.people.schema.firstNameRequired],
lastName: [es.inventory.people.schema.lastNameRequired],
department: [es.inventory.people.schema.departmentRequired],
teamId: [es.inventory.people.schema.teamIdInvalid],
email: [es.inventory.people.schema.emailInvalid],
},
})
})
@@ -62,7 +65,7 @@ describe("person actions localization", () => {
const result = await createNewPerson({
firstName: "Ada",
lastName: "Lovelace",
department: "ENGINEERING",
teamId: validTeamId,
email: "ada@example.test",
})
@@ -83,7 +86,7 @@ describe("person actions localization", () => {
id: "person-1",
firstName: "Ada",
lastName: "Lovelace",
department: "ENGINEERING",
teamId: validTeamId,
email: "ada@example.test",
})
@@ -98,7 +101,7 @@ describe("person actions localization", () => {
const result = await createNewPerson({
firstName: "Ada",
lastName: "Lovelace",
department: "ENGINEERING",
teamId: null,
userId: "not-a-uuid",
} as unknown as Parameters<typeof createNewPerson>[0])
@@ -9,6 +9,7 @@ const actionCopy = {
updateFailure: "Error al actualizar la persona",
duplicateEmail: "El correo electrónico ya existe",
notFound: "Persona no encontrada",
teamNotFound: "Equipo no encontrado",
}
describe("person action message localization", () => {
@@ -25,6 +26,19 @@ describe("person action message localization", () => {
})
})
it("localizes team not found errors", () => {
expect(
localizePersonFieldErrors(
{
teamId: ["Team not found"],
},
actionCopy,
),
).toEqual({
teamId: [actionCopy.teamNotFound],
})
})
it("keeps unknown messages unchanged", () => {
expect(
localizePersonFieldErrors(
@@ -28,6 +28,8 @@ vi.mock("@/use-cases/person.use-cases", () => ({
import { updatePersonUserAction } from "@/actions/person.actions"
const validTeamId = "550e8400-e29b-41d4-a716-446655440000"
describe("updatePersonUserAction", () => {
beforeEach(() => {
vi.clearAllMocks()
@@ -41,7 +43,7 @@ describe("updatePersonUserAction", () => {
id: "",
firstName: "Ada",
lastName: "Lovelace",
department: "ENGINEERING",
teamId: validTeamId,
email: "ada@example.test",
phone: null,
})
@@ -60,7 +62,7 @@ describe("updatePersonUserAction", () => {
id: "person-1",
firstName: "Ada",
lastName: "Lovelace",
department: "ENGINEERING",
teamId: validTeamId,
email: "not-an-email",
phone: null,
})
@@ -74,12 +76,31 @@ describe("updatePersonUserAction", () => {
expect(mocks.updatePersonUserUseCase).not.toHaveBeenCalled()
})
it("rejects invalid teamId with localized teamIdInvalid error", async () => {
const result = await updatePersonUserAction({
id: "person-1",
firstName: "Ada",
lastName: "Lovelace",
teamId: "not-a-uuid",
email: "ada@example.test",
phone: null,
})
expect(result).toEqual({
success: false,
errors: {
teamId: [es.inventory.people.schema.teamIdInvalid],
},
})
expect(mocks.updatePersonUserUseCase).not.toHaveBeenCalled()
})
it("rejects short password when role is provided", async () => {
const result = await updatePersonUserAction({
id: "person-1",
firstName: "Ada",
lastName: "Lovelace",
department: "ENGINEERING",
teamId: validTeamId,
email: "ada@example.test",
phone: null,
role: "ADMIN",
@@ -101,7 +122,7 @@ describe("updatePersonUserAction", () => {
id: "person-1",
firstName: "Ada",
lastName: "Lovelace",
department: "ENGINEERING",
teamId: validTeamId,
email: "ada@example.test",
phone: null,
role: "NO_USER" as unknown as "ADMIN",
@@ -117,7 +138,7 @@ describe("updatePersonUserAction", () => {
id: "person-1",
firstName: "Ada",
lastName: "Lovelace",
department: "ENGINEERING",
teamId: validTeamId,
email: "ada@example.test",
phone: null,
role: "SUPER_ADMIN" as unknown as "ADMIN",
@@ -140,7 +161,7 @@ describe("updatePersonUserAction", () => {
id: "person-1",
firstName: "Ada",
lastName: "Lovelace",
department: "ENGINEERING",
teamId: validTeamId,
email: "duplicate@example.test",
phone: null,
})
@@ -164,7 +185,7 @@ describe("updatePersonUserAction", () => {
id: "missing",
firstName: "Ada",
lastName: "Lovelace",
department: "ENGINEERING",
teamId: validTeamId,
email: "ada@example.test",
phone: null,
})
@@ -184,7 +205,7 @@ describe("updatePersonUserAction", () => {
id: "person-1",
firstName: "Ada",
lastName: "Lovelace",
department: "ENGINEERING",
teamId: validTeamId,
email: "ada@example.test",
phone: null,
})
@@ -204,7 +225,7 @@ describe("updatePersonUserAction", () => {
id: "person-1",
firstName: "Ada",
lastName: "Lovelace",
department: "ENGINEERING",
teamId: validTeamId,
email: "ada@example.test",
phone: null,
})