diff --git a/app/Actions/Tabulation/EnterBonusScore.php b/app/Actions/Tabulation/EnterBonusScore.php index 145106d..02f4ef8 100644 --- a/app/Actions/Tabulation/EnterBonusScore.php +++ b/app/Actions/Tabulation/EnterBonusScore.php @@ -14,9 +14,11 @@ class EnterBonusScore { public function __invoke(User $judge, Entry $entry, int $score): void { - $getRelatedEntries = App::make(GetBonusScoreRelatedEntries::class); - $this->basicValidations($judge, $entry); + // Verify there is a need for a bonus score + if ($entry->audition->bonusScore->count() === 0) { + throw new AuditionAdminException('The entries audition does not accept bonus scores'); + } $this->validateJudgeValidity($judge, $entry, $score); $entries = $getRelatedEntries($entry); @@ -33,20 +35,6 @@ class EnterBonusScore } - protected function basicValidations(User $judge, Entry $entry): void - { - if (! $judge->exists) { - throw new AuditionAdminException('Invalid judge provided'); - } - if (! $entry->exists) { - throw new AuditionAdminException('Invalid entry provided'); - } - if ($entry->audition->bonusScore->count() === 0) { - throw new AuditionAdminException('Entry does not have a bonus score'); - } - - } - protected function validateJudgeValidity(User $judge, Entry $entry, $score): void { if (BonusScore::where('entry_id', $entry->id)->where('user_id', $judge->id)->exists()) { diff --git a/tests/Feature/app/Actions/Tabulation/EnterBonusScoreTest.php b/tests/Feature/app/Actions/Tabulation/EnterBonusScoreTest.php index 013eb04..22fe44a 100644 --- a/tests/Feature/app/Actions/Tabulation/EnterBonusScoreTest.php +++ b/tests/Feature/app/Actions/Tabulation/EnterBonusScoreTest.php @@ -89,19 +89,13 @@ it('enters a bonus score for an student in multiple auditions and copies bonus t expect($bariBS->score)->toEqual(7) ->and($bariBS->originally_scored_entry)->toEqual($this->s3a2->id); }); -it('will not enter a score for a non existent judge', function () { - $fakeJudge = User::factory()->make(); - ($this->scribe)($fakeJudge, $this->s3a2, 7); -})->throws(AuditionAdminException::class, 'Invalid judge provided'); -it('will not enter a score for a non existent entry', function () { - $fakeEntry = Entry::factory()->make(); - ($this->scribe)($this->judge1, $fakeEntry, 7); -})->throws(AuditionAdminException::class, 'Invalid entry provided'); + it('will not enter a score for an audition with no bonus score', function () { $newAudition = Audition::factory()->create(); $newEntry = Entry::factory()->create(['audition_id' => $newAudition->id]); ($this->scribe)($this->judge1, $newEntry, 7); -})->throws(AuditionAdminException::class, 'Entry does not have a bonus score'); +})->throws(AuditionAdminException::class, 'The entries audition does not accept bonus scores'); + it('will not enter a bonus score for a judge that has already given one', function () { ($this->scribe)($this->judge1, $this->s2a1, 7); ($this->scribe)($this->judge1, $this->s2a2, 7); diff --git a/tests/Feature/app/Http/Controllers/Admin/AssignMonitorControllerTest.php b/tests/Feature/app/Http/Controllers/Admin/AssignMonitorControllerTest.php new file mode 100644 index 0000000..44554f8 --- /dev/null +++ b/tests/Feature/app/Http/Controllers/Admin/AssignMonitorControllerTest.php @@ -0,0 +1,52 @@ +get(route('admin.assign_monitors.index'))->assertRedirect(route('home')); + actAsNormal(); + $this->get(route('admin.assign_monitors.index'))->assertRedirect(route('dashboard')); + actAsTab(); + $this->get(route('admin.assign_monitors.index'))->assertRedirect(route('dashboard')); + }); + it('shows the assign monitors page', function () { + $users = User::factory()->count(5)->create(); + actAsAdmin(); + $response = $this->get(route('admin.assign_monitors.index'))->assertOk(); + foreach (User::all() as $user) { + $response->assertSee($user->full_name(true)); + } + }); +}); + +describe('AssignMonitorController::store', function () { + it('denies access to a non-admin user', function () { + $this->post(route('admin.assign_monitors.store'))->assertRedirect(route('home')); + actAsNormal(); + $this->post(route('admin.assign_monitors.store'))->assertRedirect(route('dashboard')); + actAsTab(); + $this->post(route('admin.assign_monitors.store'))->assertRedirect(route('dashboard')); + }); + it('assigns monitor privileges to a user', function () { + $toBeMonitor = User::factory()->create(); + $notToBeMonitor = User::factory()->create(); + $alsoAmonitor = User::factory()->create(); + actAsAdmin(); + $this->post(route('admin.assign_monitors.store'), [ + 'user' => [ + $toBeMonitor->id => 'on', + $alsoAmonitor->id => 'on', + ], + ])->assertRedirect(route('admin.assign_monitors.index'))->assertSessionHas('success', 'Monitors assigned'); + $toBeMonitor->refresh(); + $notToBeMonitor->refresh(); + $alsoAmonitor->refresh(); + expect($toBeMonitor->hasFlag('monitor'))->toBeTrue(); + expect($notToBeMonitor->hasFlag('monitor'))->toBeFalse(); + expect($alsoAmonitor->hasFlag('monitor'))->toBeTrue(); + }); +});