diff --git a/app/Http/Controllers/Admin/RoomController.php b/app/Http/Controllers/Admin/RoomController.php index 9de1eed..a4be3cd 100644 --- a/app/Http/Controllers/Admin/RoomController.php +++ b/app/Http/Controllers/Admin/RoomController.php @@ -100,7 +100,7 @@ class RoomController extends Controller $room->description = $validData['description']; $room->save(); - return redirect()->route('admin.rooms.index')->with('success', 'Room updated.'); + return redirect()->route('admin.rooms.index')->with('success', 'Room updated successfully'); } public function destroy(Room $room) diff --git a/resources/views/admin/rooms/index-room-card.blade.php b/resources/views/admin/rooms/index-room-card.blade.php index 624c8ef..c543b04 100644 --- a/resources/views/admin/rooms/index-room-card.blade.php +++ b/resources/views/admin/rooms/index-room-card.blade.php @@ -1,10 +1,12 @@ - @include('admin.rooms.index-edit-room-modal') + @if($room->id != '0') + @include('admin.rooms.index-edit-room-modal') + @endif {{ $room->name }} {{ $room->description }} - @if($room->entries->count() === 0 and $room->id != '0') + @if($room->auditions->count() === 0 and $room->id != '0')
Rooms - New Room + New Room
diff --git a/tests/Feature/Pages/Setup/RoomsIndexTest.php b/tests/Feature/Pages/Setup/RoomsIndexTest.php new file mode 100644 index 0000000..7343fbd --- /dev/null +++ b/tests/Feature/Pages/Setup/RoomsIndexTest.php @@ -0,0 +1,125 @@ +count(3)->create(); + foreach ($rooms as $room) { + Audition::factory()->count(3)->create(['room_id' => $room->id]); + } + $auditions = Audition::all(); + foreach ($auditions as $audition) { + $n = fake()->numberBetween(1, 4); + Entry::factory()->count($n)->create(['audition_id' => $audition->id]); + } +} + +it('only allows an admin to manage rooms', function () { + get(route('admin.rooms.index')) + ->assertRedirect(route('home')); + actAsNormal(); + get(route('admin.rooms.index')) + ->assertRedirect(route('dashboard')) + ->assertSessionHas('error', 'You are not authorized to perform this action'); + actAsAdmin(); + get(route('admin.rooms.index')) + ->assertOk(); +}); +it('has a link to create a new room', function () { + actAsAdmin(); + get(route('admin.rooms.index')) + ->assertSee('New Room') + ->assertSee(route('admin.rooms.create')); +}); +it('has a card for each room, including the total number of entries in that room', function () { + // Arrange + roomTestSetup(); + // Act & Assert + actAsAdmin(); + $response = get(route('admin.rooms.index')); + $response->assertOk(); + foreach (Room::all() as $room) { + $roomEntryCount = $room->entries()->count(); + $response->assertSeeInOrder(['name), '', $roomEntryCount], false); + } +}); +it('has a form for editing each room', function () { + // Arrange + roomTestSetup(); + // Act & Assert + actAsAdmin(); + $response = get(route('admin.rooms.index')); + $response->assertOk(); + foreach (Room::all() as $room) { + if ($room->id === 0) { + continue; + } + $response->assertSeeInOrder([ + route('admin.rooms.update', $room), + 'create(); + $formData = [ + 'name' => 'New Room Name', + 'description' => 'New Room Description', + ]; + actAsAdmin(); + $response = $this->patch(route('admin.rooms.update', $room), $formData); + /** @noinspection PhpUnhandledExceptionInspection */ + $response->assertRedirect(route('admin.rooms.index')) + ->assertSessionHas('success', 'Room updated successfully') + ->assertSessionHasNoErrors(); + $this->assertDatabaseHas('rooms', $formData); +}); +it('can create a room', function () { + $formData = [ + 'name' => 'New Room Name', + 'description' => 'New Room Description', + ]; + actAsAdmin(); + $response = $this->post(route('admin.rooms.store'), $formData); + /** @noinspection PhpUnhandledExceptionInspection */ + $response->assertRedirect(route('admin.rooms.index')) + ->assertSessionHas('success', 'Room created.') + ->assertSessionHasNoErrors(); + $this->assertDatabaseHas('rooms', $formData); +}); + +it('can delete a room', function () { + // Arrange + $room = Room::factory()->create(); + // Act & Assert + actAsAdmin(); + $response = $this->delete(route('admin.rooms.destroy', $room)); + /** @noinspection PhpUnhandledExceptionInspection */ + $response->assertRedirect(route('admin.rooms.index')) + ->assertSessionHas('success', 'Room deleted.') + ->assertSessionHasNoErrors(); + $this->assertDatabaseMissing('rooms', ['id' => $room->id]); +}); +it('will not delete a room with auditions', function () { + $room = Room::factory()->create(); + Audition::factory()->create(['room_id' => $room->id]); + actAsAdmin(); + $response = $this->delete(route('admin.rooms.destroy', $room)); + /** @noinspection PhpUnhandledExceptionInspection */ + $response->assertRedirect(route('admin.rooms.index')) + ->assertSessionHas('error', + 'Cannot delete room with auditions. First move the auditions to unassigned or another room') + ->assertSessionHasNoErrors(); +});