diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-12-31 19:51:21 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-12-31 19:51:21 +0900 |
| commit | c915c21d47a2b417979b20e9e9d9b6ff30a03c0d (patch) | |
| tree | 643ba4e499bae8a541d77f299837361a75890b10 /src/client/api/client.test.ts | |
| parent | 73ee02825f57d971f6f660fc5277d4aa268702ff (diff) | |
| download | kioku-c915c21d47a2b417979b20e9e9d9b6ff30a03c0d.tar.gz kioku-c915c21d47a2b417979b20e9e9d9b6ff30a03c0d.tar.zst kioku-c915c21d47a2b417979b20e9e9d9b6ff30a03c0d.zip | |
refactor(client): use Hono InferResponseType for API response types
Replace manually defined AuthResponse and User types with Hono's
InferResponseType to automatically derive types from server definitions.
This ensures client types stay in sync with server responses.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Diffstat (limited to 'src/client/api/client.test.ts')
| -rw-r--r-- | src/client/api/client.test.ts | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/client/api/client.test.ts b/src/client/api/client.test.ts index 5489547..27c3a0a 100644 --- a/src/client/api/client.test.ts +++ b/src/client/api/client.test.ts @@ -13,8 +13,10 @@ import { import { ApiClient, ApiClientError, + type LoginResponse, localStorageTokenStorage, type TokenStorage, + type User, } from "./client"; function createMockTokenStorage(): TokenStorage & { @@ -209,3 +211,31 @@ describe("localStorageTokenStorage", () => { expect(localStorageTokenStorage.getTokens()).toBeNull(); }); }); + +describe("InferResponseType types", () => { + it("LoginResponse has expected properties", () => { + // This test verifies the inferred types have the correct structure + // The type assertions will fail at compile time if the types are wrong + const mockResponse: LoginResponse = { + accessToken: "access-token", + refreshToken: "refresh-token", + user: { id: "123", username: "testuser" }, + }; + + expect(mockResponse.accessToken).toBe("access-token"); + expect(mockResponse.refreshToken).toBe("refresh-token"); + expect(mockResponse.user.id).toBe("123"); + expect(mockResponse.user.username).toBe("testuser"); + }); + + it("User type is correctly derived from LoginResponse", () => { + // Verify User type has expected structure + const user: User = { + id: "user-1", + username: "testuser", + }; + + expect(user.id).toBe("user-1"); + expect(user.username).toBe("testuser"); + }); +}); |
