Tests for BonusScoreEntryListController.php
This commit is contained in:
parent
21c2af9172
commit
f946c157ab
|
|
@ -10,12 +10,15 @@ use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
class BonusScoreEntryListController extends Controller
|
class BonusScoreEntryListController extends Controller
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Lists entries for a bonus score so the judge may select one to score.
|
||||||
|
*/
|
||||||
public function __invoke(Audition $audition)
|
public function __invoke(Audition $audition)
|
||||||
{
|
{
|
||||||
/** @var BonusScoreDefinition $bonusScore */
|
/** @var BonusScoreDefinition $bonusScore */
|
||||||
$bonusScore = $audition->bonusScore()->first();
|
$bonusScore = $audition->bonusScore()->first();
|
||||||
if (! $bonusScore->judges->contains(auth()->id())) {
|
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 = $audition->entries()->orderBy('draw_number')->get();
|
||||||
$entries = $entries->reject(fn ($entry) => $entry->hasFlag('no_show'));
|
$entries = $entries->reject(fn ($entry) => $entry->hasFlag('no_show'));
|
||||||
|
|
|
||||||
|
|
@ -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');
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue