Tests for Audition controller
This commit is contained in:
parent
eb66da14cf
commit
5014e80fb1
|
|
@ -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()) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
describe('AssignMonitorController::index', function () {
|
||||
it('denies access to a non-admin user', function () {
|
||||
$this->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();
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue