get(route('admin.rooms.judgingAssignment')) ->assertRedirect(route('home')); actAsNormal(); $this->get(route('admin.rooms.judgingAssignment')) ->assertRedirect(route('dashboard')) ->assertSessionHas('error', 'You are not authorized to perform this action'); actAsAdmin(); $this->get(route('admin.rooms.judgingAssignment')) ->assertOk(); }); it('shows a card for each room with its judges', function () { // Arrange $rooms = Room::factory()->count(3)->create(); foreach ($rooms as $room) { $users = User::factory()->count(3)->create(); foreach ($users as $user) { $room->addJudge($user->id); } } // Act & Assert actAsAdmin(); $response = $this->get(route('admin.rooms.judgingAssignment')); $response->assertOk(); foreach ($rooms as $room) { $response->assertElementExists('#room-'.$room->id.'-card', function (AssertElement $element) use ($room) { $element->is('li'); $element->containsText($room->name); foreach ($room->judges as $judge) { $element->containsText($judge->full_name()); } }); } }); it('can assign a judge', function () { // Arrange $room = Room::factory()->create(); $judge = User::factory()->create(); // Act & Assert expect($room->judges->contains($judge))->toBeFalse(); actAsAdmin(); $response = $this->post(route('admin.rooms.updateJudgeAssignment', $room), ['judge' => $judge->id]); /** @noinspection PhpUnhandledExceptionInspection */ $response->assertRedirect(route('admin.rooms.judgingAssignment')) ->assertSessionHas('success', 'Assigned '.$judge->full_name().' to '.$room->name) ->assertSessionHasNoErrors(); $checkRoom = Room::find($room->id); expect($checkRoom->judges->contains($judge))->toBeTrue(); }); it('can remove a judge', function () { // Arrange $room = Room::factory()->create(); $judge = User::factory()->create(); $room->addJudge($judge->id); expect($room->judges->contains($judge))->toBeTrue(); actAsAdmin(); // Act & Assert $response = $this->delete(route('admin.rooms.updateJudgeAssignment', $room), ['judge' => $judge->id]); /** @noinspection PhpUnhandledExceptionInspection */ $response->assertRedirect(route('admin.rooms.judgingAssignment')) ->assertSessionHas('success', 'Removed '.$judge->full_name().' from '.$room->name) ->assertSessionHasNoErrors(); $checkRoom = Room::find($room->id); expect($checkRoom->judges->contains($judge))->toBeFalse(); });