get(route('admin.bonus-scores.index')) ->assertRedirect(route('home')); actAsNormal(); $this->get(route('admin.bonus-scores.index')) ->assertRedirect(route('dashboard')) ->assertSessionHas('error', 'You are not authorized to perform this action'); actAsTab(); $this->get(route('admin.bonus-scores.index')) ->assertRedirect(route('dashboard')) ->assertSessionHas('error', 'You are not authorized to perform this action'); }); it('grants access to an administrator', function () { // Arrange actAsAdmin(); // Act & Assert $this->get(route('admin.bonus-scores.index')) ->assertOk() ->assertViewIs('admin.bonus-scores.index'); }); it('if no bonus scores exist, show a create bonus score message', function () { // Arrange actAsAdmin(); // Act & Assert $this->get(route('admin.bonus-scores.index')) ->assertOk() ->assertSee('No bonus scores have been created'); }); it('includes a form to add a new bonus score', function () { // Arrange actAsAdmin(); // Act & Assert $this->get(route('admin.bonus-scores.index')) ->assertOk() ->assertFormExists('#create-bonus-score-form', function (AssertForm $form) { /** @noinspection PhpUndefinedMethodInspection */ $form->hasCSRF() ->hasMethod('POST') ->hasAction(route('admin.bonus-scores.store')) ->containsInput(['name' => 'name']) ->containsInput(['name' => 'max_score', 'type' => 'number']) ->containsInput(['name' => 'weight']); }); }); it('can create a new subscore', function () { // Arrange $submissionData = [ 'name' => 'New Bonus Score', 'max_score' => 10, 'weight' => 1, ]; // Act & Assert actAsAdmin(); $this->post(route('admin.bonus-scores.store'), $submissionData) ->assertRedirect(route('admin.bonus-scores.index')) ->assertSessionHas('success', 'Bonus Score Created'); $test = BonusScoreDefinition::where('name', 'New Bonus Score')->first(); expect($test->exists())->toBeTrue(); }); it('shows existing bonus scores', function () { // Arrange $bonusScores = BonusScoreDefinition::factory()->count(3)->create(); actAsAdmin(); // Act & Assert $response = $this->get(route('admin.bonus-scores.index')); $response->assertOk(); $bonusScores->each(fn ($bonusScore) => $response->assertSee($bonusScore->name)); });