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", {