diff --git a/backend/__tests__/api/controllers/user.spec.ts b/backend/__tests__/api/controllers/user.spec.ts index ddc596a65..ee37253bc 100644 --- a/backend/__tests__/api/controllers/user.spec.ts +++ b/backend/__tests__/api/controllers/user.spec.ts @@ -2879,6 +2879,50 @@ describe("user controller test", () => { } ); }); + it("should update with empty strings", async () => { + //GIVEN + const newProfile = { + bio: "", + keyboard: "", + + socialProfiles: { + github: "", + twitter: "", + website: "", + }, + }; + + //WHEN + const { body } = await mockApp + .patch("/users/profile") + .set("Authorization", `Uid ${uid}`) + .send({ + ...newProfile, + selectedBadgeId: -1, + }) + .expect(200); + + //THEN + expect(body).toEqual({ + message: "Profile updated", + data: newProfile, + }); + expect(updateProfileMock).toHaveBeenCalledWith( + uid, + { + bio: "", + keyboard: "", + socialProfiles: { + github: "", + twitter: "", + website: "", + }, + }, + { + badges: [{ id: 4 }, { id: 2 }, { id: 3 }], + } + ); + }); it("should fail with unknown properties", async () => { //WHEN const { body } = await mockApp diff --git a/packages/contracts/src/schemas/users.ts b/packages/contracts/src/schemas/users.ts index c7630ead7..9bcf3c417 100644 --- a/packages/contracts/src/schemas/users.ts +++ b/packages/contracts/src/schemas/users.ts @@ -109,8 +109,8 @@ function profileDetailsBase( export const UserProfileDetailsSchema = z .object({ - bio: profileDetailsBase(z.string().max(250)), - keyboard: profileDetailsBase(z.string().max(75)), + bio: profileDetailsBase(z.string().max(250)).or(z.literal("")), + keyboard: profileDetailsBase(z.string().max(75)).or(z.literal("")), socialProfiles: z .object({ twitter: profileDetailsBase( @@ -118,16 +118,16 @@ export const UserProfileDetailsSchema = z .string() .max(20) .regex(/^[0-9a-zA-Z_.-]+$/) - ), + ).or(z.literal("")), github: profileDetailsBase( z .string() .max(39) .regex(/^[0-9a-zA-Z_.-]+$/) - ), + ).or(z.literal("")), website: profileDetailsBase( z.string().url().max(200).startsWith("https://") - ), + ).or(z.literal("")), }) .strict() .optional(),