From 157e2f496a7b72d338c7bda0495ebc9228e7939a Mon Sep 17 00:00:00 2001 From: Matt Young Date: Wed, 2 Jul 2025 11:52:59 -0500 Subject: [PATCH] Create tests for app/actions/tabulation/UnpublishSeats --- .../SeatAuditionFormControllerOLD.php | 180 ------------------ .../Actions/Tabulation/UnpublishSeatsTest.php | 82 ++++++++ 2 files changed, 82 insertions(+), 180 deletions(-) delete mode 100644 app/Http/Controllers/Tabulation/SeatAuditionFormControllerOLD.php create mode 100644 tests/Feature/app/Actions/Tabulation/UnpublishSeatsTest.php diff --git a/app/Http/Controllers/Tabulation/SeatAuditionFormControllerOLD.php b/app/Http/Controllers/Tabulation/SeatAuditionFormControllerOLD.php deleted file mode 100644 index 9e27ec4..0000000 --- a/app/Http/Controllers/Tabulation/SeatAuditionFormControllerOLD.php +++ /dev/null @@ -1,180 +0,0 @@ -calc = $calc; - $this->ranker = $ranker; - $this->doublerService = $doublerService; - $this->entryService = $entryService; - $this->auditionService = $auditionService; - $this->decider = $decider; - } - - public function __invoke(Request $request, Audition $audition) - { - // If a seating proposal was posted, deal wth it - if ($request->method() == 'POST' && $request->input('ensembleAccept')) { - $requestedEnsembleAccepts = $request->input('ensembleAccept'); - } else { - $requestedEnsembleAccepts = false; - } - - // Deal with a mass no-show request - if ($request->input('mass-no-show')) { - $entries = $audition->entries()->forSeating()->withCount('scoreSheets')->with('flags')->get(); - foreach ($entries as $entry) { - if ($entry->scoreSheets_count == 0 && ! $entry->hasFlag('no_show')) { - $entry->addFlag('no_show'); - } - Cache::forget('entryScore-'.$entry->id.'-seating'); - Cache::forget('entryScore-'.$entry->id.'-advancement'); - } - Cache::forget('audition'.$audition->id.'seating'); - Cache::forget('audition'.$audition->id.'advancement'); - } - - $entryData = []; - $entries = $this->ranker->rank('seating', $audition); - - // Deal with mass decline doubler request - if ($request->input('decline-below')) { - Cache::forget('audition'.$audition->id.'seating'); - - $changes_made = false; - foreach ($entries as $entry) { - $doublerData = $this->doublerService->entryDoublerData($entry); - if ($doublerData && ! $entry->hasFlag('declined') && $entry->rank > $request->input('decline-below')) { - try { - $this->decider->decline($entry); - $changes_made = true; - } catch (AuditionAdminException $e) { - return redirect()->back()->with('error', $e->getMessage()); - } - } - } - if ($changes_made) { - $cache_key = 'event'.$audition->event_id.'doublers-seating'; - Cache::forget($cache_key); - - return redirect()->back(); - } - } - - $entries->load('student.school'); - $entries->load('student.doublerRequests'); - $seatable = [ - 'allScored' => true, - 'doublersResolved' => true, - ]; - foreach ($entries as $entry) { - $totalScoreColumn = 'No Score'; - $fullyScored = false; - if ($entry->score_totals) { - $totalScoreColumn = $entry->score_totals[0] >= 0 ? $entry->score_totals[0] : $entry->score_message; - $fullyScored = $entry->score_totals[0] >= 0; - } - // No Shows are fully scored - if ($entry->hasFlag('no_show')) { - $fullyScored = true; - } - $doublerData = $this->doublerService->entryDoublerData($entry); - - $entryData[] = [ - 'rank' => $entry->rank, - 'id' => $entry->id, - 'studentName' => $entry->student->full_name(), - 'schoolName' => $entry->student->school->name, - 'drawNumber' => $entry->draw_number, - 'totalScore' => $totalScoreColumn, - 'fullyScored' => $fullyScored, - 'hasBonusScores' => $entry->bonus_scores_count > 0, - 'doubleData' => $doublerData, - 'doublerRequest' => $entry->student->doublerRequests()->where('event_id', - $audition->event_id)->first()?->request, - ]; - // If this entries double decision isn't made, block seating - if ($doublerData && $doublerData[$entry->id]['status'] == 'undecided') { - $seatable['doublersResolved'] = false; - } - // If entry is unscored, block seating - if (! $fullyScored) { - $seatable['allScored'] = false; - } - } - - $rightPanel = $this->pickRightPanel($audition, $seatable); - $seatableEntries = []; - if ($seatable['doublersResolved'] && $seatable['allScored']) { - $seatableEntries = $entries->reject(function ($entry) { - if ($entry->hasFlag('declined')) { - return true; - } - if ($entry->hasFlag('no_show')) { - return true; - } - if ($entry->hasFlag('failed_prelim')) { - return true; - } - - return false; - }); - } - - return view('tabulation.auditionSeating', - compact('entryData', 'audition', 'rightPanel', 'seatableEntries', 'requestedEnsembleAccepts')); - } - - protected function pickRightPanel(Audition $audition, array $seatable) - { - if ($audition->hasFlag('seats_published')) { - $resultsWindow = new GetAuditionSeats; - $rightPanel['view'] = 'tabulation.auditionSeating-show-published-seats'; - $rightPanel['data'] = $resultsWindow($audition); - - return $rightPanel; - } - if ($seatable['allScored'] == false || $seatable['doublersResolved'] == false) { - $rightPanel['view'] = 'tabulation.auditionSeating-unable-to-seat-card'; - $rightPanel['data'] = $seatable; - - return $rightPanel; - } - - $rightPanel['view'] = 'tabulation.auditionSeating-right-complete-not-published'; - $rightPanel['data'] = $this->auditionService->getSeatingLimits($audition); - - return $rightPanel; - } -} diff --git a/tests/Feature/app/Actions/Tabulation/UnpublishSeatsTest.php b/tests/Feature/app/Actions/Tabulation/UnpublishSeatsTest.php new file mode 100644 index 0000000..a2d9d9e --- /dev/null +++ b/tests/Feature/app/Actions/Tabulation/UnpublishSeatsTest.php @@ -0,0 +1,82 @@ +audition = Audition::factory()->create(['minimum_grade' => 1, 'maximum_grade' => 14]); + $this->windEnsemble = Ensemble::create([ + 'event_id' => $this->audition->event_id, + 'name' => 'Wind Ensemble', + 'code' => 'we', + 'rank' => 1, + ]); + $this->alternates = Ensemble::create([ + 'event_id' => $this->audition->event_id, + 'name' => 'Alternates', + 'code' => 'alt', + 'rank' => 2, + ]); + $this->entries = Entry::factory()->count(10)->create(['audition_id' => $this->audition->id]); + $this->seatingArray = [ + 1 => [ + 'ensemble_id' => $this->windEnsemble->id, + 'audition_id' => $this->audition->id, + 'entry_id' => $this->entries[0]->id, + 'seat' => 1, + ], + 2 => [ + 'ensemble_id' => $this->windEnsemble->id, + 'audition_id' => $this->audition->id, + 'entry_id' => $this->entries[1]->id, + 'seat' => 2, + ], + 3 => [ + 'ensemble_id' => $this->windEnsemble->id, + 'audition_id' => $this->audition->id, + 'entry_id' => $this->entries[2]->id, + 'seat' => 3, + ], + 4 => [ + 'ensemble_id' => $this->alternates->id, + 'audition_id' => $this->audition->id, + 'entry_id' => $this->entries[3]->id, + 'seat' => 1, + ], + 5 => [ + 'ensemble_id' => $this->alternates->id, + 'audition_id' => $this->audition->id, + 'entry_id' => $this->entries[4]->id, + 'seat' => 2, + ], + ]; + $this->publisher = app(PublishSeats::class); + $this->unpublisher = app(UnpublishSeats::class); + ($this->publisher)($this->audition, $this->seatingArray); + $this->get(route('results')); +}); + +it('marks an auditions seats unpublished', function () { + ($this->unpublisher)($this->audition); + expect($this->audition->hasFlag('seats_published'))->toBeFalse(); +}); + +it('removes seats from the ensembles', function () { + ($this->unpublisher)($this->audition); + expect(Seat::where('audition_id', $this->audition->id)->count())->toBe(0); +}); + +it('clears results and set list cache', function () { + ($this->unpublisher)($this->audition); + expect(Cache::has('publicResultsPage'))->toBeFalse() + ->and(Cache::has('resultsSeatList'))->toBeFalse(); +});