From c961f5292dbf3bf1173ee535ce6e7c1129fdbbbb Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 22 Jul 2026 10:05:36 -0700 Subject: [PATCH] fix signature, add tests --- server/src/domain/users/user.service.ts | 4 ++-- .../unit/validation/userValidation.test.ts | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/server/src/domain/users/user.service.ts b/server/src/domain/users/user.service.ts index 7bdb9677f..78a884a51 100644 --- a/server/src/domain/users/user.service.ts +++ b/server/src/domain/users/user.service.ts @@ -24,7 +24,7 @@ export interface IUserService { createUser(userData: Partial, teamId: string, actorRoles: UserRole[], file: Express.Multer.File | null): Promise; loginUser(email: string, password: string): Promise<{ user: User; token: string }>; editUser( - updates: Partial, + updates: Partial, file: Express.Multer.File | null, currentUserId: string, currentUserEmail: string @@ -242,7 +242,7 @@ export class UserService implements IUserService { }; editUser = async ( - updates: Partial, + updates: Partial, file: Express.Multer.File | null, currentUserId: string, currentUserEmail: string diff --git a/server/test/unit/validation/userValidation.test.ts b/server/test/unit/validation/userValidation.test.ts index c50a70caa..1c2ffb83a 100644 --- a/server/test/unit/validation/userValidation.test.ts +++ b/server/test/unit/validation/userValidation.test.ts @@ -43,4 +43,25 @@ describe("editUserBodyValidation", () => { }); expect(result.success).toBe(false); }); + + // Regression: `deleteProfileImage` was missing from this schema, so z.object() + // stripped it before it reached the repository and the remove-profile-image + // flow was silently a no-op. The flag arrives as the multipart form-data + // string "true", so it must both survive parsing and coerce to a boolean. + it("retains deleteProfileImage and coerces the multipart string 'true' to boolean true", () => { + const result = editUserBodyValidation.safeParse({ deleteProfileImage: "true" }); + expect(result.success).toBe(true); + expect(result.data).toEqual({ deleteProfileImage: true }); + }); + + it("coerces the multipart string 'false' to boolean false", () => { + const result = editUserBodyValidation.safeParse({ deleteProfileImage: "false" }); + expect(result.success).toBe(true); + expect(result.data).toEqual({ deleteProfileImage: false }); + }); + + it("rejects a non-boolean deleteProfileImage value", () => { + const result = editUserBodyValidation.safeParse({ deleteProfileImage: "banana" }); + expect(result.success).toBe(false); + }); });