auditionadmin/tests-old/Feature/Pages/JudgingIndexTest.php

151 lines
5.0 KiB
PHP

<?php
use App\Models\Audition;
use App\Models\BonusScoreDefinition;
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;
use function Pest\Laravel\actingAs;
use function Pest\Laravel\get;
uses(RefreshDatabase::class);
beforeEach(function () {
Settings::set('judging_enabled', true);
Settings::set('advanceTo', 'OMEA');
$scoringGuide = ScoringGuide::factory()->create();
SubscoreDefinition::factory()->count(5)->create(['scoring_guide_id' => $scoringGuide->id]);
$this->user = User::factory()->create();
$this->rooms = Room::factory()->count(2)->create();
$this->auditions = [];
foreach ($this->rooms as $room) {
$room->judges()->attach($this->user);
$this->auditions[] = Audition::factory()->create(['room_id' => $room->id, 'scoring_guide_id' => $scoringGuide->id]);
$this->auditions[] = Audition::factory()->create(['room_id' => $room->id, 'scoring_guide_id' => $scoringGuide->id]);
$this->auditions[] = Audition::factory()->create(['room_id' => $room->id, 'scoring_guide_id' => $scoringGuide->id]);
}
foreach ($this->auditions as $audition) {
Entry::factory()->count(23)->create(['audition_id' => $audition->id]);
}
});
it('responds nicely to a user assigned to judge when judging is enabled', function () {
actingAs($this->user);
get(route('judging.index'))
->assertOk();
});
it('redirects when judging is not enabled', function () {
Settings::set('judging_enabled', false);
actingAs($this->user);
get(route('judging.index'))
->assertRedirect(route('dashboard'));
});
it('redirects when a user not assigned to judge tries', function () {
// Arrange
actingAs(User::factory()->create());
// Act
$response = get(route('judging.index'));
// Assert
$response->assertRedirect(route('dashboard'));
});
it('redirects when a guest attempts to access', function () {
// Act & Assert
get(route('judging.index'))
->assertRedirect(route('home'));
});
it('shows rooms the user is assigned to judge', function () {
// Arrange
actingAs($this->user);
// Act
$response = get(route('judging.index'));
// Assert
foreach ($this->rooms as $room) {
$response->assertSee($room->name);
}
});
it('shows auditions in the rooms the user is assigned to judge', function () {
// Arrange
actingAs($this->user);
// Act
$response = get(route('judging.index'));
// Assert
foreach ($this->auditions as $audition) {
$response->assertSee($audition->name);
}
});
it('links to the entry list for each audition the user is assigned to judge', function () {
// Arrange
actingAs($this->user);
// Act
$response = get(route('judging.index'));
// Assert
foreach ($this->auditions as $audition) {
$response->assertSee(route('judging.auditionEntryList', $audition));
}
});
it('has links that work for each audition the user is assigned to judge', function () {
// Arrange
actingAs($this->user);
// Act & Assert
foreach ($this->auditions as $audition) {
get(route('judging.auditionEntryList', $audition))
->assertOk();
}
});
it('does not show the user room and auditions they are not assigned to judge', function () {
// Arrange
$otherRoom = Room::factory()->create();
$otherAudition = Audition::factory()->create(['room_id' => $otherRoom->id]);
actingAs($this->user);
// Act
$response = get(route('judging.index'));
// Assert
$response
->assertDontSee($otherRoom->name)
->assertDontSee($otherAudition->name);
});
it('shows bonus scores the user is assigned to judge', function () {
// Arrange
$bonusScore = BonusScoreDefinition::factory()->create();
$judge = User::factory()->create();
$bonusScore->judges()->attach($judge);
$this->actingAs($judge);
// Act & Assert
$this->get(route('judging.index'))
->assertSee($bonusScore->name);
});
it('does not show bonus scores the user is not assigned to judge', function () {
// Arrange
$bonusScore = BonusScoreDefinition::factory()->create();
$otherBonusScore = BonusScoreDefinition::factory()->create();
$judge = User::factory()->create();
$bonusScore->judges()->attach($judge);
$this->actingAs($judge);
// Act & Assert
$this->get(route('judging.index'))
->assertSee($bonusScore->name)
->assertDontSee($otherBonusScore->name);
});
it('shows auditions in a bonus score assignment', function () {
// Arrange
$bonusScore = BonusScoreDefinition::factory()->create();
$audition = Audition::factory()->create();
$bonusScore->auditions()->attach($audition);
$judge = User::factory()->create();
$bonusScore->judges()->attach($judge);
$this->actingAs($judge);
// Act & Assert
$this->get(route('judging.index'))
->assertSee($audition->name);
});