From bed4e0671e3863259deb2da64d6ae20b2fbb1fa8 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Tue, 1 Jul 2025 09:44:31 -0500 Subject: [PATCH] UpdateEntry action fully tested --- .../app/Actions/Entries/UpdateEntryTest.php | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/tests/Feature/app/Actions/Entries/UpdateEntryTest.php b/tests/Feature/app/Actions/Entries/UpdateEntryTest.php index 6cc237f..23e70fc 100644 --- a/tests/Feature/app/Actions/Entries/UpdateEntryTest.php +++ b/tests/Feature/app/Actions/Entries/UpdateEntryTest.php @@ -7,6 +7,7 @@ use App\Actions\Entries\UpdateEntry; use App\Exceptions\AuditionAdminException; use App\Models\Audition; use App\Models\AuditionFlag; +use App\Models\AuditLogEntry; use App\Models\Entry; use App\Models\Room; use App\Models\ScoringGuide; @@ -69,19 +70,23 @@ it('will not move to an audition for which the student is too young', function ( $newAudition = Audition::factory()->create([ 'event_id' => $this->entry->audition->event_id, 'minimum_grade' => 10, + 'maximum_grade' => 11, ]); $this->entry->student->update(['grade' => 9]); + dump('student grade: '.$this->entry->student->grade); + dump('new audition minimum: '.$newAudition->minimum_grade); ($this->entryScribe)($this->entry, ['audition_id' => $newAudition->id]); -})->throws(AuditionAdminException::class, 'The student is too young to enter that audition')->skip('test needs work'); +})->throws(AuditionAdminException::class, 'The student is too young to enter that audition'); it('will not move to an audition for which the student is too old', function () { $newAudition = Audition::factory()->create([ 'event_id' => $this->entry->audition->event_id, 'maximum_grade' => 8, + 'minimum_grade' => 7, ]); $this->entry->student->update(['grade' => 9]); ($this->entryScribe)($this->entry, ['audition_id' => $newAudition->id]); -})->throws(AuditionAdminException::class, 'The student is too old to enter that audition')->skip('test needs work'); +})->throws(AuditionAdminException::class, 'The student is too old to enter that audition'); it('will not change auditions for an entry with scores', function () { $scoreFaker = app(FakeScoresForEntry::class); @@ -194,3 +199,37 @@ it('cannot add forSeating if seating is published', function () { ($this->entryScribe)($this->entry, ['for_seating' => true]); })->throws(AuditionAdminException::class, 'Cannot add seating to an entry in an audition where seats are published'); + +it('logs changes', function () { + actAsAdmin(); + $originalEntry = Entry::find($this->entry->id); + $newAudition = Audition::factory()->create(['minimum_grade' => 9, 'maximum_grade' => 10, 'name' => 'Alphorn']); + ($this->entryScribe)($this->entry, ['audition' => $newAudition]); + $logEntry = AuditLogEntry::latest()->first(); + expect($logEntry->affected['auditions'])->toEqual([$originalEntry->audition_id, $newAudition->id]) + ->and($logEntry->affected['entries'])->toEqual([$this->entry->id]) + ->and($logEntry->affected['students'])->toEqual([$this->entry->student_id]) + ->and($logEntry->affected['schools'])->toEqual([$this->entry->student->school_id]) + ->and($logEntry->message)->toEqual('Changed entry '.$this->entry->id.' from '.$originalEntry->audition->name.' to '.$newAudition->name.'
'); + +}); + +it('will not change to a non-existent audition', function () { + $newAudition = Audition::factory()->make(); + ($this->entryScribe)($this->entry, ['audition' => $newAudition]); +})->throws(AuditionAdminException::class, 'Invalid audition provided'); + +it('wont change if we give it the same audition', function () { + ($this->entryScribe)($this->entry, ['audition' => $this->entry->audition]); + expect($this->entry->audition_id)->toBe($this->entry->audition->id); +}); + +it('wont change seating if we give the same value', function () { + ($this->entryScribe)($this->entry, ['for_seating' => 1]); + expect($this->entry->for_seating)->toBe($this->entry->for_seating); +}); + +it('wont change advancement if we give the same value', function () { + ($this->entryScribe)($this->entry, ['for_advancement' => 1]); + expect($this->entry->for_advancement)->toBe($this->entry->for_advancement); +});