From 2333602f2512474e01533692ab3864ae6059ccc8 Mon Sep 17 00:00:00 2001 From: Hemachandar <132386067+hmacr@users.noreply.github.com> Date: Thu, 20 Jun 2024 05:41:54 +0530 Subject: [PATCH] fix: Allow user to remove team logo (#7095) --- app/scenes/Settings/Details.tsx | 2 +- server/routes/api/teams/schema.ts | 2 +- server/routes/api/teams/teams.test.ts | 28 +++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/app/scenes/Settings/Details.tsx b/app/scenes/Settings/Details.tsx index eab2ade3b..1bf8a9a8a 100644 --- a/app/scenes/Settings/Details.tsx +++ b/app/scenes/Settings/Details.tsx @@ -104,7 +104,7 @@ function Details() { [] ); - const handleAvatarChange = async (avatarUrl: string) => { + const handleAvatarChange = async (avatarUrl: string | null) => { await team.save({ avatarUrl }); toast.success(t("Logo updated")); }; diff --git a/server/routes/api/teams/schema.ts b/server/routes/api/teams/schema.ts index 476bd4247..5f1c1e76b 100644 --- a/server/routes/api/teams/schema.ts +++ b/server/routes/api/teams/schema.ts @@ -7,7 +7,7 @@ export const TeamsUpdateSchema = BaseSchema.extend({ /** Team name */ name: z.string().optional(), /** Avatar URL */ - avatarUrl: z.string().optional(), + avatarUrl: z.string().nullish(), /** The subdomain to access the team */ subdomain: z.string().nullish(), /** Whether public sharing is enabled */ diff --git a/server/routes/api/teams/teams.test.ts b/server/routes/api/teams/teams.test.ts index 5ee519f04..44c7f3d99 100644 --- a/server/routes/api/teams/teams.test.ts +++ b/server/routes/api/teams/teams.test.ts @@ -56,6 +56,34 @@ describe("#team.update", () => { expect(body.data.name).toEqual(name); }); + it("should add avatar", async () => { + const team = await buildTeam(); + const admin = await buildAdmin({ teamId: team.id }); + const res = await server.post("/api/team.update", { + body: { + token: admin.getJwtToken(), + avatarUrl: "https://random-url.com", + }, + }); + const body = await res.json(); + expect(res.status).toEqual(200); + expect(body.data.avatarUrl).toEqual("https://random-url.com"); + }); + + it("should remove avatar", async () => { + const team = await buildTeam({ avatarUrl: "https://random-url.com" }); + const admin = await buildAdmin({ teamId: team.id }); + const res = await server.post("/api/team.update", { + body: { + token: admin.getJwtToken(), + avatarUrl: null, + }, + }); + const body = await res.json(); + expect(res.status).toEqual(200); + expect(body.data.avatarUrl).toBeNull(); + }); + it("should not invalidate request if subdomain is sent as null", async () => { const admin = await buildAdmin(); const res = await server.post("/api/team.update", {