From 8d9bbf31d53b3b81caea0253a922dc25fcf035ab Mon Sep 17 00:00:00 2001 From: Matt Young Date: Thu, 4 Jul 2024 11:37:30 -0500 Subject: [PATCH] Fix IDE flags --- tests/Feature/Pages/Admin/EntriesEditTest.php | 61 +++++++++++++++++-- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/tests/Feature/Pages/Admin/EntriesEditTest.php b/tests/Feature/Pages/Admin/EntriesEditTest.php index 5214742..6bbb19e 100644 --- a/tests/Feature/Pages/Admin/EntriesEditTest.php +++ b/tests/Feature/Pages/Admin/EntriesEditTest.php @@ -13,6 +13,7 @@ use Sinnbeck\DomAssertions\Asserts\AssertElement; use Sinnbeck\DomAssertions\Asserts\AssertForm; use Sinnbeck\DomAssertions\Asserts\AssertSelect; +use function Pest\Laravel\delete; use function Pest\Laravel\get; use function Pest\Laravel\patch; @@ -55,17 +56,15 @@ it('has a delete link', function () { get(route('admin.entries.edit', $this->entry)) ->assertSee('', false); }); + it('has a dropdown for all auditions appropriate to the students grade', function () { // Arrange $auditions = Audition::factory()->count(5)->create(['minimum_grade' => 1, 'maximum_grade' => 20]); + /** @noinspection PhpPossiblePolymorphicInvocationInspection */ $oldAudition = Audition::factory()->create(['minimum_grade' => $this->entry->grade + 1]); + /** @noinspection PhpPossiblePolymorphicInvocationInspection */ $youngAudition = Audition::factory()->create(['maximum_grade' => $this->entry->grade - 1]); actAsAdmin(); - $auditionsArray = []; - foreach ($auditions as $audition) { - $auditionsArray[] = ['value' => $audition->id, 'text' => $audition->name]; - break; - } $response = get(route('admin.entries.edit', $this->entry)); $response->assertOk(); // Act & Assert @@ -129,6 +128,7 @@ it('does not let a normal user update an entry', function () { $newAudition = Audition::factory()->create(); actAsNormal(); // Act & Assert + /** @noinspection PhpUnhandledExceptionInspection */ patch(route('admin.entries.update', $this->entry), ['audition_id' => $newAudition->id]) ->assertSessionHasNoErrors() ->assertSessionHas('error', 'You are not authorized to perform this action') @@ -139,6 +139,7 @@ it('allows an admin to update an entry', function () { $newAudition = Audition::factory()->create(); actAsAdmin(); // Act & Assert + /** @noinspection PhpUnhandledExceptionInspection */ patch(route('admin.entries.update', $this->entry), ['audition_id' => $newAudition->id]) ->assertSessionHasNoErrors() ->assertSessionHas('success', 'Entry updated successfully') @@ -154,6 +155,7 @@ it('does not allow an administrator to update an entry in a published audition', actAsAdmin(); $this->entry->audition->addFlag('seats_published'); // Act & Assert + /** @noinspection PhpUnhandledExceptionInspection */ patch(route('admin.entries.update', $this->entry), ['audition_id' => $newAudition->id]) ->assertSessionHasNoErrors() ->assertSessionHas('error', 'Entries in auditions with seats published cannot be modified') @@ -171,6 +173,7 @@ it('does not allow an administrator to update an entry in an audition with publi actAsAdmin(); $this->entry->audition->addFlag('advancement_published'); // Act & Assert + /** @noinspection PhpUnhandledExceptionInspection */ patch(route('admin.entries.update', $this->entry), ['audition_id' => $newAudition->id]) ->assertSessionHasNoErrors() ->assertSessionHas('error', 'Entries in auditions with advancement results published cannot be modified') @@ -188,6 +191,7 @@ it('always sets for_seating to true if advancement is not enabled', function () $newAudition = Audition::factory()->create(); actAsAdmin(); // Act & Assert + /** @noinspection PhpUnhandledExceptionInspection */ patch(route('admin.entries.update', $this->entry), ['audition_id' => $newAudition->id]) ->assertSessionHasNoErrors() ->assertSessionHas('success', 'Entry updated successfully') @@ -216,3 +220,50 @@ it('displays scores', function () { $response->assertSee($subscore->name); } }); + +// Delete tests +it('does not allow a normal user to delete an entry', function () { + // Arrange + actAsNormal(); + // Act & Assert + /** @noinspection PhpUnhandledExceptionInspection */ + delete(route('admin.entries.destroy', $this->entry), ['_method' => 'DELETE']) + ->assertSessionHasNoErrors() + ->assertSessionHas('error', 'You are not authorized to perform this action') + ->assertRedirect(route('dashboard')); +}); +it('allows an admin to delete an entry', function () { + // Arrange + actAsAdmin(); + // Act & Assert + /** @noinspection PhpUnhandledExceptionInspection */ + delete(route('admin.entries.destroy', $this->entry), ['_method' => 'DELETE']) + ->assertSessionHasNoErrors() + ->assertSessionHas('success', 'Entry Deleted') + ->assertRedirect(route('admin.entries.index')); + expect(Entry::find($this->entry->id))->toBeNull(); +}); +it('does not allow an admin to delete an entry if that entries audition seats are published', function () { + // Arrange + actAsAdmin(); + // Act & Assert + $this->entry->audition->addFlag('seats_published'); + /** @noinspection PhpUnhandledExceptionInspection */ + delete(route('admin.entries.destroy', $this->entry), ['_method' => 'DELETE']) + ->assertSessionHasNoErrors() + ->assertSessionHas('error', 'Entries in auditions with seats published cannot be deleted') + ->assertRedirect(route('admin.entries.index')); + expect(Entry::find($this->entry->id))->not->toBeNull(); +}); +it('does not allow an admin to delete an entry if that entries advancement is published', function () { + // Arrange + actAsAdmin(); + // Act & Assert + $this->entry->audition->addFlag('advancement_published'); + /** @noinspection PhpUnhandledExceptionInspection */ + delete(route('admin.entries.destroy', $this->entry), ['_method' => 'DELETE']) + ->assertSessionHasNoErrors() + ->assertSessionHas('error', 'Entries in auditions with advancement results published cannot be deleted') + ->assertRedirect(route('admin.entries.index')); + expect(Entry::find($this->entry->id))->not->toBeNull(); +});