AuditionsEdit Page Tests
This commit is contained in:
parent
af9bc432a3
commit
916baa2c93
|
|
@ -160,16 +160,12 @@ class AuditionController extends Controller
|
|||
|
||||
public function destroy(Audition $audition)
|
||||
{
|
||||
if (! Auth::user()->is_admin) {
|
||||
abort(403);
|
||||
}
|
||||
// if($audition->entries->count() > 0) abort(403, 'Cannot delete an audition with entries.'
|
||||
if ($audition->entries->count() > 0) {
|
||||
return redirect()->route('admin.auditions.index')->with('error', 'Cannot delete an audition with entries.');
|
||||
}
|
||||
$audition->delete();
|
||||
|
||||
return redirect('/admin/auditions');
|
||||
return to_route('admin.auditions.index')->with('success', 'Audition deleted successfully');
|
||||
}
|
||||
|
||||
public function prepareDraw()
|
||||
|
|
|
|||
|
|
@ -69,9 +69,6 @@ class AuditionService
|
|||
|
||||
public function clearCache(): void
|
||||
{
|
||||
if (App::environment('local')) {
|
||||
Session::flash('success', 'Audition Cache Cleared');
|
||||
}
|
||||
Cache::forget($this->cacheKey);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,13 @@
|
|||
<x-card.card class="max-w-lg mx-auto">
|
||||
<x-card.heading>
|
||||
Edit Audition
|
||||
<x-slot:right_side>
|
||||
@if($audition->entries->count() == 0)
|
||||
<x-delete-resource-modal title="Delete Audition {{ $audition->name }}" action="{{ route('admin.auditions.destroy', $audition) }}">
|
||||
Please confirm that you would like to delete the audition {{ $audition->name }}. This action cannot be undone.
|
||||
</x-delete-resource-modal>
|
||||
@endif
|
||||
</x-slot:right_side>
|
||||
{{-- TODO implement a way to update multiple auditions as once --}}
|
||||
</x-card.heading>
|
||||
<x-form.form method="PATCH" action="/admin/auditions/{{ $audition->id }}">
|
||||
|
|
@ -39,18 +46,13 @@
|
|||
|
||||
</x-form.body-grid>
|
||||
<x-form.footer submit-button-text="Update Audition" class="pb-4 !justify-between">
|
||||
<div>
|
||||
@if($audition->entries->count() == 0)
|
||||
<x-form.red-trash-button form="deleteResource" size="20"></x-form.red-trash-button>
|
||||
@endif
|
||||
</div>
|
||||
<div></div>
|
||||
<div>
|
||||
<x-form.button>Edit Audition</x-form.button>
|
||||
</div>
|
||||
</x-form.footer>
|
||||
|
||||
</x-form.form>
|
||||
<x-form.delete-form action="/admin/auditions/{{ $audition->id }}"></x-form.delete-form>
|
||||
</x-card.card>
|
||||
</x-layout.app>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,11 @@
|
|||
@php
|
||||
/**
|
||||
* @var int $size=20 Size of the icon
|
||||
* @var string $title Title of the modal
|
||||
* @var string $method='DELETE' method used by the form
|
||||
* @var string $action action used for the form
|
||||
*/
|
||||
@endphp
|
||||
@props(['size' => 20,'title','method'=>'DELETE','action'])
|
||||
|
||||
<div
|
||||
|
|
|
|||
|
|
@ -0,0 +1,118 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Audition;
|
||||
use App\Models\Entry;
|
||||
use App\Models\Event;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
use function Pest\Laravel\delete;
|
||||
use function Pest\Laravel\get;
|
||||
use function Pest\Laravel\patch;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
beforeEach(function () {
|
||||
$this->audition = Audition::factory()->seatingOnly()->create();
|
||||
$this->newEvent = Event::factory()->create();
|
||||
$this->changes = [
|
||||
'event_id' => $this->newEvent->id,
|
||||
'name' => 'New Name',
|
||||
'entry_deadline' => '1978-01-01',
|
||||
'entry_fee' => 10000,
|
||||
'minimum_grade' => 3,
|
||||
'maximum_grade' => 8,
|
||||
'for_advancement' => 'on',
|
||||
];
|
||||
});
|
||||
|
||||
it('allows only an admin to manage auditions', function () {
|
||||
get(route('admin.auditions.edit', $this->audition))
|
||||
->assertRedirect(route('home'));
|
||||
actAsNormal();
|
||||
get(route('admin.auditions.edit', $this->audition))
|
||||
->assertRedirect('/dashboard')
|
||||
->assertSessionHas('error', 'You are not authorized to perform this action');
|
||||
actasAdmin();
|
||||
get(route('admin.auditions.edit', $this->audition))
|
||||
->assertOk();
|
||||
});
|
||||
it('shows necessary fields', function () {
|
||||
// Arrange
|
||||
actAsAdmin();
|
||||
// Act & Assert
|
||||
get(route('admin.auditions.edit', $this->audition))
|
||||
->assertOk()
|
||||
->assertSee(route('admin.auditions.store'))
|
||||
->assertSee('name="event_id"', false)
|
||||
->assertSee('name="name"', false)
|
||||
->assertSee('name="entry_deadline"', false)
|
||||
->assertSee('name="entry_fee"', false)
|
||||
->assertSee('name="minimum_grade"', false)
|
||||
->assertSee('name="maximum_grade"', false)
|
||||
->assertSee('name="for_seating"', false)
|
||||
->assertSee('name="for_advancement"', false);
|
||||
});
|
||||
it('allows an administrator to modify auditions', function () {
|
||||
actAsAdmin();
|
||||
// Act
|
||||
$response = patch(route('admin.auditions.update', $this->audition), $this->changes);
|
||||
// Assert
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$response->assertRedirect(route('admin.auditions.index'))
|
||||
->assertSessionHasNoErrors()
|
||||
->assertSessionHas('success', 'Audition updated successfully');
|
||||
$checkAudition = Audition::find($this->audition->id);
|
||||
expect($checkAudition->event_id)->toBe($this->newEvent->id)
|
||||
->and($checkAudition->name)->toBe($this->changes['name'])
|
||||
->and($checkAudition->entry_deadline)->toBe($this->changes['entry_deadline'])
|
||||
->and($checkAudition->entry_fee)->toBe($this->changes['entry_fee'] * 100)
|
||||
->and($checkAudition->minimum_grade)->toBe($this->changes['minimum_grade'])
|
||||
->and($checkAudition->maximum_grade)->toBe($this->changes['maximum_grade'])
|
||||
->and($checkAudition->for_seating)->toBe(0)
|
||||
->and($checkAudition->for_advancement)->toBe(1);
|
||||
});
|
||||
it('does not allow a normal user or guest to create an audition', function () {
|
||||
$preCheck = Audition::find($this->audition->id);
|
||||
// Act & Assert
|
||||
patch(route('admin.auditions.update', $this->audition), $this->changes)
|
||||
->assertRedirect(route('home'));
|
||||
actAsNormal();
|
||||
patch(route('admin.auditions.update', $this->audition), $this->changes)
|
||||
->assertRedirect('/dashboard')
|
||||
->assertSessionHas('error', 'You are not authorized to perform this action');
|
||||
$checkAudition = Audition::find($this->audition->id);
|
||||
expect($checkAudition)->toEqual($preCheck);
|
||||
});
|
||||
it('has a delete function for an audition that has no entries', function () {
|
||||
// Arrange
|
||||
actAsAdmin();
|
||||
// Act & Assert
|
||||
get(route('admin.auditions.edit', $this->audition))
|
||||
->assertOk()
|
||||
->assertSee(route('admin.auditions.destroy', $this->audition));
|
||||
});
|
||||
it('does not allow guests or normal users to delete an audition', function () {
|
||||
delete(route('admin.auditions.destroy', $this->audition))
|
||||
->assertRedirect(route('home'));
|
||||
actAsNormal();
|
||||
delete(route('admin.auditions.destroy', $this->audition))
|
||||
->assertRedirect('/dashboard')
|
||||
->assertSessionHas('error', 'You are not authorized to perform this action');
|
||||
});
|
||||
it('does not allow the deletion of an audition with entries', function () {
|
||||
// Arrange
|
||||
actAsAdmin();
|
||||
Entry::factory()->create(['audition_id' => $this->audition->id]);
|
||||
// Act & Assert
|
||||
delete(route('admin.auditions.destroy', $this->audition))
|
||||
->assertRedirect(route('admin.auditions.index'))
|
||||
->assertSessionHas('error', 'Cannot delete an audition with entries.');
|
||||
});
|
||||
it('allows an administrator to delete an audition that has no entries', function () {
|
||||
// Arrange
|
||||
actAsAdmin();
|
||||
// Act & Assert
|
||||
delete(route('admin.auditions.destroy', $this->audition))
|
||||
->assertRedirect(route('admin.auditions.index'))
|
||||
->assertSessionHas('success', 'Audition deleted successfully');
|
||||
expect(Audition::find($this->audition->id))->toBeNull();
|
||||
});
|
||||
Loading…
Reference in New Issue