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'); }); });