Tests for BonusScoreEntryListController.php

This commit is contained in:
Matt Young 2025-07-10 03:39:56 -05:00
parent 21c2af9172
commit f946c157ab
2 changed files with 68 additions and 1 deletions

View File

@ -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'));

View File

@ -0,0 +1,64 @@
<?php
use App\Models\Audition;
use App\Models\BonusScoreDefinition;
use App\Models\Entry;
use App\Models\Room;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
it('returns a list of entries', function () {
$audition = Audition::factory()->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');
});