|
| 1 | +import { beforeAll, describe, expect, it } from 'vitest'; |
| 2 | +import { createTestClient } from './create-test-client'; |
| 3 | +import { StreamCall } from '../src/StreamCall'; |
| 4 | +import { StreamClient } from '../src/StreamClient'; |
| 5 | + |
| 6 | +describe('ring call API', () => { |
| 7 | + let client: StreamClient; |
| 8 | + const callId = `call${crypto.randomUUID()}`; |
| 9 | + let call: StreamCall; |
| 10 | + |
| 11 | + beforeAll(async () => { |
| 12 | + client = createTestClient(); |
| 13 | + |
| 14 | + call = client.video.call('default', callId); |
| 15 | + |
| 16 | + await client.upsertUsers([ |
| 17 | + { id: 'myself' }, |
| 18 | + { id: 'my-friend' }, |
| 19 | + { id: 'my-other-friend' }, |
| 20 | + ]); |
| 21 | + }); |
| 22 | + |
| 23 | + it(`create call without ringing`, async () => { |
| 24 | + const response = await call.getOrCreate({ |
| 25 | + ring: false, // set to false to avoid ringing the whole call |
| 26 | + data: { |
| 27 | + created_by_id: 'myself', |
| 28 | + members: [{ user_id: 'myself' }, { user_id: 'my-friend' }], |
| 29 | + }, |
| 30 | + }); |
| 31 | + |
| 32 | + // Dummy expect |
| 33 | + expect(response.call.id).toBe(callId); |
| 34 | + }); |
| 35 | + |
| 36 | + it(`ring my-friend`, async () => { |
| 37 | + const response = await call.ring({ member_ids: ['my-friend'] }); |
| 38 | + |
| 39 | + // Dummy expect |
| 40 | + expect(response.call.id).toBe(callId); |
| 41 | + }); |
| 42 | + |
| 43 | + it(`ring my-other-friend`, async () => { |
| 44 | + await call.updateCallMembers({ |
| 45 | + update_members: [{ user_id: 'my-other-friend' }], |
| 46 | + }); |
| 47 | + const response = await call.ring({ member_ids: ['my-other-friend'] }); |
| 48 | + |
| 49 | + // Dummy expect |
| 50 | + expect(response.call.id).toBe(callId); |
| 51 | + }); |
| 52 | + |
| 53 | + it('delete call', async () => { |
| 54 | + try { |
| 55 | + await call.delete({ hard: true }); |
| 56 | + } catch (e) { |
| 57 | + // the first request fails on backend sometimes |
| 58 | + // retry it |
| 59 | + await new Promise<void>((resolve) => { |
| 60 | + setTimeout(() => resolve(), 2000); |
| 61 | + }); |
| 62 | + |
| 63 | + await call.delete({ hard: true }); |
| 64 | + } |
| 65 | + }); |
| 66 | +}); |
0 commit comments