From f946c157ab5269b6b66086add3fc97a1017115e7 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Thu, 10 Jul 2025 03:39:56 -0500 Subject: [PATCH] Tests for BonusScoreEntryListController.php --- .../Judging/BonusScoreEntryListController.php | 5 +- .../BonusScoreEntryListControllerTest.php | 64 +++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 tests/Feature/app/Http/Controllers/Judging/BonusScoreEntryListControllerTest.php diff --git a/app/Http/Controllers/Judging/BonusScoreEntryListController.php b/app/Http/Controllers/Judging/BonusScoreEntryListController.php index ae5f30c..6412888 100644 --- a/app/Http/Controllers/Judging/BonusScoreEntryListController.php +++ b/app/Http/Controllers/Judging/BonusScoreEntryListController.php @@ -10,12 +10,15 @@ use Illuminate\Support\Facades\Auth; class BonusScoreEntryListController extends Controller { + /** + * Lists entries for a bonus score so the judge may select one to score. + */ public function __invoke(Audition $audition) { /** @var BonusScoreDefinition $bonusScore */ $bonusScore = $audition->bonusScore()->first(); if (! $bonusScore->judges->contains(auth()->id())) { - return redirect()->route('dashboard')->with('error', 'You are not assigned to judge this bonus score'); + return redirect()->route('dashboard')->with('error', 'You are not assigned to judge that bonus score'); } $entries = $audition->entries()->orderBy('draw_number')->get(); $entries = $entries->reject(fn ($entry) => $entry->hasFlag('no_show')); diff --git a/tests/Feature/app/Http/Controllers/Judging/BonusScoreEntryListControllerTest.php b/tests/Feature/app/Http/Controllers/Judging/BonusScoreEntryListControllerTest.php new file mode 100644 index 0000000..7ddfb05 --- /dev/null +++ b/tests/Feature/app/Http/Controllers/Judging/BonusScoreEntryListControllerTest.php @@ -0,0 +1,64 @@ +create(); + $entries = Entry::factory()->count(5)->forAudition($audition)->create(); + $scoredEntry = Entry::factory()->forAudition($audition)->create(); + $judge = User::factory()->create(); + DB::table('bonus_scores')->insert([ + 'entry_id' => $scoredEntry->id, + 'user_id' => $judge->id, + 'originally_scored_entry' => $scoredEntry->id, + 'score' => 28, + ]); + $bonusScoreDefinition = BonusScoreDefinition::factory()->create(); + $bonusScoreDefinition->auditions()->attach($audition); + $bonusScoreDefinition->judges()->attach($judge); + + $response = $this->actingAs($judge)->get(route('judging.bonusScore.EntryList', $audition)); + $response->assertOk(); + $response->assertViewIs('judging.bonus_score_entry_list'); + $response->assertViewHas('audition', $audition); + expect($response->viewData('entries'))->toHaveCount(6); + expect($response->viewData('scores'))->toHaveCount(1); + foreach ($entries as $entry) { + $response->assertSee($entry->audition->name.' '.$entry->draw_number); + $response->assertDontSee($entry->student->full_name()); + $response->assertDontSee($entry->student->full_name(true)); + $response->assertDontSee($entry->student->school->name); + } +}); + +it('will not let us in if we are not a judge', function () { + $audition = Audition::factory()->create(); + $entries = Entry::factory()->count(5)->forAudition($audition)->create(); + $scoredEntry = Entry::factory()->forAudition($audition)->create(); + $judge = User::factory()->create(); + $bonusScoreDefinition = BonusScoreDefinition::factory()->create(); + $bonusScoreDefinition->auditions()->attach($audition); + $response = $this->actingAs($judge)->get(route('judging.bonusScore.EntryList', $audition)); + $response->assertRedirect(route('dashboard')); + $response->assertSessionHas('error', 'You are not assigned to judge.'); +}); + +it('will not let us in if we are not assigned to the audition', function () { + $audition = Audition::factory()->create(); + $entries = Entry::factory()->count(5)->forAudition($audition)->create(); + $judge = User::factory()->create(); + $bonusScoreDefinition = BonusScoreDefinition::factory()->create(); + $bonusScoreDefinition->auditions()->attach($audition); + $room = Room::factory()->create(); + $room->judges()->attach($judge); + $response = $this->actingAs($judge)->get(route('judging.bonusScore.EntryList', $audition)); + $response->assertRedirect(route('dashboard')); + $response->assertSessionHas('error', 'You are not assigned to judge that bonus score'); +});