fix signature, add tests
This commit is contained in:
1 parent
d53785b768
commit
c961f5292d
2 files changed
+23
-2
No files matched your search
@@ -24,7 +24,7 @@ export interface IUserService {
|
|||||||
createUser(userData: Partial<User>, teamId: string, actorRoles: UserRole[], file: Express.Multer.File | null): Promise<User>;
|
createUser(userData: Partial<User>, teamId: string, actorRoles: UserRole[], file: Express.Multer.File | null): Promise<User>;
|
||||||
loginUser(email: string, password: string): Promise<{ user: User; token: string }>;
|
loginUser(email: string, password: string): Promise<{ user: User; token: string }>;
|
||||||
editUser(
|
editUser(
|
||||||
updates: Partial<User & { newPassword?: string }>,
|
updates: Partial<User & { newPassword?: string; deleteProfileImage?: boolean }>,
|
||||||
file: Express.Multer.File | null,
|
file: Express.Multer.File | null,
|
||||||
currentUserId: string,
|
currentUserId: string,
|
||||||
currentUserEmail: string
|
currentUserEmail: string
|
||||||
@@ -242,7 +242,7 @@ export class UserService implements IUserService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
editUser = async (
|
editUser = async (
|
||||||
updates: Partial<User & { newPassword?: string }>,
|
updates: Partial<User & { newPassword?: string; deleteProfileImage?: boolean }>,
|
||||||
file: Express.Multer.File | null,
|
file: Express.Multer.File | null,
|
||||||
currentUserId: string,
|
currentUserId: string,
|
||||||
currentUserEmail: string
|
currentUserEmail: string
|
||||||
|
|||||||
@@ -43,4 +43,25 @@ describe("editUserBodyValidation", () => {
|
|||||||
});
|
});
|
||||||
expect(result.success).toBe(false);
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user