create test for app/actions/tabulation/DoublerSync
This commit is contained in:
parent
6715c9346a
commit
0b54b57e41
|
|
@ -0,0 +1,75 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/** @noinspection PhpUnhandledExceptionInspection */
|
||||||
|
|
||||||
|
use App\Actions\Entries\CreateEntry;
|
||||||
|
use App\Actions\Tabulation\DoublerSync;
|
||||||
|
use App\Models\Audition;
|
||||||
|
use App\Models\Doubler;
|
||||||
|
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,
|
||||||
|
]);
|
||||||
|
$this->audition3 = \App\Models\Audition::factory()->create([
|
||||||
|
'minimum_grade' => 8, 'maximum_grade' => 8, 'event_id' => $this->event->id,
|
||||||
|
]);
|
||||||
|
$entryCreator = app(CreateEntry::class);
|
||||||
|
$this->entry1 = $entryCreator($this->student, $this->audition1);
|
||||||
|
$this->entry2 = $entryCreator($this->student, $this->audition2);
|
||||||
|
$this->entry3 = $entryCreator($this->student, $this->audition3);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can load doublers for a given event', function () {
|
||||||
|
$syncer = app(DoublerSync::class);
|
||||||
|
Doubler::truncate();
|
||||||
|
expect(Doubler::count())->toBe(0);
|
||||||
|
$syncer($this->event->id);
|
||||||
|
expect(Doubler::count())->toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can load doublers for all events', function () {
|
||||||
|
$newEvent = Event::factory()->create();
|
||||||
|
$newStudent = Student::factory()->create(['grade' => 8]);
|
||||||
|
$newAudition1 = Audition::factory()->create([
|
||||||
|
'minimum_grade' => 8, 'maximum_grade' => 8, 'event_id' => $newEvent->id,
|
||||||
|
]);
|
||||||
|
$newAudition2 = Audition::factory()->create([
|
||||||
|
'minimum_grade' => 8, 'maximum_grade' => 8, 'event_id' => $newEvent->id,
|
||||||
|
]);
|
||||||
|
$entryCreator = app(CreateEntry::class);
|
||||||
|
$entryCreator($newStudent, $newAudition1);
|
||||||
|
$entryCreator($newStudent, $newAudition2);
|
||||||
|
|
||||||
|
$syncer = app(DoublerSync::class);
|
||||||
|
Doubler::truncate();
|
||||||
|
expect(Doubler::count())->toBe(0);
|
||||||
|
$syncer();
|
||||||
|
expect(Doubler::count())->toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('marks an entry accepted if all others are declined', function () {
|
||||||
|
$syncer = app(DoublerSync::class);
|
||||||
|
$this->entry1->addFlag('declined');
|
||||||
|
Doubler::truncate();
|
||||||
|
expect(Doubler::count())->toBe(0);
|
||||||
|
$syncer($this->event->id);
|
||||||
|
expect(Doubler::count())->toBe(1);
|
||||||
|
$doubler = Doubler::first();
|
||||||
|
expect($doubler->accepted_entry)->toBenull;
|
||||||
|
$this->entry3->addFlag('declined');
|
||||||
|
Doubler::truncate();
|
||||||
|
$syncer($this->event->id);
|
||||||
|
$doubler->refresh();
|
||||||
|
expect($doubler->accepted_entry)->toBe($this->entry2->id);
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue