diff --git a/app/Http/Controllers/Judging/BonusScoreEntryController.php b/app/Http/Controllers/Judging/BonusScoreEntryController.php index 447d160..f718847 100644 --- a/app/Http/Controllers/Judging/BonusScoreEntryController.php +++ b/app/Http/Controllers/Judging/BonusScoreEntryController.php @@ -12,16 +12,23 @@ use function redirect; class BonusScoreEntryController extends Controller { + /** + * Displays a form for a judge to enter a bonus score for an entry. + */ public function __invoke(Entry $entry) { + // We can't submit another bonus score for this entry if we have already submitted one. if (BonusScore::where('entry_id', $entry->id)->where('user_id', Auth::user()->id)->exists()) { - return redirect()->route('judging.bonusScore.EntryList', $entry->audition)->with('error', 'You have already judged that entry'); + return redirect()->route('judging.bonusScore.EntryList', $entry->audition)->with('error', + 'You have already judged that entry'); } + /** @var BonusScoreDefinition $bonusScore */ $bonusScore = $entry->audition->bonusScore()->first(); if (! $bonusScore->judges->contains(auth()->id())) { - return redirect()->route('judging.index')->with('error', 'You are not assigned to judge this entry'); + return redirect()->route('judging.index')->with('error', 'You are not assigned to judge that entry'); } + $maxScore = $bonusScore->max_score; $bonusName = $bonusScore->name; diff --git a/tests/Feature/app/Http/Controllers/Judging/BonusScoreEntryControllerTest.php b/tests/Feature/app/Http/Controllers/Judging/BonusScoreEntryControllerTest.php new file mode 100644 index 0000000..2512d95 --- /dev/null +++ b/tests/Feature/app/Http/Controllers/Judging/BonusScoreEntryControllerTest.php @@ -0,0 +1,72 @@ +create(); + $entry = Entry::factory()->forAudition($audition)->create(); + $judge = User::factory()->create(); + $bonusScoreDefinition = BonusScoreDefinition::factory()->create(); + $bonusScoreDefinition->auditions()->attach($audition); + $bonusScoreDefinition->judges()->attach($judge); + $response = $this->actingAs($judge)->get(route('judging.bonusScore.entry', $entry)); + $response->assertOk(); + $response->assertViewIs('judging.bonus_entry_score_sheet'); + $response->assertViewHas('entry', $entry); + $response->assertViewHas('maxScore', $bonusScoreDefinition->maximum_score); + $response->assertViewHas('bonusName', $bonusScoreDefinition->name); + $response->assertDontSee($entry->student->full_name()); +}); + +it('wont let us enter two scores for the same entry', function () { + $scoringGuide = ScoringGuide::factory()->create(); + $audition = Audition::factory()->create(); + $audition->update(['scoring_guide_id' => $scoringGuide->id]); + $entry = Entry::factory()->forAudition($audition)->create(); + $judge = User::factory()->create(); + $bonusScoreDefinition = BonusScoreDefinition::factory()->create(); + $bonusScoreDefinition->auditions()->attach($audition); + $bonusScoreDefinition->judges()->attach($judge); + BonusScore::create([ + 'entry_id' => $entry->id, + 'user_id' => $judge->id, + 'originally_scored_entry' => $entry->id, + 'score' => 28, + ]); + $response = $this->actingAs($judge)->get(route('judging.bonusScore.entry', $entry)); + $response->assertRedirect(route('judging.bonusScore.EntryList', $entry->audition)); + $response->assertSessionHas('error', 'You have already judged that entry'); +}); + +it('wont let a judge score an entry not assigned to them', function () { + $room = Room::factory()->create(); + $audition = Audition::factory()->create(); + $entry = Entry::factory()->forAudition($audition)->create(); + $judge = User::factory()->create(); + $room->judges()->attach($judge); + $bonusScoreDefinition = BonusScoreDefinition::factory()->create(); + $bonusScoreDefinition->auditions()->attach($audition); + $response = $this->actingAs($judge)->get(route('judging.bonusScore.entry', $entry)); + $response->assertRedirect(route('judging.index')); + $response->assertSessionHas('error', 'You are not assigned to judge that entry'); +}); + +it('bounces non-judge users to the dashboard', function () { + $audition = Audition::factory()->create(); + $entry = 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.entry', $entry)); + $response->assertRedirect(route('dashboard')); + $response->assertSessionHas('error', 'You are not assigned to judge.'); +});