fix(members/invites): unwrap ApiResponse before returning to client
POST /members/invites was returning the full ApiResponseInviteResponse wrapper. The client set activeInvite directly from the response body, so shareUrl/inviteCode/expiresAt were missing (nested under .data). Fixed to return data?.data — the inner InviteResponse — matching the shape that InvitePanel and page.server.ts already expect. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -5,5 +5,5 @@ import { apiClient } from '$lib/server/api';
|
|||||||
export const POST: RequestHandler = async ({ fetch }) => {
|
export const POST: RequestHandler = async ({ fetch }) => {
|
||||||
const api = apiClient(fetch);
|
const api = apiClient(fetch);
|
||||||
const { data, response } = await api.POST('/v1/households/mine/invites');
|
const { data, response } = await api.POST('/v1/households/mine/invites');
|
||||||
return json(data, { status: response?.status ?? 201 });
|
return json(data?.data, { status: response?.status ?? 201 });
|
||||||
};
|
};
|
||||||
|
|||||||
33
frontend/src/routes/(app)/members/invites/server.test.ts
Normal file
33
frontend/src/routes/(app)/members/invites/server.test.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||||
|
|
||||||
|
vi.mock('$env/dynamic/private', () => ({ env: { BACKEND_URL: 'http://localhost:8080' } }));
|
||||||
|
|
||||||
|
const mockPost = vi.fn();
|
||||||
|
vi.mock('$lib/server/api', () => ({
|
||||||
|
apiClient: () => ({ POST: mockPost })
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('invites server route', () => {
|
||||||
|
let POST: any;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
mockPost.mockReset();
|
||||||
|
vi.resetModules();
|
||||||
|
const mod = await import('./+server');
|
||||||
|
POST = mod.POST;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('POST returns unwrapped InviteResponse', async () => {
|
||||||
|
const invite = { inviteCode: 'ABC123', shareUrl: 'https://x.com/join/ABC123', expiresAt: '2026-12-01T00:00:00Z' };
|
||||||
|
mockPost.mockResolvedValue({
|
||||||
|
data: { status: 'success', data: invite },
|
||||||
|
response: { status: 200 }
|
||||||
|
});
|
||||||
|
const event = { fetch: vi.fn() } as any;
|
||||||
|
const res = await POST(event);
|
||||||
|
const body = await res.json();
|
||||||
|
expect(body.inviteCode).toBe('ABC123');
|
||||||
|
expect(body.shareUrl).toBe('https://x.com/join/ABC123');
|
||||||
|
expect(body.expiresAt).toBe('2026-12-01T00:00:00Z');
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user