175 lines
5.6 KiB
PHP
175 lines
5.6 KiB
PHP
<?php
|
|
|
|
use App\Actions\Tabulation\CheckPrelimResult;
|
|
use App\Actions\Tabulation\EnterPrelimScore;
|
|
use App\Exceptions\AuditionAdminException;
|
|
use App\Models\Entry;
|
|
use App\Models\PrelimDefinition;
|
|
use App\Models\PrelimScoreSheet;
|
|
use App\Models\Room;
|
|
use App\Models\ScoringGuide;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
$this->tabulator = app(CheckPrelimResult::class);
|
|
});
|
|
|
|
it('throws an exception if the provided entry does not exist', function () {
|
|
$entry = Entry::factory()->make();
|
|
($this->tabulator)($entry);
|
|
})->throws(AuditionAdminException::class, 'Entry does not exist');
|
|
|
|
it('throws an exception if the entries audition does not have a prelim', function () {
|
|
$entry = Entry::factory()->create();
|
|
($this->tabulator)($entry);
|
|
})->throws(AuditionAdminException::class, 'Entry does not have a prelim');
|
|
|
|
it('does not change an existing decision unless forced', function () {
|
|
$entry = Entry::factory()->create();
|
|
PrelimDefinition::create([
|
|
'audition_id' => $entry->audition_id,
|
|
'passing_score' => 80,
|
|
]);
|
|
$entry->addFlag('failed_prelim');
|
|
$result = ($this->tabulator)($entry);
|
|
expect($result)->toBe('noChange');
|
|
|
|
$entry2 = Entry::factory()->create(['audition_id' => $entry->audition_id]);
|
|
$entry2->addFlag('passed_prelim');
|
|
$result = ($this->tabulator)($entry);
|
|
expect($result)->toBe('noChange');
|
|
});
|
|
|
|
it('doesnt make a decision if there are no judges assigned', function () {
|
|
$entry = Entry::factory()->create();
|
|
PrelimDefinition::create([
|
|
'audition_id' => $entry->audition_id,
|
|
'passing_score' => 80,
|
|
]);
|
|
$result = ($this->tabulator)($entry);
|
|
expect($result)->toBe('noJudgesAssigned');
|
|
});
|
|
|
|
it('doesnt make a decision if there are insufficient scores', function () {
|
|
$prelimRoom = Room::factory()->create();
|
|
$judge1 = User::factory()->create();
|
|
$judge2 = User::factory()->create();
|
|
$prelimRoom->addJudge($judge1);
|
|
$prelimRoom->addJudge($judge2);
|
|
$prelimScoringGuide = ScoringGuide::factory()->create();
|
|
$entry = Entry::factory()->create();
|
|
PrelimDefinition::create([
|
|
'audition_id' => $entry->audition_id,
|
|
'passing_score' => 80,
|
|
'room_id' => $prelimRoom->id,
|
|
'scoring_guide_id' => $prelimScoringGuide->id,
|
|
]);
|
|
$result = ($this->tabulator)($entry);
|
|
expect($result)->toBe('missing2scores');
|
|
app(EnterPrelimScore::class)($judge1, $entry, [
|
|
1 => 50,
|
|
2 => 50,
|
|
3 => 50,
|
|
4 => 50,
|
|
5 => 50,
|
|
]);
|
|
$result = ($this->tabulator)($entry);
|
|
expect($result)->toBe('missing1scores');
|
|
});
|
|
|
|
it('correctly identifies passing entries', function () {
|
|
$prelimRoom = Room::factory()->create();
|
|
$judge1 = User::factory()->create();
|
|
$judge2 = User::factory()->create();
|
|
$prelimRoom->addJudge($judge1);
|
|
$prelimRoom->addJudge($judge2);
|
|
$prelimScoringGuide = ScoringGuide::factory()->create();
|
|
$entry = Entry::factory()->create();
|
|
PrelimDefinition::create([
|
|
'audition_id' => $entry->audition_id,
|
|
'passing_score' => 80,
|
|
'room_id' => $prelimRoom->id,
|
|
'scoring_guide_id' => $prelimScoringGuide->id,
|
|
]);
|
|
PrelimScoreSheet::create([
|
|
'entry_id' => $entry->id,
|
|
'user_id' => $judge1->id,
|
|
'subscores' => [],
|
|
'total' => 85,
|
|
]);
|
|
PrelimScoreSheet::create([
|
|
'entry_id' => $entry->id,
|
|
'user_id' => $judge2->id,
|
|
'subscores' => [],
|
|
'total' => 75,
|
|
]);
|
|
$result = ($this->tabulator)($entry);
|
|
expect($result)->toBe('markedPassed');
|
|
});
|
|
|
|
it('correctly identifies failing entries', function () {
|
|
$prelimRoom = Room::factory()->create();
|
|
$judge1 = User::factory()->create();
|
|
$judge2 = User::factory()->create();
|
|
$prelimRoom->addJudge($judge1);
|
|
$prelimRoom->addJudge($judge2);
|
|
$prelimScoringGuide = ScoringGuide::factory()->create();
|
|
$entry = Entry::factory()->create();
|
|
PrelimDefinition::create([
|
|
'audition_id' => $entry->audition_id,
|
|
'passing_score' => 81,
|
|
'room_id' => $prelimRoom->id,
|
|
'scoring_guide_id' => $prelimScoringGuide->id,
|
|
]);
|
|
PrelimScoreSheet::create([
|
|
'entry_id' => $entry->id,
|
|
'user_id' => $judge1->id,
|
|
'subscores' => [],
|
|
'total' => 85,
|
|
]);
|
|
PrelimScoreSheet::create([
|
|
'entry_id' => $entry->id,
|
|
'user_id' => $judge2->id,
|
|
'subscores' => [],
|
|
'total' => 75,
|
|
]);
|
|
$result = ($this->tabulator)($entry);
|
|
expect($result)->toBe('markedFailed');
|
|
});
|
|
|
|
it('can force a recalculation', function () {
|
|
$prelimRoom = Room::factory()->create();
|
|
$judge1 = User::factory()->create();
|
|
$judge2 = User::factory()->create();
|
|
$prelimRoom->addJudge($judge1);
|
|
$prelimRoom->addJudge($judge2);
|
|
$prelimScoringGuide = ScoringGuide::factory()->create();
|
|
$entry = Entry::factory()->create();
|
|
$entry->addFlag('failed_prelim');
|
|
PrelimDefinition::create([
|
|
'audition_id' => $entry->audition_id,
|
|
'passing_score' => 80,
|
|
'room_id' => $prelimRoom->id,
|
|
'scoring_guide_id' => $prelimScoringGuide->id,
|
|
]);
|
|
PrelimScoreSheet::create([
|
|
'entry_id' => $entry->id,
|
|
'user_id' => $judge1->id,
|
|
'subscores' => [],
|
|
'total' => 85,
|
|
]);
|
|
PrelimScoreSheet::create([
|
|
'entry_id' => $entry->id,
|
|
'user_id' => $judge2->id,
|
|
'subscores' => [],
|
|
'total' => 75,
|
|
]);
|
|
$result = ($this->tabulator)($entry);
|
|
expect($result)->toBe('noChange');
|
|
$result = ($this->tabulator)($entry, true);
|
|
expect($result)->toBe('markedPassed');
|
|
});
|