progress on tests

This commit is contained in:
Matt Young 2024-07-04 01:56:44 -05:00
parent ec28cffaf3
commit c373995039
4 changed files with 150 additions and 19 deletions

View File

@ -12,6 +12,7 @@ use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use function compact; use function compact;
use function to_route;
class EntryController extends Controller class EntryController extends Controller
{ {
@ -62,12 +63,14 @@ class EntryController extends Controller
$entries = $entries->paginate(10); $entries = $entries->paginate(10);
return view('admin.entries.index', ['entries' => $entries, return view('admin.entries.index', [
'entries' => $entries,
'auditions' => $auditions, 'auditions' => $auditions,
'schools' => $schools, 'schools' => $schools,
'minGrade' => $minGrade, 'minGrade' => $minGrade,
'maxGrade' => $maxGrade, 'maxGrade' => $maxGrade,
'filters' => $filters]); 'filters' => $filters,
]);
} }
public function create() public function create()
@ -106,9 +109,16 @@ class EntryController extends Controller
public function edit(Entry $entry) public function edit(Entry $entry)
{ {
if (! Auth::user()->is_admin) { if ($entry->audition->hasFlag('seats_published')) {
abort(403); return to_route('admin.entries.index')->with('error',
'Entries in auditions with seats published cannot be modified');
} }
if ($entry->audition->hasFlag('advancement_published')) {
return to_route('admin.entries.index')->with('error',
'Entries in auditions with advancement results published cannot be modified');
}
$students = Student::with('school')->orderBy('last_name')->orderBy('first_name')->get(); $students = Student::with('school')->orderBy('last_name')->orderBy('first_name')->get();
$auditions = Audition::orderBy('score_order')->get(); $auditions = Audition::orderBy('score_order')->get();
$scores = $entry->scoreSheets()->get(); $scores = $entry->scoreSheets()->get();
@ -119,8 +129,14 @@ class EntryController extends Controller
public function update(Request $request, Entry $entry) public function update(Request $request, Entry $entry)
{ {
if (! Auth::user()->is_admin) { if ($entry->audition->hasFlag('seats_published')) {
abort(403); return to_route('admin.entries.index')->with('error',
'Entries in auditions with seats published cannot be modified');
}
if ($entry->audition->hasFlag('advancement_published')) {
return to_route('admin.entries.index')->with('error',
'Entries in auditions with advancement results published cannot be modified');
} }
$validData = request()->validate([ $validData = request()->validate([
'student_id' => ['required', 'exists:students,id'], 'student_id' => ['required', 'exists:students,id'],
@ -142,8 +158,14 @@ class EntryController extends Controller
public function destroy(Request $request, Entry $entry) public function destroy(Request $request, Entry $entry)
{ {
if (! Auth::user()->is_admin) { if ($entry->audition->hasFlag('seats_published')) {
abort(403); return to_route('admin.entries.index')->with('error',
'Entries in auditions with seats published cannot be deleted');
}
if ($entry->audition->hasFlag('advancement_published')) {
return to_route('admin.entries.index')->with('error',
'Entries in auditions with advancement results published cannot be deleted');
} }
if (Seat::where('entry_id', $entry->id)->exists()) { if (Seat::where('entry_id', $entry->id)->exists()) {
return redirect()->route('admin.entries.index')->with('error', 'Cannot delete an entry that is seated'); return redirect()->route('admin.entries.index')->with('error', 'Cannot delete an entry that is seated');

View File

@ -5,15 +5,9 @@
Edit Entry #{{ $entry->id }} Edit Entry #{{ $entry->id }}
<x-slot:right_side> <x-slot:right_side>
@if(! Seat::where('entry_id', $entry->id)->exists()) <x-delete-resource-modal action="{{route('admin.entries.destroy',$entry->id)}}" title="Delete entry #{{ $entry->id }}">
<form method="POST" action="{{ route('admin.entries.destroy',['entry' => $entry->id]) }}"> Confirm you would like to delete entry #{{$entry->id}} by {{$entry->student->full_name()}} on {{$entry->audition->name}}.
@csrf </x-delete-resource-modal>
@method('DELETE')
<x-form.red-trash-button type="submit" />
</form>
@else
Seated: {{ $entry->seat->ensemble->name }} #{{ $entry->seat->seat }}
@endif
</x-slot:right_side> </x-slot:right_side>
</x-card.heading> </x-card.heading>

View File

@ -0,0 +1,115 @@
<?php
use App\Models\Audition;
use App\Models\Entry;
use App\Settings;
use Illuminate\Foundation\Testing\RefreshDatabase;
use function Pest\Laravel\get;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->entry = Entry::factory()->create();
});
it('does not respond to an ordinary user', function () {
actAsNormal();
get(route('admin.entries.edit', $this->entry))
->assertRedirect(route('dashboard'));
});
it('does not respond to a guest', function () {
// Act & Assert
get(route('admin.entries.edit', $this->entry))
->assertRedirect(route('home'));
});
it('does not respond if the audition is published', function () {
// Arrange
actAsAdmin();
$this->entry->audition->addFlag('seats_published');
get(route('admin.entries.edit', $this->entry))
->assertRedirect(route('admin.entries.index'))
->assertSessionHas('error', 'Entries in auditions with seats published cannot be modified');
});
it('does not respond if advancement for the audition is published', function () {
// Arrange
actAsAdmin();
$this->entry->audition->addFlag('advancement_published');
get(route('admin.entries.edit', $this->entry))
->assertRedirect(route('admin.entries.index'))
->assertSessionHas('error', 'Entries in auditions with advancement results published cannot be modified');
});
it('has a delete link', function () {
// Arrange
actAsAdmin();
// Act & Assert
get(route('admin.entries.edit', $this->entry))
->assertSee('<input type="hidden" name="_method" value="DELETE">', false);
});
it('has a dropdown for all auditions', function () {
// Arrange
$auditions = Audition::factory()->count(5)->create();
actAsAdmin();
$response = get(route('admin.entries.edit', $this->entry));
foreach ($auditions as $audition) {
$response->assertSeeInOrder([
'option',
'value=',
$audition->id,
'option',
], false);
$response->assertSeeInOrder([
'option',
'value=',
$this->entry->audition->id,
'selected',
'option',
], false);
}
});
it('shows checkboxes for entry types only if advancement is enabled', function () {
actAsAdmin();
get(route('admin.entries.edit', $this->entry))
->assertSee('Enter for '.auditionSetting('auditionAbbreviation'))
->assertSee('Enter for '.auditionSetting('advanceTo'));
Settings::set('advanceTo', '');
get(route('admin.entries.edit', $this->entry))
->assertDontSee('Enter for '.auditionSetting('auditionAbbreviation'))
->assertDontSee('Enter for '.auditionSetting('advanceTo'));
});
it('properly checks boxes based on entries settings', function () {
actAsAdmin();
get(route('admin.entries.edit', $this->entry))
->assertSeeInOrder([
'input',
'name=',
'for_seating',
'checked',
auditionSetting('auditionAbbreviation'),
])
->assertSeeInOrder([
'input',
'name=',
'for_advancement',
'checked',
auditionSetting('advanceTo'),
]);
$entry2 = Entry::factory()->advanceOnly()->create();
get(route('admin.entries.edit', $entry2))
->assertSeeInOrder([
'input',
'name=',
'for_seating',
'checked',
auditionSetting('auditionAbbreviation'),
])
->assertSeeInOrder([
'input',
'name=',
'for_advancement',
'checked',
auditionSetting('advanceTo'),
]);
});
// Submission tests

View File

@ -60,7 +60,7 @@ function actAsNormal()
actingAs(User::factory()->create()); actingAs(User::factory()->create());
} }
uses(TestCase::class)->beforeEach(function () { uses()->beforeEach(function () {
Settings::set('auditionName', 'Somewhere Band Directors Association'); Settings::set('auditionName', 'Somewhere Band Directors Association');
Settings::set('auditionAbbreviation', 'SBDA'); Settings::set('auditionAbbreviation', 'SBDA');
Settings::set('registrationCode', 'secret'); Settings::set('registrationCode', 'secret');
@ -75,5 +75,5 @@ uses(TestCase::class)->beforeEach(function () {
Settings::set('payment_city', 'Washington'); Settings::set('payment_city', 'Washington');
Settings::set('payment_state', 'DC'); Settings::set('payment_state', 'DC');
Settings::set('payment_zip', '20500'); Settings::set('payment_zip', '20500');
}); })->in('Feature');