Create tests for app/Models/Doubler

This commit is contained in:
Matt Young 2025-07-03 10:26:13 -05:00
parent c1f7d58efb
commit 51b2b01359
1 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,53 @@
<?php
/** @noinspection PhpUnhandledExceptionInspection */
use App\Actions\Entries\CreateEntry;
use App\Models\Audition;
use App\Models\Doubler;
use App\Models\Entry;
use App\Models\Event;
use App\Models\Student;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->event = Event::factory()->create();
$this->student = Student::factory()->create(['grade' => 8]);
$this->audition1 = Audition::factory()->create([
'minimum_grade' => 8, 'maximum_grade' => 8, 'event_id' => $this->event->id,
]);
$this->audition2 = \App\Models\Audition::factory()->create([
'minimum_grade' => 8, 'maximum_grade' => 8, 'event_id' => $this->event->id,
]);
$entryCreator = app(CreateEntry::class);
$entryCreator($this->student, $this->audition1);
$entryCreator($this->student, $this->audition2);
});
it('can return its student', function () {
expect(Doubler::first()->student->id)->toEqual($this->student->id)
->and(Doubler::first()->student)->toBeInstanceOf(Student::class);
});
it('can return its event', function () {
expect(Doubler::first()->event->id)->toEqual($this->event->id)
->and(Doubler::first()->event)->toBeInstanceOf(Event::class);
});
it('can return its entries', function () {
expect(Doubler::first()->entries()->count())->toEqual(2)
->and(Doubler::first()->entries()->first())->toBeInstanceOf(Entry::class);
});
it('can find a doubler', function () {
expect(Doubler::findDoubler($this->student->id, $this->event->id))->toBeInstanceOf(Doubler::class);
});
it('can load doublers for a given event', function () {
Doubler::truncate();
expect(Doubler::count())->toBe(0);
Doubler::syncForEvent($this->event->id);
expect(Doubler::count())->toBe(1);
});