|
| 1 | +import { beforeAll, describe, expect, it } from 'vitest'; |
| 2 | +import { v4 as uuidv4 } from 'uuid'; |
| 3 | +import { createTestClient } from './create-test-client'; |
| 4 | +import { StreamClient } from '../src/StreamClient'; |
| 5 | +import { UserObjectRequest } from '../src/gen/chat'; |
| 6 | +import { StreamCall } from '../src/StreamCall'; |
| 7 | + |
| 8 | +describe('teams', () => { |
| 9 | + let client: StreamClient; |
| 10 | + const userId = 'streamnodetest' + uuidv4(); |
| 11 | + const newUser: UserObjectRequest = { |
| 12 | + id: userId, |
| 13 | + role: 'user', |
| 14 | + custom: { |
| 15 | + color: 'red', |
| 16 | + }, |
| 17 | + name: userId, |
| 18 | + image: ':)', |
| 19 | + teams: ['red', 'blue'], |
| 20 | + }; |
| 21 | + const user = { |
| 22 | + id: 'stream-node-test-user', |
| 23 | + role: 'admin', |
| 24 | + }; |
| 25 | + const callId = `call${uuidv4()}`; |
| 26 | + let call: StreamCall; |
| 27 | + |
| 28 | + beforeAll(async () => { |
| 29 | + client = createTestClient(); |
| 30 | + await client.upsertUsers({ |
| 31 | + users: { |
| 32 | + [user.id]: { ...user }, |
| 33 | + }, |
| 34 | + }); |
| 35 | + call = client.video.call('default', callId); |
| 36 | + }); |
| 37 | + |
| 38 | + it('create user with team', async () => { |
| 39 | + const response = await client.upsertUsers({ |
| 40 | + users: { |
| 41 | + [newUser.id]: { |
| 42 | + ...newUser, |
| 43 | + }, |
| 44 | + }, |
| 45 | + }); |
| 46 | + |
| 47 | + const createdUser = response.users[newUser.id]; |
| 48 | + |
| 49 | + expect(createdUser.teams).toEqual(['red', 'blue']); |
| 50 | + |
| 51 | + const queryResponse = await client.queryUsers({ |
| 52 | + sort: [], |
| 53 | + filter_conditions: { |
| 54 | + id: { $eq: newUser.id }, |
| 55 | + }, |
| 56 | + }); |
| 57 | + |
| 58 | + expect(queryResponse.users.find((u) => u.id === newUser.id)?.teams).toEqual( |
| 59 | + ['red', 'blue'], |
| 60 | + ); |
| 61 | + }); |
| 62 | + |
| 63 | + it('search users with teams', async () => { |
| 64 | + let response = await client.queryUsers({ |
| 65 | + filter_conditions: { |
| 66 | + name: userId, |
| 67 | + teams: { $in: ['blue', 'green'] }, |
| 68 | + }, |
| 69 | + }); |
| 70 | + |
| 71 | + expect(response.users[0].id).toBe(userId); |
| 72 | + |
| 73 | + response = await client.queryUsers({ |
| 74 | + filter_conditions: { |
| 75 | + name: userId, |
| 76 | + teams: null, |
| 77 | + }, |
| 78 | + }); |
| 79 | + |
| 80 | + expect(response.users.length).toBe(0); |
| 81 | + }); |
| 82 | + |
| 83 | + it('create call with teams', async () => { |
| 84 | + const response = await call.create({ |
| 85 | + data: { team: 'red', created_by_id: user.id }, |
| 86 | + }); |
| 87 | + |
| 88 | + expect(response.call.team).toBe('red'); |
| 89 | + }); |
| 90 | + |
| 91 | + it('query calls', async () => { |
| 92 | + let response = await client.video.queryCalls(); |
| 93 | + |
| 94 | + expect(response.calls.length).toBeGreaterThan(0); |
| 95 | + |
| 96 | + // TODO: backend issue |
| 97 | + // response = await client.video.queryCalls({ |
| 98 | + // filter_conditions: { |
| 99 | + // team: null, |
| 100 | + // }, |
| 101 | + // }); |
| 102 | + |
| 103 | + response = await client.video.queryCalls({ |
| 104 | + filter_conditions: { |
| 105 | + team: 'red', |
| 106 | + }, |
| 107 | + }); |
| 108 | + |
| 109 | + expect(response.calls.find((c) => c.call.id === callId)).toBeDefined(); |
| 110 | + }); |
| 111 | +}); |
0 commit comments