Test AuditionService

This commit is contained in:
Matt Young 2024-07-12 11:16:57 -05:00
parent 0eebd541a0
commit 10a1751019
2 changed files with 26 additions and 6 deletions

View File

@ -53,7 +53,6 @@ class AuditionService
return Cache::remember($cacheKey, 10, function () use ($audition) {
$this->validateAudition($audition);
return $audition->judges;
});
}

View File

@ -3,21 +3,24 @@
/** @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 = 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 = new \App\Services\AuditionService();
$auditionService = App::make(AuditionService::class);
$this->expectException(\App\Exceptions\AuditionServiceException::class);
// Act
@ -25,7 +28,7 @@ it('throws an exception when an invalid sort is requested', function () {
});
it('throws an exception when an invalid audition is provided', function () {
// Arrange
#$auditionService = new \App\Services\AuditionService();
//$auditionService = new \App\Services\AuditionService();
$auditionService = App::make(AuditionService::class);
$this->expectException(\App\Exceptions\AuditionServiceException::class);
$auditionService->getSubscores(new Audition(), 'seating', 'tiebreak');
@ -35,10 +38,28 @@ it('throws an exception when an invalid audition is provided', function () {
it('gets subscores for an audition', function () {
// Arrange
loadSampleAudition();
#$auditionService = new \App\Services\AuditionService();
//$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());
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();
});