| import { describe, it, expect, vi } from 'vitest' | |
| vi.mock('lib/persistence', () => ({ | |
| insertRoom: vi.fn(async (payload) => ({ id: 'room-1', ...payload })), | |
| updateCodesRoomId: vi.fn(async (ids: string[], roomId: string) => ids.map(id => ({ id, room_id: roomId }))), | |
| })) | |
| import { createRoom } from './roomService' | |
| import { insertRoom, updateCodesRoomId } from 'lib/persistence' | |
| describe('roomService', () => { | |
| it('createRoom links codes and returns id', async () => { | |
| const res = await createRoom('code-a', 'code-b') | |
| expect(res).toBe('room-1') | |
| expect(insertRoom).toHaveBeenCalled() | |
| expect(updateCodesRoomId).toHaveBeenCalledWith(['code-a', 'code-b'], 'room-1') | |
| }) | |
| }) | |