diff --git a/app/Http/Controllers/Admin/ScoringGuideController.php b/app/Http/Controllers/Admin/ScoringGuideController.php
index e07b1f7..0e84a5c 100644
--- a/app/Http/Controllers/Admin/ScoringGuideController.php
+++ b/app/Http/Controllers/Admin/ScoringGuideController.php
@@ -17,13 +17,10 @@ class ScoringGuideController extends Controller
{
public function index()
{
- if (! Auth::user()->is_admin) {
- abort(403);
- }
DB::table('auditions')
->whereNull('scoring_guide_id')
->update(['scoring_guide_id' => 0]);
- $guides = ScoringGuide::with('auditions')->orderBy('name')->get();
+ $guides = ScoringGuide::with(['auditions'])->withCount('subscores')->orderBy('name')->get();
return view('admin.scoring.index', ['guides' => $guides]);
}
@@ -42,7 +39,7 @@ class ScoringGuideController extends Controller
'name' => request('name'),
]);
- return redirect('/admin/scoring');
+ return redirect(route('admin.scoring.index'))->with('success', 'Scoring guide created');
}
public function edit(Request $request, ScoringGuide $guide)
diff --git a/database/migrations/2024_06_04_205015_ensure_room_id_0_for_unassigned_entries.php b/database/migrations/2024_06_04_205015_ensure_room_id_0_for_unassigned_entries.php
index 1c28c98..c2e0ac5 100644
--- a/database/migrations/2024_06_04_205015_ensure_room_id_0_for_unassigned_entries.php
+++ b/database/migrations/2024_06_04_205015_ensure_room_id_0_for_unassigned_entries.php
@@ -1,10 +1,7 @@
0,
- 'name' => 'No Guide Assigned'
+ 'name' => 'No Guide Assigned',
]);
$room->update([
- 'id' => 0
+ 'id' => 0,
]);
}
}
diff --git a/database/migrations/2024_06_05_011858_add_scoring_guide_id_column_to_auditions_table.php b/database/migrations/2024_06_05_011858_add_scoring_guide_id_column_to_auditions_table.php
index c1f7640..c66e6ee 100644
--- a/database/migrations/2024_06_05_011858_add_scoring_guide_id_column_to_auditions_table.php
+++ b/database/migrations/2024_06_05_011858_add_scoring_guide_id_column_to_auditions_table.php
@@ -1,6 +1,5 @@
0,
- 'name' => 'No Guide Assigned'
+ 'name' => 'No Guide Assigned',
]);
$sg->update([
- 'id' => 0
+ 'id' => 0,
]);
}
}
diff --git a/resources/views/admin/scoring/index-scoring-guide-management-card.blade.php b/resources/views/admin/scoring/index-scoring-guide-management-card.blade.php
index 8a57ab3..851cef3 100644
--- a/resources/views/admin/scoring/index-scoring-guide-management-card.blade.php
+++ b/resources/views/admin/scoring/index-scoring-guide-management-card.blade.php
@@ -17,14 +17,14 @@
@continue
@endif
- {{ $guide->name }} {{ $guide->subscores->count() }} subscores
- Edit
+ {{ $guide->name }} {{ $guide->subscores_count }} subscores
+ Edit
@endforeach
-
+
diff --git a/tests/Feature/Pages/Setup/ScoringGuideIndexTest.php b/tests/Feature/Pages/Setup/ScoringGuideIndexTest.php
new file mode 100644
index 0000000..92368f2
--- /dev/null
+++ b/tests/Feature/Pages/Setup/ScoringGuideIndexTest.php
@@ -0,0 +1,85 @@
+assertRedirect(route('home'));
+ actAsNormal();
+ get(route('admin.scoring.index'))
+ ->assertRedirect(route('dashboard'))
+ ->assertSessionHas('error', 'You are not authorized to perform this action');
+ actAsAdmin();
+ get(route('admin.scoring.index'))
+ ->assertOk()
+ ->assertViewIs('admin.scoring.index');
+});
+it('shows a list of scoring guides and their count of subscores', function () {
+ $scoringGuide = ScoringGuide::factory()->create();
+ SubscoreDefinition::factory()->count(3)->create(['scoring_guide_id' => $scoringGuide->id]);
+ Audition::factory()->count(3)->create(['scoring_guide_id' => $scoringGuide->id]);
+ actAsAdmin();
+ $response = get(route('admin.scoring.index'));
+ $response->assertOk()
+ ->assertSeeInOrder(['| name, $scoringGuide->subscores()->count()], false);
+});
+it('shows a link to edit each scoring guide', function () {
+ $scoringGuide = ScoringGuide::factory()->create();
+ actAsAdmin();
+ $response = get(route('admin.scoring.index'));
+ $response->assertOk()
+ ->assertSee(route('admin.scoring.edit', $scoringGuide));
+});
+it('shows auditions in groups with their scoring guide', function () {
+ $guides = ScoringGuide::factory()->count(2)->create();
+ foreach ($guides as $guide) {
+ Audition::factory()->count(3)->create(['scoring_guide_id' => $guide->id]);
+ }
+ actAsAdmin();
+ $response = get(route('admin.scoring.index'));
+ $response->assertOk();
+ foreach (Audition::all() as $audition) {
+ $guide = $audition->scoringGuide;
+ $response->assertElementExists('#guide-'.$guide->id, function (AssertElement $element) use ($audition) {
+ $element->containsText($audition->name);
+ });
+ }
+});
+it('has a form for a new scoring guide', function () {
+ actAsAdmin();
+ $response = get(route('admin.scoring.index'));
+ $response->assertOk()
+ ->assertSeeInOrder(['assertSee(route('admin.scoring.store'));
+});
+it('creates a new scoring guide', function () {
+ $formData = ['name' => 'New Scoring Guide'];
+ actAsAdmin();
+ $response = post(route('admin.scoring.store'), $formData);
+ /** @noinspection PhpUnhandledExceptionInspection */
+ $response
+ ->assertSessionHasNoErrors()
+ ->assertRedirect(route('admin.scoring.index'))
+ ->assertSessionHas('success', 'Scoring guide created');
+ $this->assertDatabaseHas('scoring_guides', $formData);
+});
+it('only allows an admin to create a new scoring guide', function () {
+ // Arrange
+ $formData = ['name' => 'New Scoring Guide'];
+ // Act & Assert
+ $response = post(route('admin.scoring.store'), $formData);
+ $response->assertRedirect(route('home'));
+ actAsNormal();
+ $response = post(route('admin.scoring.store'), $formData);
+ $response->assertRedirect(route('dashboard'))
+ ->assertSessionHas('error', 'You are not authorized to perform this action');
+});
|