54 lines
1.8 KiB
PHP
54 lines
1.8 KiB
PHP
<?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);
|
|
});
|