diff --git a/app/Policies/EntryPolicy.php b/app/Policies/EntryPolicy.php
index 051f529..f508bff 100644
--- a/app/Policies/EntryPolicy.php
+++ b/app/Policies/EntryPolicy.php
@@ -26,7 +26,7 @@ class EntryPolicy
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 $user->school_id == $entry->student()->school_id;
+ return $user->school_id == $entry->student->school_id;
}
/**
diff --git a/database/factories/AuditionFactory.php b/database/factories/AuditionFactory.php
index a5b83ed..96e5a59 100644
--- a/database/factories/AuditionFactory.php
+++ b/database/factories/AuditionFactory.php
@@ -41,7 +41,8 @@ class AuditionFactory extends Factory
return [
'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),
'entry_deadline' => Carbon::tomorrow(),
'entry_fee' => 1000,
diff --git a/resources/views/judging/index.blade.php b/resources/views/judging/index.blade.php
index 27cdb34..abd34eb 100644
--- a/resources/views/judging/index.blade.php
+++ b/resources/views/judging/index.blade.php
@@ -8,7 +8,7 @@
{{ $room->name }}
@foreach($room->auditions as $audition)
-
+
{{ $audition->name }}
@endforeach
diff --git a/tests/Feature/Pages/JudgingIndexTest.php b/tests/Feature/Pages/JudgingIndexTest.php
new file mode 100644
index 0000000..082b1f7
--- /dev/null
+++ b/tests/Feature/Pages/JudgingIndexTest.php
@@ -0,0 +1,115 @@
+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);
+});