assertRedirect(route('home')); actAsNormal(); get((route('admin.ensembles.index'))) ->assertRedirect('/dashboard') ->assertSessionHas('error', 'You are not authorized to perform this action'); actasAdmin(); get((route('admin.ensembles.index'))) ->assertOk(); }); it('has a form to create an ensemble', function () { // Arrange actAsAdmin(); // Act & Assert get((route('admin.ensembles.index'))) ->assertOk() ->assertSee('action="'.route('admin.ensembles.store').'"', false) ->assertSee('name="name"', false) ->assertSee('name="code"', false) ->assertSee('name="event_id"', false) ->assertSeeInOrder([''], false); }); it('shows ensemble data', function () { // Arrange Ensemble::factory()->count(10)->create(); actAsAdmin(); // Act & Assert $response = get((route('admin.ensembles.index'))); $response->assertOk(); $events = Event::all(); foreach ($events as $event) { foreach ($event->ensembles as $ensemble) { $response->assertSeeInOrder([ e($event->name), 'id, '', 'name), '', ], false); } $response->assertSee($event->name); } }); it('shows a delete option for ensembles with no students seated', function () { // Arrange $event = Event::factory()->create(); $noSeatsEnsemble = Ensemble::factory()->create(['event_id' => $event->id]); $seatsEnsemble = Ensemble::factory()->create(['event_id' => $event->id]); $audition = Audition::factory()->create(['event_id' => $event->id]); $entry = Entry::factory()->create(['audition_id' => $audition->id]); Seat::create([ 'ensemble_id' => $seatsEnsemble->id, 'audition_id' => $audition->id, 'seat' => 1, 'entry_id' => $entry->id, ]); // Act & Assert actAsAdmin(); $response = get((route('admin.ensembles.index'))); $response->assertOk(); $response->assertSee(route('admin.ensembles.destroy', $noSeatsEnsemble), false); //$response->assertDontSee(route('admin.ensembles.destroy', $seatsEnsemble), false); // TODO figure out how to test for a delete form that does not also see an edit form }); it('allows an administrator to delete an ensemble while no entries are seated', function () { // Arrange $event = Event::factory()->create(); $noSeatsEnsemble = Ensemble::factory()->create(['event_id' => $event->id]); $seatsEnsemble = Ensemble::factory()->create(['event_id' => $event->id]); $audition = Audition::factory()->create(['event_id' => $event->id]); $entry = Entry::factory()->create(['audition_id' => $audition->id]); Seat::create([ 'ensemble_id' => $seatsEnsemble->id, 'audition_id' => $audition->id, 'seat' => 1, 'entry_id' => $entry->id, ]); // Act & Assert actAsAdmin(); delete((route('admin.ensembles.destroy', $noSeatsEnsemble))) ->assertRedirect(route('admin.ensembles.index')) ->assertSessionHas('success', 'Ensemble deleted successfully'); expect(Ensemble::find($noSeatsEnsemble->id))->toBeNull(); delete((route('admin.ensembles.destroy', $seatsEnsemble))) ->assertRedirect(route('admin.ensembles.index')) ->assertSessionHas('error', 'Ensemble has students seated and cannot be deleted'); }); it('does not allow a guest or normal user to delete an ensemble', function () { $ensemble = Ensemble::factory()->create(); delete((route('admin.ensembles.destroy', $ensemble))) ->assertRedirect(route('home')); actAsNormal(); delete((route('admin.ensembles.destroy', $ensemble))) ->assertRedirect('/dashboard') ->assertSessionHas('error', 'You are not authorized to perform this action'); }); it('includes a form to edit an ensemble', function () { // Arrange $ensemble = Ensemble::factory()->create(); actAsAdmin(); // Act & Assert get((route('admin.ensembles.index'))) ->assertOk() ->assertSee('action="'.route('admin.ensembles.update', $ensemble).'"', false); }); it('allows an administrator to update an ensemble', function () { // Arrange $ensemble = Ensemble::factory()->create(); $newData = [ 'name' => 'New Ensemble Name', 'code' => 'newC', ]; // Act & Assert actAsAdmin(); $response = patch(route('admin.ensembles.update', $ensemble), $newData); /** @noinspection PhpUnhandledExceptionInspection */ $response->assertRedirect(route('admin.ensembles.index')) ->assertSessionHas('success', 'Ensemble updated successfully') ->assertSessionHasNoErrors(); $postCheck = Ensemble::find($ensemble->id); expect($postCheck->name)->toBe($newData['name']) ->and($postCheck->code)->toBe($newData['code']); });