auditionadmin/tests/Feature/app/Actions/Tabulation/EnterNoShowTest.php

89 lines
3.1 KiB
PHP

<?php
/** @noinspection PhpUnhandledExceptionInspection */
use App\Actions\Tabulation\EnterNoShow;
use App\Actions\Tabulation\EnterScore;
use App\Exceptions\AuditionAdminException;
use App\Models\Audition;
use App\Models\AuditLogEntry;
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 = AuditLogEntry::orderBy('id', 'desc')->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 = AuditLogEntry::orderBy('id', 'desc')->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);
});