71 lines
2.3 KiB
PHP
71 lines
2.3 KiB
PHP
<?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);
|
|
});
|