Test AuditionService
This commit is contained in:
parent
0eebd541a0
commit
10a1751019
|
|
@ -53,7 +53,6 @@ class AuditionService
|
||||||
|
|
||||||
return Cache::remember($cacheKey, 10, function () use ($audition) {
|
return Cache::remember($cacheKey, 10, function () use ($audition) {
|
||||||
$this->validateAudition($audition);
|
$this->validateAudition($audition);
|
||||||
|
|
||||||
return $audition->judges;
|
return $audition->judges;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,21 +3,24 @@
|
||||||
/** @noinspection PhpUnhandledExceptionInspection */
|
/** @noinspection PhpUnhandledExceptionInspection */
|
||||||
|
|
||||||
use App\Models\Audition;
|
use App\Models\Audition;
|
||||||
|
use App\Models\Room;
|
||||||
|
use App\Models\User;
|
||||||
use App\Services\AuditionService;
|
use App\Services\AuditionService;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
|
|
||||||
uses(RefreshDatabase::class);
|
uses(RefreshDatabase::class);
|
||||||
|
|
||||||
|
// getSubscores()
|
||||||
it('throws an exception when an invalid mode is requested', function () {
|
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);
|
$auditionService = App::make(AuditionService::class);
|
||||||
$this->expectException(\App\Exceptions\AuditionServiceException::class);
|
$this->expectException(\App\Exceptions\AuditionServiceException::class);
|
||||||
$auditionService->getSubscores(new Audition(), 'invalid_mode');
|
$auditionService->getSubscores(new Audition(), 'invalid_mode');
|
||||||
});
|
});
|
||||||
it('throws an exception when an invalid sort is requested', function () {
|
it('throws an exception when an invalid sort is requested', function () {
|
||||||
// Arrange
|
// Arrange
|
||||||
#$auditionService = new \App\Services\AuditionService();
|
//$auditionService = new \App\Services\AuditionService();
|
||||||
$auditionService = App::make(AuditionService::class);
|
$auditionService = App::make(AuditionService::class);
|
||||||
$this->expectException(\App\Exceptions\AuditionServiceException::class);
|
$this->expectException(\App\Exceptions\AuditionServiceException::class);
|
||||||
// Act
|
// 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 () {
|
it('throws an exception when an invalid audition is provided', function () {
|
||||||
// Arrange
|
// Arrange
|
||||||
#$auditionService = new \App\Services\AuditionService();
|
//$auditionService = new \App\Services\AuditionService();
|
||||||
$auditionService = App::make(AuditionService::class);
|
$auditionService = App::make(AuditionService::class);
|
||||||
$this->expectException(\App\Exceptions\AuditionServiceException::class);
|
$this->expectException(\App\Exceptions\AuditionServiceException::class);
|
||||||
$auditionService->getSubscores(new Audition(), 'seating', 'tiebreak');
|
$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 () {
|
it('gets subscores for an audition', function () {
|
||||||
// Arrange
|
// Arrange
|
||||||
loadSampleAudition();
|
loadSampleAudition();
|
||||||
#$auditionService = new \App\Services\AuditionService();
|
//$auditionService = new \App\Services\AuditionService();
|
||||||
$auditionService = App::make(AuditionService::class);
|
$auditionService = App::make(AuditionService::class);
|
||||||
// Act
|
// Act
|
||||||
$subscores = $auditionService->getSubscores(Audition::find(1000), 'seating', 'tiebreak');
|
$subscores = $auditionService->getSubscores(Audition::find(1000), 'seating', 'tiebreak');
|
||||||
// Assert
|
// 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();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue