From 0b54b57e41017dc38176d503eaf9d7baeff556d5 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Fri, 4 Jul 2025 11:49:31 -0500 Subject: [PATCH] create test for app/actions/tabulation/DoublerSync --- .../Actions/Tabulation/DoublerSyncTest.php | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 tests/Feature/app/Actions/Tabulation/DoublerSyncTest.php diff --git a/tests/Feature/app/Actions/Tabulation/DoublerSyncTest.php b/tests/Feature/app/Actions/Tabulation/DoublerSyncTest.php new file mode 100644 index 0000000..4abfe4f --- /dev/null +++ b/tests/Feature/app/Actions/Tabulation/DoublerSyncTest.php @@ -0,0 +1,75 @@ +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); +});