auditionadmin/tests/Feature/Services/ScoreServiceTest.php

45 lines
1.4 KiB
PHP

<?php
use App\Models\Audition;
use App\Models\Entry;
use App\Models\Room;
use App\Models\ScoreSheet;
use App\Models\User;
use App\Services\ScoreService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use function Pest\Laravel\artisan;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->scoreService = new ScoreService();
});
it('can record a score', function () {
// Arrange
// run the seeder AuditionWithScoringGuideAndRoom
artisan('db:seed', ['--class' => 'AuditionWithScoringGuideAndRoom']);
// Act & Assert
expect(Audition::find(1000)->name)->toBe('Test Audition');
});
it('can check if an entry is fully scored', function () {
$room = Room::factory()->create();
$judges = User::factory()->count(2)->create();
$judges->each(fn ($judge) => $room->addJudge($judge));
$audition = Audition::factory()->create(['room_id' => $room->id]);
$entry = Entry::factory()->create(['audition_id' => $audition->id]);
expect($this->scoreService->isEntryFullyScored($entry))->toBeFalse();
ScoreSheet::create([
'user_id' => $judges->first()->id,
'entry_id' => $entry->id,
'subscores' => 7,
]);
expect($this->scoreService->isEntryFullyScored($entry))->toBeFalse();
ScoreSheet::create([
'user_id' => $judges->last()->id,
'entry_id' => $entry->id,
'subscores' => 7,
]);
expect($this->scoreService->isEntryFullyScored($entry))->toBeTrue();
});