auditionadmin/tests/Feature/app/Http/Controllers/Judging/PrelimJudgingControllerTest...

197 lines
8.3 KiB
PHP

<?php
use App\Actions\Draw\RunDraw;
use App\Models\Audition;
use App\Models\Entry;
use App\Models\PrelimDefinition;
use App\Models\PrelimScoreSheet;
use App\Models\Room;
use App\Models\ScoringGuide;
use App\Models\SubscoreDefinition;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
describe('PrelimJudgingController:prelimEntryList', function () {
it('only allows access to an assigned judge', function () {
$judgeUser = User::factory()->create();
$notJudgeUser = User::factory()->create();
$finalsRoom = Room::factory()->create();
$audition = Audition::factory()->create(['room_id' => $finalsRoom->id]);
$room = Room::factory()->create();
$finalsRoom = Room::factory()->create();
$prelimDefinition = PrelimDefinition::create([
'audition_id' => $audition->id,
'room_id' => $room->id,
'scoring_guide_id' => 0,
'passing_score' => 75,
]);
$room->addJudge($judgeUser);
$finalsRoom->addJudge($notJudgeUser);
$this->actingAs($notJudgeUser);
$this->get(route('judging.prelimEntryList', $prelimDefinition))
->assertRedirect(route('dashboard'))
->assertSessionHas('error', 'You are not assigned to judge that prelim audition.');
$this->actingAs($judgeUser);
$this->get(route('judging.prelimEntryList', $prelimDefinition))
->assertOk();
});
it('shows all auditions entered in the given audition', function () {
$judgeUser = User::factory()->create();
$finalsRoom = Room::factory()->create();
$audition = Audition::factory()->create(['room_id' => $finalsRoom->id, 'name' => 'Euphonium']);
$room = Room::factory()->create();
$prelimDefinition = PrelimDefinition::create([
'audition_id' => $audition->id,
'room_id' => $room->id,
'scoring_guide_id' => 0,
'passing_score' => 75,
]);
$room->addJudge($judgeUser);
$entries = Entry::factory()->count(5)->create(['audition_id' => $audition->id]);
app(RunDraw::class)($audition);
$this->actingAs($judgeUser);
$response = $this->get(route('judging.prelimEntryList', $prelimDefinition));
$response->assertOk();
foreach ($entries as $entry) {
$entry->refresh();
$identifierString = $entry->audition->name.' '.$entry->draw_number;
$response->assertSee($identifierString);
}
});
it('shows scores for previously judged entries', function () {
});
it('has links to enter scores for each entry', function () {
});
it('does not allow modifications to an entry that has finals scores', function () {
});
});
describe('PrelimJudgingController:prelimScoreEntryForm', function () {
beforeEach(function () {
$this->room = Room::factory()->create();
$this->finalsRoom = Room::factory()->create();
$this->scoringGuide = ScoringGuide::factory()->create();
$this->audition = Audition::factory()->create(['room_id' => $this->finalsRoom->id]);
$this->prelimDefinition = PrelimDefinition::create([
'audition_id' => $this->audition->id,
'room_id' => $this->room->id,
'scoring_guide_id' => $this->scoringGuide->id,
'passing_score' => 75,
]);
$this->prelimJudge = User::factory()->create(['judging_preference' => 'Prelims']);
$this->finalsJudge = User::factory()->create(['judging_preference' => 'Finals']);
$this->room->addJudge($this->prelimJudge);
$this->finalsRoom->addJudge($this->finalsJudge);
$this->entry = Entry::factory()->create(['audition_id' => $this->audition->id]);
});
it('denies access to non-judges', function () {
actAsNormal();
$entry = Entry::factory()->create();
$response = $this->get(route('judging.prelimScoreEntryForm', $this->entry));
$response->assertRedirect(route('dashboard'));
$response->assertSessionHas('error', 'You are not assigned to judge.');
});
it('denies access if the judge is not assigned to the room', function () {
$this->actingAs($this->finalsJudge);
$response = $this->get(route('judging.prelimScoreEntryForm', $this->entry));
$response->assertRedirect(route('dashboard'));
$response->assertSessionHas('error', 'You are not assigned to judge that prelim audition.');
});
it('denies access if the audition is published', function () {
$this->actingAs($this->prelimJudge);
$this->entry->audition->addFlag('seats_published');
$response = $this->get(route('judging.prelimScoreEntryForm', $this->entry));
$response->assertRedirect(route('dashboard'));
$response->assertSessionHas('error', 'Scores for entries in published auditions cannot be modified.');
});
it('denies access if the entry is flagged as a no-show', function () {
$this->entry->addFlag('no_show');
$this->actingAs($this->prelimJudge);
$response = $this->get(route('judging.prelimScoreEntryForm', $this->entry));
$response->assertRedirect(route('judging.prelimEntryList', $this->prelimDefinition));
$response->assertSessionHas('error', 'The requested entry is marked as a no-show. Scores cannot be entered.');
});
it('gives us a form to enter a score for an entry', function () {
$this->actingAs($this->prelimJudge);
$response = $this->get(route('judging.prelimScoreEntryForm', $this->entry));
$response->assertOk();
$response->assertDontSee($this->entry->student->last_name)
->assertDontSee($this->entry->student->first_name);
foreach (SubscoreDefinition::all() as $subscore) {
$response->assertSee($subscore->name);
$response->assertSee('score['.$subscore->id.']');
}
});
});
describe('PrelimJudgingController:savePrelimEntryForm', function () {
beforeEach(function () {
$this->room = Room::factory()->create();
$this->finalsRoom = Room::factory()->create();
$this->scoringGuide = ScoringGuide::factory()->create();
$this->audition = Audition::factory()->create(['room_id' => $this->finalsRoom->id]);
$this->prelimDefinition = PrelimDefinition::create([
'audition_id' => $this->audition->id,
'room_id' => $this->room->id,
'scoring_guide_id' => $this->scoringGuide->id,
'passing_score' => 75,
]);
$this->prelimJudge = User::factory()->create(['judging_preference' => 'Prelims']);
$this->finalsJudge = User::factory()->create(['judging_preference' => 'Finals']);
$this->room->addJudge($this->prelimJudge);
$this->finalsRoom->addJudge($this->finalsJudge);
$this->entry = Entry::factory()->create(['audition_id' => $this->audition->id]);
});
it('denies access to non-judges', function () {
actAsNormal();
$response = $this->post(route('judging.savePrelimScoreSheet', $this->entry));
$response->assertRedirect(route('dashboard'));
$response->assertSessionHas('error', 'You are not assigned to judge.');
});
it('denies access if the judge is not assigned to the room', function () {
$this->actingAs($this->finalsJudge);
$response = $this->post(route('judging.savePrelimScoreSheet', $this->entry));
$response->assertRedirect(route('dashboard'));
$response->assertSessionHas('error', 'You are not assigned to judge that prelim audition.');
});
it('saves a score sheet', function () {
$subscoreIds = SubscoreDefinition::all()->pluck('id')->toArray();
$submitData = [
'score' => [
$subscoreIds[0] => 10,
$subscoreIds[1] => 20,
$subscoreIds[2] => 30,
$subscoreIds[3] => 40,
$subscoreIds[4] => 50,
],
];
$this->actingAs($this->prelimJudge);
$response = $this->post(route('judging.savePrelimScoreSheet', $this->entry), $submitData);
$response->assertRedirect(route('judging.prelimEntryList', $this->prelimDefinition));
$response->assertSessionHas('success');
expect(PrelimScoreSheet::where('entry_id', $this->entry->id)->count())->toBe(1);
});
});