prelim definition relationship tests.
This commit is contained in:
parent
a7d1776c44
commit
7c0504ea89
|
|
@ -10,6 +10,7 @@ use Illuminate\Database\Eloquent\Model;
|
|||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
use function in_array;
|
||||
|
|
@ -165,6 +166,11 @@ class Audition extends Model
|
|||
return $this->hasMany(Seat::class);
|
||||
}
|
||||
|
||||
public function prelimDefinition(): HasOne
|
||||
{
|
||||
return $this->hasOne(PrelimDefinition::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnoreStart
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ namespace App\Models;
|
|||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class prelim_definition extends Model
|
||||
class PrelimDefinition extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'audition_id',
|
||||
|
|
@ -13,7 +13,7 @@ return new class extends Migration
|
|||
{
|
||||
Schema::create('prelim_definitions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignIdFor(Audition::class)->constrained()->cascadeOnDelete()->cascadeOnUpdate();
|
||||
$table->foreignIdFor(Audition::class)->unique()->constrained()->cascadeOnDelete()->cascadeOnUpdate();
|
||||
$table->foreignIdFor(Room::class)->nullable()->constrained()->nullOnDelete()->cascadeOnUpdate();
|
||||
$table->integer('order_in_room')->nullable();
|
||||
$table->foreignIdFor(ScoringGuide::class)->nullable()->constrained()->nullOnDelete()->cascadeOnUpdate();
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
use App\Models\Audition;
|
||||
use App\Models\Ensemble;
|
||||
use App\Models\Entry;
|
||||
use App\Models\PrelimDefinition;
|
||||
use App\Models\Room;
|
||||
use App\Models\ScoringGuide;
|
||||
use App\Models\Seat;
|
||||
|
|
@ -198,3 +199,16 @@ it('can return its seats if any exits', function () {
|
|||
expect($this->audition->seats()->count())->toBe(5)
|
||||
->and($this->audition->seats->first())->toBeInstanceOf(Seat::class);
|
||||
});
|
||||
|
||||
it('returns null if a prelim definition is requested and none exists', function () {
|
||||
expect($this->audition->prelimDefinition)->toBeNull();
|
||||
});
|
||||
|
||||
it('can return its prelim definition if one exists', function () {
|
||||
|
||||
$prelimDefinition = PrelimDefinition::create([
|
||||
'audition_id' => $this->audition->id,
|
||||
'passing_score' => 72,
|
||||
]);
|
||||
expect($this->audition->prelimDefinition->passing_score)->toEqual(72);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Audition;
|
||||
use App\Models\PrelimDefinition;
|
||||
use App\Models\Room;
|
||||
use App\Models\ScoringGuide;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->audition = Audition::factory()->create();
|
||||
$this->prelim = PrelimDefinition::create([
|
||||
'audition_id' => $this->audition->id,
|
||||
'passing_score' => 80,
|
||||
]);
|
||||
});
|
||||
|
||||
it('can provide its audition', function () {
|
||||
expect($this->prelim->audition->name)->toEqual($this->audition->name);
|
||||
});
|
||||
|
||||
it('can return its room if one is set', function () {
|
||||
$room = Room::factory()->create();
|
||||
$this->prelim->room()->associate($room);
|
||||
expect($this->prelim->room->name)->toEqual($room->name);
|
||||
});
|
||||
|
||||
it('returns null if no room is set', function () {
|
||||
expect($this->prelim->room)->toBeNull();
|
||||
});
|
||||
|
||||
it('returns its scoring guide if one is set', function () {
|
||||
$guide = ScoringGuide::factory()->create();
|
||||
$this->prelim->scoringGuide()->associate($guide);
|
||||
expect($this->prelim->scoringGuide->name)->toEqual($guide->name);
|
||||
});
|
||||
|
||||
it('returns null if no scoring guide is set', function () {
|
||||
expect($this->prelim->scoringGuide)->toBeNull();
|
||||
});
|
||||
Loading…
Reference in New Issue