Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/OpenViduTest.php
Show First 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | public function testJoinRoom(): void | ||||
$response = $this->actingAs($john)->post("api/v4/openvidu/rooms/{$room->name}", ['init' => 1]); | $response = $this->actingAs($john)->post("api/v4/openvidu/rooms/{$room->name}", ['init' => 1]); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$session_id = $room->fresh()->session_id; | $session_id = $room->fresh()->session_id; | ||||
$this->assertSame(Room::ROLE_MODERATOR, $json['role']); | $this->assertSame(Room::ROLE_SUBSCRIBER | Room::ROLE_MODERATOR | Room::ROLE_OWNER, $json['role']); | ||||
$this->assertSame($session_id, $json['session']); | $this->assertSame($session_id, $json['session']); | ||||
$this->assertFalse($json['canPublish']); | |||||
$this->assertTrue(is_string($session_id) && !empty($session_id)); | $this->assertTrue(is_string($session_id) && !empty($session_id)); | ||||
$this->assertTrue(strpos($json['token'], 'wss://') === 0); | $this->assertTrue(strpos($json['token'], 'wss://') === 0); | ||||
$this->assertTrue(!array_key_exists('shareToken', $json)); | $this->assertTrue(!array_key_exists('shareToken', $json)); | ||||
$john_token = $json['token']; | $john_token = $json['token']; | ||||
// Non-owner, now the session exists, no 'init' argument | // Non-owner, now the session exists, no 'init' argument | ||||
$response = $this->actingAs($jack)->post("api/v4/openvidu/rooms/{$room->name}"); | $response = $this->actingAs($jack)->post("api/v4/openvidu/rooms/{$room->name}"); | ||||
$response->assertStatus(422); | $response->assertStatus(422); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertSame(322, $json['code']); | $this->assertSame(322, $json['code']); | ||||
$this->assertTrue(empty($json['token'])); | $this->assertTrue(empty($json['token'])); | ||||
$this->assertTrue(empty($json['shareToken'])); | $this->assertTrue(empty($json['shareToken'])); | ||||
// Non-owner, now the session exists, with 'init', but no 'canPublish' argument | // Non-owner, now the session exists, with 'init', but no 'canPublish' argument | ||||
$response = $this->actingAs($jack)->post("api/v4/openvidu/rooms/{$room->name}", ['init' => 1]); | $response = $this->actingAs($jack)->post("api/v4/openvidu/rooms/{$room->name}", ['init' => 1]); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertSame(Room::ROLE_SUBSCRIBER, $json['role']); | $this->assertSame(Room::ROLE_SUBSCRIBER, $json['role']); | ||||
$this->assertFalse($json['canPublish']); | |||||
$this->assertSame($session_id, $json['session']); | $this->assertSame($session_id, $json['session']); | ||||
$this->assertTrue(strpos($json['token'], 'wss://') === 0); | $this->assertTrue(strpos($json['token'], 'wss://') === 0); | ||||
$this->assertTrue($json['token'] != $john_token); | $this->assertTrue($json['token'] != $john_token); | ||||
$this->assertTrue(empty($json['shareToken'])); | $this->assertTrue(empty($json['shareToken'])); | ||||
// Non-owner, now the session exists, with 'init', and with 'role=PUBLISHER' | // Non-owner, now the session exists, with 'init', and with 'role=PUBLISHER' | ||||
$post = ['canPublish' => true, 'init' => 1]; | $post = ['canPublish' => true, 'init' => 1]; | ||||
$response = $this->actingAs($jack)->post("api/v4/openvidu/rooms/{$room->name}", $post); | $response = $this->actingAs($jack)->post("api/v4/openvidu/rooms/{$room->name}", $post); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertSame(Room::ROLE_PUBLISHER, $json['role']); | $this->assertSame(Room::ROLE_PUBLISHER, $json['role']); | ||||
$this->assertSame($session_id, $json['session']); | $this->assertSame($session_id, $json['session']); | ||||
$this->assertTrue($json['canPublish']); | |||||
$this->assertTrue(strpos($json['token'], 'wss://') === 0); | $this->assertTrue(strpos($json['token'], 'wss://') === 0); | ||||
$this->assertTrue($json['token'] != $john_token); | $this->assertTrue($json['token'] != $john_token); | ||||
$this->assertTrue(!array_key_exists('shareToken', $json)); | $this->assertTrue(!array_key_exists('shareToken', $json)); | ||||
$this->assertEmpty($json['config']['password']); | $this->assertEmpty($json['config']['password']); | ||||
$this->assertEmpty($json['config']['requires_password']); | $this->assertEmpty($json['config']['requires_password']); | ||||
// Non-owner, password protected room, password not provided | // Non-owner, password protected room, password not provided | ||||
$room->setSettings(['password' => 'pass']); | $room->setSettings(['password' => 'pass']); | ||||
▲ Show 20 Lines • Show All 159 Lines • ▼ Show 20 Lines | public function testJoinRequests(): void | ||||
// Non-owner, locked room, join request accepted | // Non-owner, locked room, join request accepted | ||||
$post['init'] = 1; | $post['init'] = 1; | ||||
$post['canPublish'] = true; | $post['canPublish'] = true; | ||||
$response = $this->actingAs($jack)->post("api/v4/openvidu/rooms/{$room->name}", $post); | $response = $this->actingAs($jack)->post("api/v4/openvidu/rooms/{$room->name}", $post); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertSame(Room::ROLE_PUBLISHER, $json['role']); | $this->assertSame(Room::ROLE_PUBLISHER, $json['role']); | ||||
$this->assertTrue($json['canPublish']); | |||||
$this->assertTrue(strpos($json['token'], 'wss://') === 0); | $this->assertTrue(strpos($json['token'], 'wss://') === 0); | ||||
// TODO: Test a scenario where both password and lock are enabled | // TODO: Test a scenario where both password and lock are enabled | ||||
} | } | ||||
/** | /** | ||||
* Test joining the room | * Test joining the room | ||||
* | * | ||||
Show All 11 Lines | public function testJoinRoomGuest(): void | ||||
// Guest, request with screenShare token | // Guest, request with screenShare token | ||||
$post = ['canPublish' => true, 'screenShare' => 1, 'init' => 1]; | $post = ['canPublish' => true, 'screenShare' => 1, 'init' => 1]; | ||||
$response = $this->post("api/v4/openvidu/rooms/{$room->name}", $post); | $response = $this->post("api/v4/openvidu/rooms/{$room->name}", $post); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertSame(Room::ROLE_PUBLISHER, $json['role']); | $this->assertSame(Room::ROLE_PUBLISHER, $json['role']); | ||||
$this->assertTrue($json['canPublish']); | |||||
$this->assertSame($room->session_id, $json['session']); | $this->assertSame($room->session_id, $json['session']); | ||||
$this->assertTrue(strpos($json['token'], 'wss://') === 0); | $this->assertTrue(strpos($json['token'], 'wss://') === 0); | ||||
$this->assertTrue(strpos($json['shareToken'], 'wss://') === 0); | $this->assertTrue(strpos($json['shareToken'], 'wss://') === 0); | ||||
$this->assertTrue($json['shareToken'] != $json['token']); | $this->assertTrue($json['shareToken'] != $json['token']); | ||||
} | } | ||||
/** | /** | ||||
* Test closing the room (session) | * Test closing the room (session) | ||||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | public function testDismissConnection(): void | ||||
// Non-existing room name | // Non-existing room name | ||||
$response = $this->actingAs($john)->post("api/v4/openvidu/rooms/non-existing/connections/{$conn_id}/dismiss"); | $response = $this->actingAs($john)->post("api/v4/openvidu/rooms/non-existing/connections/{$conn_id}/dismiss"); | ||||
$response->assertStatus(404); | $response->assertStatus(404); | ||||
// TODO: Test accessing an existing room of deleted owner | // TODO: Test accessing an existing room of deleted owner | ||||
// Non-existing connection | // Non-existing connection | ||||
$response = $this->actingAs($john)->post("api/v4/openvidu/rooms/{$room->name}/connections/123/dismiss"); | $response = $this->actingAs($john)->post("api/v4/openvidu/rooms/{$room->name}/connections/123/dismiss"); | ||||
$response->assertStatus(500); | $response->assertStatus(404); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertCount(2, $json); | $this->assertCount(2, $json); | ||||
$this->assertSame('error', $json['status']); | $this->assertSame('error', $json['status']); | ||||
$this->assertSame('Failed to dismiss the connection.', $json['message']); | $this->assertSame('The connection does not exist.', $json['message']); | ||||
// Non-owner access | // Non-owner access | ||||
$response = $this->actingAs($jack)->post("api/v4/openvidu/rooms/{$room->name}/connections/{$conn_id}/dismiss"); | $response = $this->actingAs($jack)->post("api/v4/openvidu/rooms/{$room->name}/connections/{$conn_id}/dismiss"); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
// Expected success | // Expected success | ||||
$response = $this->actingAs($john)->post("api/v4/openvidu/rooms/{$room->name}/connections/{$conn_id}/dismiss"); | $response = $this->actingAs($john)->post("api/v4/openvidu/rooms/{$room->name}/connections/{$conn_id}/dismiss"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
▲ Show 20 Lines • Show All 85 Lines • Show Last 20 Lines |