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'); });