From 9556e7909a3586fa1c002d1aedfdade635889a0a Mon Sep 17 00:00:00 2001 From: Matt Young Date: Wed, 2 Jul 2025 00:48:51 -0500 Subject: [PATCH] Create tests for app/actions/fortify/CalculateAuditionScores --- .../Tabulation/CalculateAuditionScores.php | 2 - .../CalculateAuditionScoresTest.php | 70 +++++++++++++++++++ 2 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 tests/Feature/app/Actions/Tabulation/CalculateAuditionScoresTest.php diff --git a/app/Actions/Tabulation/CalculateAuditionScores.php b/app/Actions/Tabulation/CalculateAuditionScores.php index 72d774c..b04aa87 100644 --- a/app/Actions/Tabulation/CalculateAuditionScores.php +++ b/app/Actions/Tabulation/CalculateAuditionScores.php @@ -4,7 +4,6 @@ namespace App\Actions\Tabulation; use App\Models\Audition; use App\Models\Entry; -use Debugbar; class CalculateAuditionScores { @@ -23,7 +22,6 @@ class CalculateAuditionScores ->with('audition.scoringGuide.subscores') ->get(); foreach ($pending_entries as $entry) { - Debugbar::debug('Calculating scores for entry: '.$entry->id); $totaler->__invoke($entry); } } diff --git a/tests/Feature/app/Actions/Tabulation/CalculateAuditionScoresTest.php b/tests/Feature/app/Actions/Tabulation/CalculateAuditionScoresTest.php new file mode 100644 index 0000000..ecdf75c --- /dev/null +++ b/tests/Feature/app/Actions/Tabulation/CalculateAuditionScoresTest.php @@ -0,0 +1,70 @@ +run(); + SubscoreDefinition::where('id', '<', 900)->delete(); + $this->audition = Audition::first(); + $this->judge1 = User::factory()->create(); + $this->judge2 = User::factory()->create(); + $this->audition->judges()->attach([$this->judge1->id, $this->judge2->id]); + $this->entry1 = Entry::factory()->create(['audition_id' => $this->audition->id]); + $this->entry2 = Entry::factory()->create(['audition_id' => $this->audition->id]); + $scribe = app(EnterScore::class); + $scribe($this->judge1, $this->entry1, [ + 1001 => 10, + 1002 => 11, + 1003 => 12, + 1004 => 13, + 1005 => 14, + ]); + $scribe($this->judge1, $this->entry2, [ + 1001 => 15, + 1002 => 16, + 1003 => 17, + 1004 => 18, + 1005 => 19, + ]); + $scribe($this->judge2, $this->entry1, [ + 1001 => 20, + 1002 => 21, + 1003 => 22, + 1004 => 23, + 1005 => 24, + ]); + $scribe($this->judge2, $this->entry2, [ + 1001 => 25, + 1002 => 26, + 1003 => 27, + 1004 => 28, + 1005 => 29, + ]); +}); + +it('results in a total score for all entries', function () { + $calculator = app(CalculateAuditionScores::class); + EntryTotalScore::where('entry_id', $this->entry1->id)->delete(); + $calculator($this->audition); + $this->entry1->refresh(); + $this->entry2->refresh(); + expect($this->entry1->totalScore)->toBeInstanceOf(EntryTotalScore::class) + ->and($this->entry2->totalScore)->toBeInstanceOf(EntryTotalScore::class) + ->and($this->entry1->totalScore->seating_total)->toBe(16.875) + ->and($this->entry2->totalScore->seating_total)->toBe(21.875) + ->and($this->entry1->totalScore->advancement_total)->toBe(17.375) + ->and($this->entry2->totalScore->advancement_total)->toBe(22.375); +});