Tests for BonusScoreRecordController.php
This commit is contained in:
parent
f946c157ab
commit
118a465bb7
|
|
@ -3,7 +3,7 @@
|
||||||
namespace App\Http\Controllers\Judging;
|
namespace App\Http\Controllers\Judging;
|
||||||
|
|
||||||
use App\Actions\Tabulation\EnterBonusScore;
|
use App\Actions\Tabulation\EnterBonusScore;
|
||||||
use App\Exceptions\ScoreEntryException;
|
use App\Exceptions\AuditionAdminException;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Entry;
|
use App\Models\Entry;
|
||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
|
|
@ -14,15 +14,17 @@ class BonusScoreRecordController extends Controller
|
||||||
public function __invoke(Entry $entry)
|
public function __invoke(Entry $entry)
|
||||||
{
|
{
|
||||||
$enterBonusScore = App::make(EnterBonusScore::class);
|
$enterBonusScore = App::make(EnterBonusScore::class);
|
||||||
|
$max = $entry->audition->bonusScore()->first()->max_score;
|
||||||
$validData = request()->validate([
|
$validData = request()->validate([
|
||||||
'score' => 'required|integer',
|
'score' => 'required|integer|min:0|max:'.$max,
|
||||||
]);
|
]);
|
||||||
try {
|
try {
|
||||||
$enterBonusScore(Auth::user(), $entry, $validData['score']);
|
$enterBonusScore(Auth::user(), $entry, $validData['score']);
|
||||||
} catch (ScoreEntryException $ex) {
|
} catch (AuditionAdminException $ex) {
|
||||||
return redirect()->back()->with('error', 'Score Entry Error - '.$ex->getMessage());
|
return redirect(route('dashboard'))->with('error', 'Score Entry Error - '.$ex->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->route('judging.bonusScore.EntryList', $entry->audition)->with('Score Recorded Successfully');
|
return redirect()->route('judging.bonusScore.EntryList', $entry->audition)->with('success',
|
||||||
|
'Score Recorded Successfully');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,85 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Audition;
|
||||||
|
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('records a bonus score', function () {
|
||||||
|
$audition = Audition::factory()->create();
|
||||||
|
$entry = Entry::factory()->forAudition($audition)->create();
|
||||||
|
$judge = User::factory()->create();
|
||||||
|
$bonusScoreDefinition = BonusScoreDefinition::factory()->create(['max_score' => 100]);
|
||||||
|
$bonusScoreDefinition->auditions()->attach($audition);
|
||||||
|
$bonusScoreDefinition->judges()->attach($judge);
|
||||||
|
|
||||||
|
// BonusScoreObserver needs regular scoring set up
|
||||||
|
$sg = ScoringGuide::factory()->create();
|
||||||
|
$audition->update(['scoring_guide_id' => $sg->id]);
|
||||||
|
|
||||||
|
$response = $this->actingAs($judge)->post(route('judging.bonusScores.recordScore', $entry), [
|
||||||
|
'score' => 28,
|
||||||
|
]);
|
||||||
|
$response->assertRedirect(route('judging.bonusScore.EntryList', $audition))
|
||||||
|
->assertSessionHas('success', 'Score Recorded Successfully');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sends us to the dashboard if we arent a judge', function () {
|
||||||
|
$audition = Audition::factory()->create();
|
||||||
|
$entry = Entry::factory()->forAudition($audition)->create();
|
||||||
|
$judge = User::factory()->create();
|
||||||
|
$bonusScoreDefinition = BonusScoreDefinition::factory()->create(['max_score' => 100]);
|
||||||
|
$bonusScoreDefinition->auditions()->attach($audition);
|
||||||
|
|
||||||
|
// BonusScoreObserver needs regular scoring set up
|
||||||
|
$sg = ScoringGuide::factory()->create();
|
||||||
|
$audition->update(['scoring_guide_id' => $sg->id]);
|
||||||
|
|
||||||
|
$response = $this->actingAs($judge)->post(route('judging.bonusScores.recordScore', $entry), [
|
||||||
|
'score' => 28,
|
||||||
|
]);
|
||||||
|
$response->assertRedirect(route('dashboard'))
|
||||||
|
->assertSessionHas('error', 'You are not assigned to judge.');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sends us to judging home if we arent assigned to the audition', function () {
|
||||||
|
$audition = Audition::factory()->create();
|
||||||
|
$entry = Entry::factory()->forAudition($audition)->create();
|
||||||
|
$judge = User::factory()->create();
|
||||||
|
$bonusScoreDefinition = BonusScoreDefinition::factory()->create(['max_score' => 100]);
|
||||||
|
$bonusScoreDefinition->auditions()->attach($audition);
|
||||||
|
$room = Room::factory()->create();
|
||||||
|
$room->judges()->attach($judge);
|
||||||
|
// BonusScoreObserver needs regular scoring set up
|
||||||
|
$sg = ScoringGuide::factory()->create();
|
||||||
|
$audition->update(['scoring_guide_id' => $sg->id]);
|
||||||
|
|
||||||
|
$response = $this->actingAs($judge)->post(route('judging.bonusScores.recordScore', $entry), [
|
||||||
|
'score' => 28,
|
||||||
|
]);
|
||||||
|
$response->assertRedirect(route('dashboard'))
|
||||||
|
->assertSessionHas('error', 'Score Entry Error - That judge is not assigned to judge that bonus score');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('will not accept a score that is too high', function () {
|
||||||
|
$audition = Audition::factory()->create();
|
||||||
|
$entry = Entry::factory()->forAudition($audition)->create();
|
||||||
|
$judge = User::factory()->create();
|
||||||
|
$bonusScoreDefinition = BonusScoreDefinition::factory()->create(['max_score' => 100]);
|
||||||
|
$bonusScoreDefinition->auditions()->attach($audition);
|
||||||
|
$bonusScoreDefinition->judges()->attach($judge);
|
||||||
|
|
||||||
|
// BonusScoreObserver needs regular scoring set up
|
||||||
|
$sg = ScoringGuide::factory()->create();
|
||||||
|
$audition->update(['scoring_guide_id' => $sg->id]);
|
||||||
|
|
||||||
|
$response = $this->actingAs($judge)->post(route('judging.bonusScores.recordScore', $entry), [
|
||||||
|
'score' => 101,
|
||||||
|
]);
|
||||||
|
$response->assertRedirect()->assertSessionHasErrors('score');
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue