Create tests for app/actions/tabulation/EnterNoShow
This commit is contained in:
parent
23de496ce6
commit
a924b3bf51
|
|
@ -9,6 +9,8 @@ use App\Models\EntryTotalScore;
|
|||
use App\Models\ScoreSheet;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
use function auditionLog;
|
||||
|
||||
class EnterNoShow
|
||||
{
|
||||
/**
|
||||
|
|
@ -51,6 +53,13 @@ class EnterNoShow
|
|||
$msg = 'No Show has been entered for '.$entry->audition->name.' #'.$entry->draw_number.' (ID: '.$entry->id.').';
|
||||
}
|
||||
|
||||
$affected = [
|
||||
['entries', [$entry->id]],
|
||||
['auditions', [$entry->audition_id]],
|
||||
['students', [$entry->student_id]],
|
||||
];
|
||||
auditionLog($msg, $affected);
|
||||
|
||||
return $msg;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
|
||||
use App\Actions\Tabulation\EnterNoShow;
|
||||
use App\Actions\Tabulation\EnterScore;
|
||||
use App\Exceptions\AuditionAdminException;
|
||||
use App\Models\Audition;
|
||||
use App\Models\Entry;
|
||||
use App\Models\SubscoreDefinition;
|
||||
use App\Models\User;
|
||||
use Database\Seeders\AuditionWithScoringGuideAndRoom;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
(new AuditionWithScoringGuideAndRoom)->run();
|
||||
SubscoreDefinition::where('id', '<', 900)->delete();
|
||||
$this->audition = Audition::first();
|
||||
$this->entry = Entry::factory()->create(['audition_id' => $this->audition->id]);
|
||||
$this->rollTaker = app(EnterNoShow::class);
|
||||
});
|
||||
|
||||
it('can enter a no-show', function () {
|
||||
($this->rollTaker)($this->entry);
|
||||
expect($this->entry->hasFlag('no_show'))->toBeTrue();
|
||||
});
|
||||
|
||||
it('creates a log entry when entering a no-show', function () {
|
||||
($this->rollTaker)($this->entry);
|
||||
$logEntry = \App\Models\AuditLogEntry::latest()->first();
|
||||
expect($logEntry->message)->toStartWith('No Show has been entered for');
|
||||
});
|
||||
|
||||
it('can enter a failed prelim', function () {
|
||||
($this->rollTaker)($this->entry, 'failprelim');
|
||||
expect($this->entry->hasFlag('failed_prelim'))->toBeTrue();
|
||||
});
|
||||
|
||||
it('creates a log entry when entering a failed prelim', function () {
|
||||
($this->rollTaker)($this->entry, 'failprelim');
|
||||
$logEntry = \App\Models\AuditLogEntry::latest()->first();
|
||||
expect($logEntry->message)->toStartWith('Failed prelim has been entered for');
|
||||
});
|
||||
|
||||
it('will not accept an invalid flag type', function () {
|
||||
($this->rollTaker)($this->entry, 'bazinga');
|
||||
})->throws(AuditionAdminException::class, 'Invalid flag type');
|
||||
|
||||
it('will not enter a no-show in an audition with published seats', function () {
|
||||
$this->audition->addFlag('seats_published');
|
||||
($this->rollTaker)($this->entry);
|
||||
})->throws(AuditionAdminException::class,
|
||||
'Cannot enter a no-show for an entry in an audition where seats are published');
|
||||
|
||||
it('will not enter a no-show in an audition with published advancement', function () {
|
||||
$this->audition->addFlag('advancement_published');
|
||||
($this->rollTaker)($this->entry);
|
||||
})->throws(AuditionAdminException::class,
|
||||
'Cannot enter a no-show for an entry in an audition where advancement is published');
|
||||
|
||||
it('deletes existing score sheets when marking a no show', function () {
|
||||
$scribe = app(EnterScore::class);
|
||||
$judge1 = User::factory()->create();
|
||||
$judge2 = User::factory()->create();
|
||||
$this->audition->judges()->attach([$judge1->id, $judge2->id]);
|
||||
$scribe($judge1, $this->entry, [
|
||||
1001 => 10,
|
||||
1002 => 11,
|
||||
1003 => 12,
|
||||
1004 => 13,
|
||||
1005 => 14,
|
||||
]);
|
||||
$scribe($judge2, $this->entry, [
|
||||
1001 => 10,
|
||||
1002 => 11,
|
||||
1003 => 12,
|
||||
1004 => 13,
|
||||
1005 => 14,
|
||||
]);
|
||||
expect($this->entry->scoreSheets()->count())->toBe(2);
|
||||
expect($this->entry->TotalScore()->count())->toBe(1);
|
||||
($this->rollTaker)($this->entry);
|
||||
expect($this->entry->scoreSheets()->count())->toBe(0);
|
||||
expect($this->entry->TotalScore()->count())->toBe(0);
|
||||
});
|
||||
Loading…
Reference in New Issue