|
1 | 1 | import { Messages, Packet } from '@prisel/client'; |
2 | | -import { |
3 | | - connectAndLogin, |
4 | | - createClients, |
5 | | - createLoginedClients, |
6 | | - waitForRoomUpdate, |
7 | | -} from './testHelper'; |
| 2 | +import { createClients } from './testHelper'; |
8 | 3 |
|
9 | 4 | describe('create room', () => { |
10 | | - it('create a room', async () => { |
| 5 | + it('join default room', async () => { |
11 | 6 | const [client] = createClients(); |
12 | 7 | await client.connect(); |
13 | 8 | await client.request(Messages.getLogin(client.newId(), 'batman')); |
14 | | - const response = await client.request(Messages.getCreateRoom(client.newId(), 'party room')); |
15 | | - expect(Packet.getPayload(response, 'createRoomResponse')?.room?.id).toEqual( |
16 | | - expect.any(String), |
17 | | - ); |
| 9 | + const response = await client.request(Messages.getJoin(client.newId())); |
| 10 | + expect(Packet.isStatusOk(response)); |
| 11 | + expect(Packet.getPayload(response, 'joinResponse')?.room?.name).toEqual('room'); |
18 | 12 | client.exit(); |
19 | 13 | }); |
| 14 | + // it('create a room', async () => { |
| 15 | + // const [client] = createClients(); |
| 16 | + // await client.connect(); |
| 17 | + // await client.request(Messages.getLogin(client.newId(), 'batman')); |
| 18 | + // const response = await client.request(Messages.getCreateRoom(client.newId(), 'party room')); |
| 19 | + // expect(Packet.getPayload(response, 'createRoomResponse')?.room?.id).toEqual( |
| 20 | + // expect.any(String), |
| 21 | + // ); |
| 22 | + // client.exit(); |
| 23 | + // }); |
20 | 24 |
|
21 | 25 | it('create a room, join and then leave', async () => { |
22 | 26 | const [client] = createClients(); |
23 | 27 | await client.connect(); |
24 | 28 | await client.request(Messages.getLogin(client.newId(), 'batman')); |
25 | | - const createRoomResponse = await client.request( |
26 | | - Messages.getCreateRoom(client.newId(), 'room'), |
27 | | - ); |
28 | | - expect(Packet.isStatusOk(createRoomResponse)).toBe(true); |
| 29 | + await client.request(Messages.getJoin(client.newId())); |
29 | 30 | const leaveResponse = await client.request(Messages.getLeave(client.newId())); |
30 | 31 | expect(Packet.isStatusOk(leaveResponse)).toBe(true); |
31 | 32 | client.exit(); |
32 | 33 | }); |
33 | 34 |
|
34 | | - it('create a room and a client join', async () => { |
35 | | - const [host, client] = createClients(2); |
36 | | - const hostId = await connectAndLogin(host); |
37 | | - const clientId = await connectAndLogin(client); |
| 35 | + // it('create a room and a client join', async () => { |
| 36 | + // const [host, client] = createClients(2); |
| 37 | + // const hostId = await connectAndLogin(host); |
| 38 | + // const clientId = await connectAndLogin(client); |
38 | 39 |
|
39 | | - const createRoomResponse = await host.request( |
40 | | - Messages.getCreateRoom(host.newId(), 'party room'), |
41 | | - ); |
42 | | - const roomId = Packet.getPayload(createRoomResponse, 'createRoomResponse')?.room?.id; |
43 | | - expect(roomId).toBeDefined(); |
44 | | - if (roomId) { |
45 | | - const [hostRoomUpdateResult, clientJoinResponse] = await Promise.all([ |
46 | | - waitForRoomUpdate(host), |
47 | | - client |
48 | | - .request(Messages.getJoin(client.newId(), roomId)) |
49 | | - .then((response) => Packet.getPayload(response, 'joinResponse')), |
50 | | - ]); |
| 40 | + // const createRoomResponse = await host.request( |
| 41 | + // Messages.getCreateRoom(host.newId(), 'party room'), |
| 42 | + // ); |
| 43 | + // const roomId = Packet.getPayload(createRoomResponse, 'createRoomResponse')?.room?.id; |
| 44 | + // expect(roomId).toBeDefined(); |
| 45 | + // if (roomId) { |
| 46 | + // const [hostRoomUpdateResult, clientJoinResponse] = await Promise.all([ |
| 47 | + // waitForRoomUpdate(host), |
| 48 | + // client |
| 49 | + // .request(Messages.getJoin(client.newId(), roomId)) |
| 50 | + // .then((response) => Packet.getPayload(response, 'joinResponse')), |
| 51 | + // ]); |
51 | 52 |
|
52 | | - expect(clientJoinResponse?.roomState?.players.length).toBe(2); |
53 | | - expect(clientJoinResponse?.roomState?.hostId).toBe(hostId); |
54 | | - expect(clientJoinResponse?.roomState?.token).toEqual(expect.any(String)); |
55 | | - expect(hostRoomUpdateResult.token).toEqual( |
56 | | - expect.objectContaining({ |
57 | | - previousToken: expect.any(String), |
58 | | - token: expect.any(String), |
59 | | - }), |
60 | | - ); |
61 | | - } |
| 53 | + // expect(clientJoinResponse?.roomState?.players.length).toBe(2); |
| 54 | + // expect(clientJoinResponse?.roomState?.hostId).toBe(hostId); |
| 55 | + // expect(clientJoinResponse?.roomState?.token).toEqual(expect.any(String)); |
| 56 | + // expect(hostRoomUpdateResult.token).toEqual( |
| 57 | + // expect.objectContaining({ |
| 58 | + // previousToken: expect.any(String), |
| 59 | + // token: expect.any(String), |
| 60 | + // }), |
| 61 | + // ); |
| 62 | + // } |
62 | 63 |
|
63 | | - host.exit(); |
64 | | - client.exit(); |
65 | | - }); |
| 64 | + // host.exit(); |
| 65 | + // client.exit(); |
| 66 | + // }); |
66 | 67 |
|
67 | | - it('in a room everyone leaves', async () => { |
68 | | - const [host, guest] = await createLoginedClients(2); |
69 | | - const createResponse = await host.request(Messages.getCreateRoom(host.newId(), 'room')); |
70 | | - const roomId = Packet.getPayload(createResponse, 'createRoomResponse')?.room?.id; |
71 | | - expect(roomId).toBeDefined(); |
72 | | - if (roomId) { |
73 | | - await Promise.all([ |
74 | | - waitForRoomUpdate(host), |
75 | | - guest.request(Messages.getJoin(guest.newId(), roomId)), |
76 | | - ]); |
77 | | - await Promise.all([ |
78 | | - waitForRoomUpdate(guest), |
79 | | - host.request(Messages.getLeave(host.newId())), |
80 | | - ]); |
81 | | - await guest.request(Messages.getLeave(guest.newId())); |
82 | | - } |
83 | | - host.exit(); |
84 | | - guest.exit(); |
85 | | - }); |
| 68 | + // it('in a room everyone leaves', async () => { |
| 69 | + // const [host, guest] = await createLoginedClients(2); |
| 70 | + // const createResponse = await host.request(Messages.getCreateRoom(host.newId(), 'room')); |
| 71 | + // const roomId = Packet.getPayload(createResponse, 'createRoomResponse')?.room?.id; |
| 72 | + // expect(roomId).toBeDefined(); |
| 73 | + // if (roomId) { |
| 74 | + // await Promise.all([ |
| 75 | + // waitForRoomUpdate(host), |
| 76 | + // guest.request(Messages.getJoin(guest.newId(), roomId)), |
| 77 | + // ]); |
| 78 | + // await Promise.all([ |
| 79 | + // waitForRoomUpdate(guest), |
| 80 | + // host.request(Messages.getLeave(host.newId())), |
| 81 | + // ]); |
| 82 | + // await guest.request(Messages.getLeave(guest.newId())); |
| 83 | + // } |
| 84 | + // host.exit(); |
| 85 | + // guest.exit(); |
| 86 | + // }); |
86 | 87 | }); |
0 commit comments