mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-09-20 07:16:17 +08:00
fix: unable to update profile with missing values (@fehmer) (#5859)
This commit is contained in:
parent
6de9ad6e1c
commit
9c083f2397
|
@ -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
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in a new issue