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>
34 lines
1021 B
TypeScript
34 lines
1021 B
TypeScript
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');
|
|
});
|
|
});
|