File size: 710 Bytes
9853b20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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')
  })
})