From 2fb6471a685bec1433be3335f377a1a2313e4820 Mon Sep 17 00:00:00 2001
From: nsfisis <nsfisis@gmail.com>
Date: Thu, 1 Jan 2026 23:44:50 +0900
Subject: refactor(client): migrate API calls to typed RPC client
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Replace raw fetch() calls with apiClient.rpc typed client across all
modal and page components. This provides better type safety and
eliminates manual auth header handling.

- Make handleResponse public for component usage
- Update all component tests to mock RPC methods instead of fetch
- Change POSTGRES_HOST default to kioku-db for Docker compatibility

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
---
 src/client/pages/HomePage.test.tsx | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

(limited to 'src/client/pages/HomePage.test.tsx')

diff --git a/src/client/pages/HomePage.test.tsx b/src/client/pages/HomePage.test.tsx
index 944dd31..cb96aa3 100644
--- a/src/client/pages/HomePage.test.tsx
+++ b/src/client/pages/HomePage.test.tsx
@@ -11,6 +11,10 @@ import { apiClient } from "../api/client";
 import { AuthProvider, SyncProvider } from "../stores";
 import { HomePage } from "./HomePage";
 
+const mockDeckPut = vi.fn();
+const mockDeckDelete = vi.fn();
+const mockHandleResponse = vi.fn();
+
 vi.mock("../api/client", () => ({
 	apiClient: {
 		login: vi.fn(),
@@ -24,9 +28,14 @@ vi.mock("../api/client", () => ({
 				decks: {
 					$get: vi.fn(),
 					$post: vi.fn(),
+					":id": {
+						$put: (args: unknown) => mockDeckPut(args),
+						$delete: (args: unknown) => mockDeckDelete(args),
+					},
 				},
 			},
 		},
+		handleResponse: (res: unknown) => mockHandleResponse(res),
 	},
 	ApiClientError: class ApiClientError extends Error {
 		constructor(
@@ -110,6 +119,9 @@ describe("HomePage", () => {
 		vi.mocked(apiClient.getAuthHeader).mockReturnValue({
 			Authorization: "Bearer access-token",
 		});
+
+		// handleResponse passes through whatever it receives
+		mockHandleResponse.mockImplementation((res) => Promise.resolve(res));
 	});
 
 	afterEach(() => {
@@ -544,10 +556,7 @@ describe("HomePage", () => {
 					}),
 				);
 
-			mockFetch.mockResolvedValue({
-				ok: true,
-				json: async () => ({ deck: updatedDeck }),
-			});
+			mockDeckPut.mockResolvedValue({ deck: updatedDeck });
 
 			renderWithProviders();
 
@@ -686,10 +695,7 @@ describe("HomePage", () => {
 					}),
 				);
 
-			mockFetch.mockResolvedValue({
-				ok: true,
-				json: async () => ({}),
-			});
+			mockDeckDelete.mockResolvedValue({ success: true });
 
 			renderWithProviders();
 
-- 
cgit v1.2.3-70-g09d2

