Write tests - Write tests for what was done to this point that will be kept #11

Merged
okorpheus merged 61 commits from write-tests into master 2024-07-05 21:21:32 +00:00
1 changed files with 120 additions and 0 deletions
Showing only changes of commit 482acd7913 - Show all commits

View File

@ -0,0 +1,120 @@
<?php
use App\Models\Audition;
use App\Models\Entry;
use App\Models\Room;
use App\Models\ScoringGuide;
use App\Models\SubscoreDefinition;
use App\Models\User;
use App\Settings;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
beforeEach(function () {
Settings::set('judging_enabled', true);
Settings::set('advanceTo', 'OMEA');
$this->scoringGuide = ScoringGuide::factory()->create();
SubscoreDefinition::factory()->count(5)->create(['scoring_guide_id' => $this->scoringGuide->id]);
$this->user = User::factory()->create();
$this->room = Room::factory()->create();
$this->room->addJudge($this->user->id);
$this->audition = Audition::factory()->create([
'room_id' => $this->room->id,
'scoring_guide_id' => $this->scoringGuide->id,
]);
$this->entries = Entry::factory()->count(35)->create(['audition_id' => $this->audition->id]);
$n = 1;
foreach ($this->entries as $entry) {
$entry->draw_number = $n++;
$entry->save();
}
});
it('responds favorably to a user assigned to judge this audition', function () {
$this->actingAs($this->user);
$this->get(route('judging.entryScoreSheet', $this->entries->first()))
->assertOK();
});
it('redirects a user that is not assigned to judge this audition', function () {
$user = User::factory()->create();
$this->actingAs($user);
$this->get(route('judging.entryScoreSheet', $this->entries->first()))
->assertRedirect(route('dashboard'));
});
it('redirects a guest', function () {
$this->get(route('judging.entryScoreSheet', $this->entries->first()))
->assertRedirect(route('home'));
});
it('redirects if judging is not enabled', function () {
// Arrange
Settings::set('judging_enabled', false);
// Act & Assert
$this->actingAs($this->user);
$this->get(route('judging.entryScoreSheet', $this->entries->first()))
->assertRedirect(route('dashboard'));
});
it('has a field label for each subscore', function () {
// Arrange
$this->actingAs($this->user);
$response = $this->get(route('judging.entryScoreSheet', $this->entries->first()));
// Act & Assert
foreach ($this->scoringGuide->subscores as $subscore) {
$response->assertSeeInOrder(['label', $subscore->name, '/label']);
}
});
it('has an input field for each subscore', function () {
// Arrange
$this->actingAs($this->user);
// Act & Assert
$response = $this->get(route('judging.entryScoreSheet', $this->entries->first()));
foreach ($this->scoringGuide->subscores as $subscore) {
$response->assertSeeInOrder(['input', 'name=', 'score['.$subscore->id.']']);
}
});
it('shows advancement votes if advancement is enabled', function () {
// Arrange
Settings::set('advanceTo', 'OMEA');
$this->actingAs($this->user);
// Act & Assert
$response = $this->get(route('judging.entryScoreSheet', $this->entries->first()));
$response
->assertSee(auditionSetting('advanceTo').' Advancement')
->assertSeeInOrder(['Yes', 'No', 'DQ']);
Settings::set('advanceTo', null);
$response = $this->get(route('judging.entryScoreSheet', $this->entries->first()));
$response
->assertDontSee([auditionSetting('advanceTo').' Advancement', 'Yes', 'DQ']);
});
it('allows an assigned judge to enter scores', function () {
// Arrange
$this->actingAs($this->user);
$score = [];
foreach ($this->scoringGuide->subscores as $subscore) {
$score[$subscore->id] = mt_rand(0, 100);
}
// Act & Assert
$this->post(route('judging.saveScoreSheet', $this->entries->first()),
['advancement-vote' => 'yes', 'score' => $score])
->assertSessionHasNoErrors()
->assertRedirect(route('judging.auditionEntryList', $this->entries->first()->audition))
->assertSessionHas('success',
'Entered scores for '.$this->entries->first()->audition->name.' '.$this->entries->first()->draw_number);
$arrayToTest = [];
$orderedSubscores = $this->audition->scoringGuide->subscores()->orderBy('display_order')->get();
foreach ($orderedSubscores as $subscore) {
$arrayToTest[] = $score[$subscore->id];
}
$this->get(route('judging.auditionEntryList', $this->entries->first()->audition))
->assertOk()
->assertSeeInOrder([
'td', $arrayToTest[0], '/td',
'td', $arrayToTest[1], '/td',
'td', $arrayToTest[2], '/td',
'td', $arrayToTest[3], '/td',
'td', $arrayToTest[4], '/td',
]);
});