Create tests for app/actions/tabulation/UnpublishSeats
This commit is contained in:
parent
1253c18087
commit
157e2f496a
|
|
@ -1,180 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Tabulation;
|
||||
|
||||
use App\Actions\Entries\DoublerDecision;
|
||||
use App\Actions\Tabulation\CalculateEntryScore;
|
||||
use App\Actions\Tabulation\GetAuditionSeats;
|
||||
use App\Actions\Tabulation\RankAuditionEntries;
|
||||
use App\Exceptions\AuditionAdminException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Audition;
|
||||
use App\Services\AuditionService;
|
||||
use App\Services\DoublerService;
|
||||
use App\Services\EntryService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
use function redirect;
|
||||
|
||||
class SeatAuditionFormControllerOLD extends Controller
|
||||
{
|
||||
protected CalculateEntryScore $calc;
|
||||
protected DoublerService $doublerService;
|
||||
protected RankAuditionEntries $ranker;
|
||||
protected EntryService $entryService;
|
||||
protected AuditionService $auditionService;
|
||||
protected DoublerDecision $decider;
|
||||
|
||||
public function __construct(
|
||||
CalculateEntryScore $calc,
|
||||
RankAuditionEntries $ranker,
|
||||
DoublerService $doublerService,
|
||||
EntryService $entryService,
|
||||
AuditionService $auditionService,
|
||||
DoublerDecision $decider,
|
||||
) {
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
|
||||
use App\Actions\Tabulation\PublishSeats;
|
||||
use App\Actions\Tabulation\UnpublishSeats;
|
||||
use App\Models\Audition;
|
||||
use App\Models\Ensemble;
|
||||
use App\Models\Entry;
|
||||
use App\Models\Seat;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->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();
|
||||
});
|
||||
Loading…
Reference in New Issue