diff --git a/app/Http/Controllers/Admin/StudentController.php b/app/Http/Controllers/Admin/StudentController.php index 24d29a5..9916f64 100644 --- a/app/Http/Controllers/Admin/StudentController.php +++ b/app/Http/Controllers/Admin/StudentController.php @@ -6,10 +6,8 @@ use App\Http\Controllers\Controller; use App\Models\Audition; use App\Models\School; use App\Models\Student; -use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; -use Illuminate\Support\Facades\Log; use function abort; use function to_route; use function view; @@ -50,7 +48,7 @@ class StudentController extends Controller 'school_id' => ['required', 'exists:schools,id'], ]); - $student = Student::create([ + Student::create([ 'first_name' => request('first_name'), 'last_name' => request('last_name'), 'grade' => request('grade'), @@ -69,11 +67,12 @@ class StudentController extends Controller $maxGrade = Audition::max('maximum_grade'); $schools = School::orderBy('name')->get(); $student->loadCount('entries'); + return view('admin.students.edit', ['student' => $student, 'schools' => $schools, 'minGrade' => $minGrade, 'maxGrade' => $maxGrade]); } - public function update(Request $request, Student $student) + public function update(Student $student) { if (! Auth::user()->is_admin) { abort(403); @@ -105,8 +104,7 @@ class StudentController extends Controller public function destroy(Student $student) { - Log::debug('Deleting student '.$student->id); - if($student->entries()->count() > 0) { + if ($student->entries()->count() > 0) { return to_route('admin.students.index')->with('error', 'You cannot delete a student with entries.'); } $name = $student->full_name(); diff --git a/app/Http/Controllers/Tabulation/EntryFlagController.php b/app/Http/Controllers/Tabulation/EntryFlagController.php index 3a9b1b1..32da870 100644 --- a/app/Http/Controllers/Tabulation/EntryFlagController.php +++ b/app/Http/Controllers/Tabulation/EntryFlagController.php @@ -76,7 +76,7 @@ class EntryFlagController extends Controller 'Cannot enter a no-show for an entry in an audition where advancement is published'); } DB::table('score_sheets')->where('entry_id', $entry->id)->delete(); - + $entry->addFlag('no_show'); $msg = 'No Show has been entered for '.$entry->audition->name.' #'.$entry->draw_number.' (ID: '.$entry->id.').'; @@ -86,6 +86,18 @@ class EntryFlagController extends Controller public function undoNoShow(Entry $entry) { - // + if ($entry->audition->hasFlag('seats_published')) { + return to_route('entry-flags.noShowSelect')->with('error', + 'Cannot undo a no-show for an entry in an audition where seats are published'); + } + if ($entry->audition->hasFlag('advance_published')) { + return to_route('entry-flags.noShowSelect')->with('error', + 'Cannot undo a no-show for an entry in an audition where advancement is published'); + } + + $entry->removeFlag('no_show'); + + return to_route('entry-flags.noShowSelect')->with('success', + 'No Show status has been removed for '.$entry->audition->name.' #'.$entry->draw_number.' (ID: '.$entry->id.').'); } } diff --git a/database/factories/EnsembleFactory.php b/database/factories/EnsembleFactory.php index a0b950c..4e85c3f 100644 --- a/database/factories/EnsembleFactory.php +++ b/database/factories/EnsembleFactory.php @@ -2,10 +2,12 @@ namespace Database\Factories; +use App\Models\Ensemble; +use App\Models\Event; use Illuminate\Database\Eloquent\Factories\Factory; /** - * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Ensemble> + * @extends Factory */ class EnsembleFactory extends Factory { @@ -17,8 +19,8 @@ class EnsembleFactory extends Factory public function definition(): array { return [ - 'name' => $this->faker->name, - 'event_id' => \App\Models\Event::factory(), + 'name' => $this->faker->words(4, true), + 'event_id' => Event::factory(), 'code' => $this->faker->randomLetter().$this->faker->randomLetter, 'rank' => $this->faker->numberBetween(1, 10), ]; diff --git a/tests/Feature/Pages/Tabulation/noShowEnterAndCancelTest.php b/tests/Feature/Pages/Tabulation/noShowEnterTest.php similarity index 95% rename from tests/Feature/Pages/Tabulation/noShowEnterAndCancelTest.php rename to tests/Feature/Pages/Tabulation/noShowEnterTest.php index 51d3bac..fd16205 100644 --- a/tests/Feature/Pages/Tabulation/noShowEnterAndCancelTest.php +++ b/tests/Feature/Pages/Tabulation/noShowEnterTest.php @@ -13,12 +13,14 @@ it('only allows an admin or tab user to enter a no-show', function () { post(route('entry-flags.enterNoShow', $entry)) ->assertRedirect(route('home')); actAsAdmin(); + /** @noinspection PhpUnhandledExceptionInspection */ post(route('entry-flags.enterNoShow', $entry)) ->assertSessionHasNoErrors() ->assertSessionHas('success', 'No Show has been entered for '.$entry->audition->name.' #'.$entry->draw_number.' (ID: '.$entry->id.').') ->assertRedirect(route('entry-flags.noShowSelect')); actAsTab(); + /** @noinspection PhpUnhandledExceptionInspection */ post(route('entry-flags.enterNoShow', $entry)) ->assertSessionHasNoErrors() ->assertSessionHas('success', diff --git a/tests/Feature/Pages/Tabulation/noShowUndoTest.php b/tests/Feature/Pages/Tabulation/noShowUndoTest.php new file mode 100644 index 0000000..cd5723c --- /dev/null +++ b/tests/Feature/Pages/Tabulation/noShowUndoTest.php @@ -0,0 +1,55 @@ +create(); + $entry->addFlag('no_show'); + delete(route('entry-flags.undoNoShow', $entry)) + ->assertRedirect(route('home')); + actAsAdmin(); + /** @noinspection PhpUnhandledExceptionInspection */ + delete(route('entry-flags.undoNoShow', $entry)) + ->assertSessionHasNoErrors() + ->assertSessionHas('success', + 'No Show status has been removed for '.$entry->audition->name.' #'.$entry->draw_number.' (ID: '.$entry->id.').') + ->assertRedirect(route('entry-flags.noShowSelect')); + actAsTab(); + /** @noinspection PhpUnhandledExceptionInspection */ + delete(route('entry-flags.undoNoShow', $entry)) + ->assertSessionHasNoErrors() + ->assertSessionHas('success', + 'No Show status has been removed for '.$entry->audition->name.' #'.$entry->draw_number.' (ID: '.$entry->id.').') + ->assertRedirect(route('entry-flags.noShowSelect')); +}); +it('will not undo a no-show flag for an entry in a published audition', function () { + $entry1 = Entry::factory()->create(); + $entry2 = Entry::factory()->create(); + $entry1->addFlag('no_show'); + $entry2->addFlag('no_show'); + $entry1->audition->addFlag('seats_published'); + $entry2->audition->addFlag('advance_published'); + actAsAdmin(); + delete(route('entry-flags.undoNoShow', $entry1)) + ->assertRedirect(route('entry-flags.noShowSelect')) + ->assertSessionHas('error', 'Cannot undo a no-show for an entry in an audition where seats are published'); + delete(route('entry-flags.undoNoShow', $entry2)) + ->assertRedirect(route('entry-flags.noShowSelect')) + ->assertSessionHas('error', + 'Cannot undo a no-show for an entry in an audition where advancement is published'); +}); + +it('removes a no_show flag to the entry', function () { + // Arrange + $entry = Entry::factory()->create(); + $entry->addFlag('no_show'); + // Act & Assert + actAsAdmin(); + delete(route('entry-flags.undoNoShow', $entry)); + expect(Entry::find($entry->id)->hasFlag('no_show'))->toBeFalse(); +});