auditionadmin/tests/Feature/Actions/CalculateScoreSheetTotalTes...

73 lines
2.8 KiB
PHP

<?php
/** @noinspection PhpUnhandledExceptionInspection */
use App\Actions\Tabulation\CalculateScoreSheetTotal;
use App\Exceptions\TabulationException;
use App\Models\Entry;
use App\Models\Room;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->calculator = app(CalculateScoreSheetTotal::class);
});
it('throws an exception if an invalid mode is called for', function () {
$calculator = app(CalculateScoreSheetTotal::class);
$calculator('anything', Entry::factory()->create(), User::factory()->create());
})->throws(TabulationException::class, 'Invalid mode requested. Mode must be seating or advancement');
it('throws an exception if an invalid judge is provided', function () {
$calculator = app(CalculateScoreSheetTotal::class);
$calculator('seating', Entry::factory()->create(), User::factory()->make());
})->throws(TabulationException::class, 'Invalid judge provided');
it('throws an exception if an invalid entry is provided', function () {
$calculator = app(CalculateScoreSheetTotal::class);
$calculator('advancement', Entry::factory()->make(), User::factory()->create());
})->throws(TabulationException::class, 'Invalid entry provided');
it('throws an exception if the specified judge has not scored the entry', function () {
// Arrange
$calculator = app(CalculateScoreSheetTotal::class);
// Act
$calculator('seating', Entry::factory()->create(), User::factory()->create());
//Assert
})->throws(TabulationException::class, 'No score sheet by that judge for that entry');
it('correctly calculates final score for seating', function () {
loadSampleAudition();
$judge = User::factory()->create();
Room::find(1000)->addJudge($judge);
$entry = Entry::factory()->create(['audition_id' => 1000]);
$scores = [
1001 => 50,
1002 => 60,
1003 => 70,
1004 => 80,
1005 => 90,
];
enterScore($judge, $entry, $scores);
$calculator = app(CalculateScoreSheetTotal::class);
$total = $calculator('seating', $entry, $judge);
expect($total[0])->toBe(68.75);
$expectedArray = [68.75, 80, 60, 70, 50];
expect($total)->toBe($expectedArray);
});
it('correctly calculates final score for advancement', function () {
loadSampleAudition();
$judge = User::factory()->create();
Room::find(1000)->addJudge($judge);
$entry = Entry::factory()->create(['audition_id' => 1000]);
$scores = [
1001 => 50,
1002 => 60,
1003 => 70,
1004 => 80,
1005 => 90,
];
enterScore($judge, $entry, $scores);
$calculator = app(CalculateScoreSheetTotal::class);
$total = $calculator('advancement', $entry, $judge);
expect($total[0])->toBe(73.75);
$expectedArray = [73.75, 90, 80, 60, 70];
expect($total)->toBe($expectedArray);
});