66 lines
2.5 KiB
PHP
66 lines
2.5 KiB
PHP
<?php
|
|
|
|
/** @noinspection PhpUnhandledExceptionInspection */
|
|
|
|
use App\Models\Audition;
|
|
use App\Models\Room;
|
|
use App\Models\User;
|
|
use App\Services\AuditionService;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\App;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
// getSubscores()
|
|
it('throws an exception when an invalid mode is requested', function () {
|
|
//$auditionService = new \App\Services\AuditionService();
|
|
$auditionService = App::make(AuditionService::class);
|
|
$this->expectException(\App\Exceptions\AuditionServiceException::class);
|
|
$auditionService->getSubscores(new Audition(), 'invalid_mode');
|
|
});
|
|
it('throws an exception when an invalid sort is requested', function () {
|
|
// Arrange
|
|
//$auditionService = new \App\Services\AuditionService();
|
|
$auditionService = App::make(AuditionService::class);
|
|
$this->expectException(\App\Exceptions\AuditionServiceException::class);
|
|
// Act
|
|
$auditionService->getSubscores(new Audition(), 'seating', 'invalid_sort');
|
|
});
|
|
it('throws an exception when an invalid audition is provided', function () {
|
|
// Arrange
|
|
//$auditionService = new \App\Services\AuditionService();
|
|
$auditionService = App::make(AuditionService::class);
|
|
$this->expectException(\App\Exceptions\AuditionServiceException::class);
|
|
$auditionService->getSubscores(new Audition(), 'seating', 'tiebreak');
|
|
// Act & Assert
|
|
|
|
});
|
|
it('gets subscores for an audition', function () {
|
|
// Arrange
|
|
loadSampleAudition();
|
|
//$auditionService = new \App\Services\AuditionService();
|
|
$auditionService = App::make(AuditionService::class);
|
|
// Act
|
|
$subscores = $auditionService->getSubscores(Audition::find(1000), 'seating', 'tiebreak');
|
|
// Assert
|
|
expect($subscores->toArray())->toBe(Audition::find(1000)->scoringGuide->subscores->where('for_seating',
|
|
true)->sortBy('tiebreak_order')->toArray());
|
|
});
|
|
// getJudges()
|
|
it('gets judges for an audition', function () {
|
|
loadSampleAudition();
|
|
$auditionService = App::make(AuditionService::class);
|
|
$judge = User::factory()->create();
|
|
$notJudge = User::factory()->create();
|
|
Room::find(1000)->addJudge($judge);
|
|
$testValue = $auditionService->getJudges(Audition::find(1000));
|
|
$test = $testValue->contains(function ($item) use ($judge) {
|
|
return $item->id === $judge->id;
|
|
});
|
|
$negativeTest = $testValue->contains(function ($item) use ($notJudge) {
|
|
return $item->id === $notJudge->id;
|
|
});
|
|
expect($test)->toBeTrue();
|
|
expect($negativeTest)->toBeFalse();
|
|
});
|