From a924b3bf51987431bfb2132dd0045846225aa621 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Wed, 2 Jul 2025 02:52:43 -0500 Subject: [PATCH] Create tests for app/actions/tabulation/EnterNoShow --- app/Actions/Tabulation/EnterNoShow.php | 9 ++ .../Actions/Tabulation/EnterNoShowTest.php | 87 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 tests/Feature/app/Actions/Tabulation/EnterNoShowTest.php diff --git a/app/Actions/Tabulation/EnterNoShow.php b/app/Actions/Tabulation/EnterNoShow.php index 3bd1718..3a26f4b 100644 --- a/app/Actions/Tabulation/EnterNoShow.php +++ b/app/Actions/Tabulation/EnterNoShow.php @@ -9,6 +9,8 @@ use App\Models\EntryTotalScore; use App\Models\ScoreSheet; use Illuminate\Support\Facades\DB; +use function auditionLog; + class EnterNoShow { /** @@ -51,6 +53,13 @@ class EnterNoShow $msg = 'No Show has been entered for '.$entry->audition->name.' #'.$entry->draw_number.' (ID: '.$entry->id.').'; } + $affected = [ + ['entries', [$entry->id]], + ['auditions', [$entry->audition_id]], + ['students', [$entry->student_id]], + ]; + auditionLog($msg, $affected); + return $msg; } } diff --git a/tests/Feature/app/Actions/Tabulation/EnterNoShowTest.php b/tests/Feature/app/Actions/Tabulation/EnterNoShowTest.php new file mode 100644 index 0000000..db4dc3d --- /dev/null +++ b/tests/Feature/app/Actions/Tabulation/EnterNoShowTest.php @@ -0,0 +1,87 @@ +run(); + SubscoreDefinition::where('id', '<', 900)->delete(); + $this->audition = Audition::first(); + $this->entry = Entry::factory()->create(['audition_id' => $this->audition->id]); + $this->rollTaker = app(EnterNoShow::class); +}); + +it('can enter a no-show', function () { + ($this->rollTaker)($this->entry); + expect($this->entry->hasFlag('no_show'))->toBeTrue(); +}); + +it('creates a log entry when entering a no-show', function () { + ($this->rollTaker)($this->entry); + $logEntry = \App\Models\AuditLogEntry::latest()->first(); + expect($logEntry->message)->toStartWith('No Show has been entered for'); +}); + +it('can enter a failed prelim', function () { + ($this->rollTaker)($this->entry, 'failprelim'); + expect($this->entry->hasFlag('failed_prelim'))->toBeTrue(); +}); + +it('creates a log entry when entering a failed prelim', function () { + ($this->rollTaker)($this->entry, 'failprelim'); + $logEntry = \App\Models\AuditLogEntry::latest()->first(); + expect($logEntry->message)->toStartWith('Failed prelim has been entered for'); +}); + +it('will not accept an invalid flag type', function () { + ($this->rollTaker)($this->entry, 'bazinga'); +})->throws(AuditionAdminException::class, 'Invalid flag type'); + +it('will not enter a no-show in an audition with published seats', function () { + $this->audition->addFlag('seats_published'); + ($this->rollTaker)($this->entry); +})->throws(AuditionAdminException::class, + 'Cannot enter a no-show for an entry in an audition where seats are published'); + +it('will not enter a no-show in an audition with published advancement', function () { + $this->audition->addFlag('advancement_published'); + ($this->rollTaker)($this->entry); +})->throws(AuditionAdminException::class, + 'Cannot enter a no-show for an entry in an audition where advancement is published'); + +it('deletes existing score sheets when marking a no show', function () { + $scribe = app(EnterScore::class); + $judge1 = User::factory()->create(); + $judge2 = User::factory()->create(); + $this->audition->judges()->attach([$judge1->id, $judge2->id]); + $scribe($judge1, $this->entry, [ + 1001 => 10, + 1002 => 11, + 1003 => 12, + 1004 => 13, + 1005 => 14, + ]); + $scribe($judge2, $this->entry, [ + 1001 => 10, + 1002 => 11, + 1003 => 12, + 1004 => 13, + 1005 => 14, + ]); + expect($this->entry->scoreSheets()->count())->toBe(2); + expect($this->entry->TotalScore()->count())->toBe(1); + ($this->rollTaker)($this->entry); + expect($this->entry->scoreSheets()->count())->toBe(0); + expect($this->entry->TotalScore()->count())->toBe(0); +});