From 9afb5fcee8296a6454999a33420c2bac2ef8e358 Mon Sep 17 00:00:00 2001 From: Munkherdene Date: Sat, 22 Aug 2026 20:29:35 +0800 Subject: [PATCH] fix(web): handle empty-body 201/204 responses in API client --- src/api/client.test.ts | 8 +++++++- src/api/client.ts | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/api/client.test.ts b/src/api/client.test.ts index 3118c47..57e471c 100644 --- a/src/api/client.test.ts +++ b/src/api/client.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from "vitest"; -import { apiGet } from "./client"; +import { apiGet, apiSend } from "./client"; import { NetWorthSchema } from "./schemas"; beforeEach(() => vi.restoreAllMocks()); describe("apiGet", () => { @@ -13,3 +13,9 @@ describe("apiGet", () => { await expect(apiGet("/networth", NetWorthSchema)).rejects.toThrow(); }); }); +describe("apiSend", () => { + it("resolves to null on an empty-body 201 (e.g. POST /categories, POST /manual-assets)", async () => { + vi.stubGlobal("fetch", vi.fn(async () => new Response("", { status: 201 }))); + await expect(apiSend("POST", "/categories", { name: "Food" })).resolves.toBeNull(); + }); +}); diff --git a/src/api/client.ts b/src/api/client.ts index 9373a14..04aa0cf 100644 --- a/src/api/client.ts +++ b/src/api/client.ts @@ -21,7 +21,8 @@ async function req(method: string, path: string, body?: unknown): Promise(path: string, schema: z.ZodType): Promise {