add testValidity method to ScoreSheet model. Aimed to replace scoreSheetService::isScoreSheetValid
This commit is contained in:
parent
b09f1b13ca
commit
4963124d22
|
|
@ -48,4 +48,9 @@ class ScoreSheet extends Model
|
|||
return $this->subscores[$id]['score'] ?? false;
|
||||
// this function is used at resources/views/tabulation/entry_score_sheet.blade.php
|
||||
}
|
||||
|
||||
public function testValidity()
|
||||
{
|
||||
return $this->audition->judges->contains('id', $this->user_id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use App\Models\Audition;
|
||||
use App\Models\Entry;
|
||||
use App\Models\Room;
|
||||
use App\Models\ScoreSheet;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
|
@ -39,3 +40,13 @@ it('returns its audition', function () {
|
|||
it('can return a specified subscore', function () {
|
||||
expect($this->scoreSheet->getSubscore(2))->toEqual(68);
|
||||
});
|
||||
|
||||
it('can validate itself', function () {
|
||||
$room = Room::factory()->create();
|
||||
$this->entry->audition->update(['room_id' => $room->id]);
|
||||
$room->addJudge($this->judge);
|
||||
expect($this->scoreSheet->testValidity())->toBeTrue;
|
||||
$room->removeJudge($this->judge);
|
||||
$this->scoreSheet->refresh();
|
||||
expect($this->scoreSheet->testValidity())->toBeFalse;
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue