Tests for BonusScoreEntryController.php
This commit is contained in:
parent
5014e80fb1
commit
21c2af9172
|
|
@ -12,16 +12,23 @@ use function redirect;
|
||||||
|
|
||||||
class BonusScoreEntryController extends Controller
|
class BonusScoreEntryController extends Controller
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Displays a form for a judge to enter a bonus score for an entry.
|
||||||
|
*/
|
||||||
public function __invoke(Entry $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()) {
|
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 */
|
/** @var BonusScoreDefinition $bonusScore */
|
||||||
$bonusScore = $entry->audition->bonusScore()->first();
|
$bonusScore = $entry->audition->bonusScore()->first();
|
||||||
if (! $bonusScore->judges->contains(auth()->id())) {
|
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;
|
$maxScore = $bonusScore->max_score;
|
||||||
$bonusName = $bonusScore->name;
|
$bonusName = $bonusScore->name;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,72 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Audition;
|
||||||
|
use App\Models\BonusScore;
|
||||||
|
use App\Models\BonusScoreDefinition;
|
||||||
|
use App\Models\Entry;
|
||||||
|
use App\Models\Room;
|
||||||
|
use App\Models\ScoringGuide;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
|
||||||
|
uses(RefreshDatabase::class);
|
||||||
|
|
||||||
|
it('returns a form to enter a bonus score', function () {
|
||||||
|
$audition = Audition::factory()->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.');
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue