From 7e8315e7a6ea08bdb55354aab5aaa04dadfd380d Mon Sep 17 00:00:00 2001 From: Bottersnike Date: Sun, 2 Oct 2022 23:51:25 +0100 Subject: [PATCH] Permit zero-length strings for about me --- client/src/app/pages/dashboard/users/UserPage.tsx | 2 +- .../router/api/v1/users/_userID/router.test.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/client/src/app/pages/dashboard/users/UserPage.tsx b/client/src/app/pages/dashboard/users/UserPage.tsx index 6d449d9d6..001f6011a 100644 --- a/client/src/app/pages/dashboard/users/UserPage.tsx +++ b/client/src/app/pages/dashboard/users/UserPage.tsx @@ -34,7 +34,7 @@ function AboutMeCard({ reqUser }: Props) { headers: { "Content-Type": "application/json", }, - body: JSON.stringify({ about: content.length === 0 ? null : content }), + body: JSON.stringify({ about: content }), }, true, true diff --git a/server/src/server/router/api/v1/users/_userID/router.test.ts b/server/src/server/router/api/v1/users/_userID/router.test.ts index cd2a96bec..a2f33ed82 100644 --- a/server/src/server/router/api/v1/users/_userID/router.test.ts +++ b/server/src/server/router/api/v1/users/_userID/router.test.ts @@ -120,6 +120,20 @@ t.test("PATCH /api/v1/users/:userID", async (t) => { t.end(); }); + t.test("Shouldn't allow empty strings for about me.", async (t) => { + const res = await mockApi.patch("/api/v1/users/1").set("Cookie", cookie).send({ + about: "", + }); + + t.equal(res.statusCode, 200); + + const dbUser = await db.users.findOne({ id: 1 }); + + t.equal(dbUser?.about, ""); + + t.end(); + }); + t.test("Shouldn't allow about me to be set to null.", async (t) => { const res = await mockApi.patch("/api/v1/users/1").set("Cookie", cookie).send({ about: null,