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
4 changed files with 120 additions and 4 deletions
Showing only changes of commit 183d1ed030 - Show all commits

View File

@ -26,7 +26,7 @@ class EntryPolicy
return true; return true;
} }
return $user->school_id == $entry->student()->school_id; return $user->school_id == $entry->student->school_id;
} }
/** /**
@ -50,7 +50,7 @@ class EntryPolicy
return true; return true;
} }
return $user->school_id == $entry->student()->school_id; return $user->school_id == $entry->student->school_id;
} }
/** /**

View File

@ -41,7 +41,8 @@ class AuditionFactory extends Factory
return [ return [
'event_id' => $event->id, 'event_id' => $event->id,
'name' => $this->faker->randomElement($instruments).$this->faker->numberBetween(1, 1000), #'name' => $this->faker->randomElement($instruments).$this->faker->numberBetween(1, 1000),
'name' => 'New Instrument ' . $this->faker->sentence(5),
'score_order' => $this->faker->numberBetween(2, 50), 'score_order' => $this->faker->numberBetween(2, 50),
'entry_deadline' => Carbon::tomorrow(), 'entry_deadline' => Carbon::tomorrow(),
'entry_fee' => 1000, 'entry_fee' => 1000,

View File

@ -8,7 +8,7 @@
<x-card.heading>{{ $room->name }}</x-card.heading> <x-card.heading>{{ $room->name }}</x-card.heading>
<x-card.list.body> <x-card.list.body>
@foreach($room->auditions as $audition) @foreach($room->auditions as $audition)
<a href="/judging/audition/{{$audition->id}}"> <a href="{{ route('judging.auditionEntryList', $audition) }}">
<x-card.list.row class="!py-3 ml-3">{{ $audition->name }}</x-card.list.row> <x-card.list.row class="!py-3 ml-3">{{ $audition->name }}</x-card.list.row>
</a> </a>
@endforeach @endforeach

View File

@ -0,0 +1,115 @@
<?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;
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);
});