Create tests for app/actions/fortify/CalculateAuditionScores

This commit is contained in:
Matt Young 2025-07-02 00:48:51 -05:00
parent b04bdc960b
commit 9556e7909a
2 changed files with 70 additions and 2 deletions

View File

@ -4,7 +4,6 @@ namespace App\Actions\Tabulation;
use App\Models\Audition; use App\Models\Audition;
use App\Models\Entry; use App\Models\Entry;
use Debugbar;
class CalculateAuditionScores class CalculateAuditionScores
{ {
@ -23,7 +22,6 @@ class CalculateAuditionScores
->with('audition.scoringGuide.subscores') ->with('audition.scoringGuide.subscores')
->get(); ->get();
foreach ($pending_entries as $entry) { foreach ($pending_entries as $entry) {
Debugbar::debug('Calculating scores for entry: '.$entry->id);
$totaler->__invoke($entry); $totaler->__invoke($entry);
} }
} }

View File

@ -0,0 +1,70 @@
<?php
use App\Actions\Tabulation\CalculateAuditionScores;
use App\Actions\Tabulation\EnterScore;
use App\Exceptions\ScoreEntryException;
use App\Models\Audition;
use App\Models\Entry;
use App\Models\EntryTotalScore;
use App\Models\SubscoreDefinition;
use App\Models\User;
use Database\Seeders\AuditionWithScoringGuideAndRoom;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
beforeEach(/**
* @throws ScoreEntryException
*/ function () {
(new AuditionWithScoringGuideAndRoom)->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);
});