Recording no shows works

This commit is contained in:
Matt Young 2024-07-07 22:48:07 -05:00
parent 03a2dd2e1d
commit f4f1d6cff7
3 changed files with 108 additions and 6 deletions

View File

@ -5,6 +5,9 @@ namespace App\Http\Controllers\Tabulation;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\Entry; use App\Models\Entry;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use function to_route;
class EntryFlagController extends Controller class EntryFlagController extends Controller
{ {
@ -22,6 +25,17 @@ class EntryFlagController extends Controller
'entry_id' => 'required|exists:entries,id', 'entry_id' => 'required|exists:entries,id',
]); ]);
$entry = Entry::with('flags')->withCount('scoreSheets')->find($validData['entry_id']); $entry = Entry::with('flags')->withCount('scoreSheets')->find($validData['entry_id']);
// If any results are published, get gone
if ($entry->audition->hasFlag('seats_published')) {
return to_route('entry-flags.noShowSelect')->with('error',
'Cannot enter a no-show for an entry in an audition where seats are published');
}
if ($entry->audition->hasFlag('advance_published')) {
return to_route('entry-flags.noShowSelect')->with('error',
'Cannot enter a no-show for an entry in an audition where advancement is published');
}
if ($entry->hasFlag('no_show')) { if ($entry->hasFlag('no_show')) {
$formId = 'no-show-cancellation-form'; $formId = 'no-show-cancellation-form';
$buttonName = 'Remove No Show'; $buttonName = 'Remove No Show';
@ -40,6 +54,7 @@ class EntryFlagController extends Controller
$scores = $entry->scoreSheets; $scores = $entry->scoreSheets;
$scores->load('judge'); $scores->load('judge');
} }
return view('tabulation.no_show_confirm', return view('tabulation.no_show_confirm',
compact('entry', compact('entry',
'formId', 'formId',
@ -52,7 +67,21 @@ class EntryFlagController extends Controller
public function enterNoShow(Entry $entry) public function enterNoShow(Entry $entry)
{ {
// if ($entry->audition->hasFlag('seats_published')) {
return to_route('entry-flags.noShowSelect')->with('error',
'Cannot enter a no-show for an entry in an audition where seats are published');
}
if ($entry->audition->hasFlag('advance_published')) {
return to_route('entry-flags.noShowSelect')->with('error',
'Cannot enter a no-show for an entry in an audition where advancement is published');
}
DB::table('score_sheets')->where('entry_id', $entry->id)->delete();
$entry->addFlag('no_show');
$msg = 'No Show has been entered for '.$entry->audition->name.' #'.$entry->draw_number.' (ID: '.$entry->id.').';
return to_route('entry-flags.noShowSelect')->with('success', $msg);
} }
public function undoNoShow(Entry $entry) public function undoNoShow(Entry $entry)

View File

@ -29,6 +29,19 @@ it('only allows an admin or tab user to confirm a no-show', function () {
get(route('entry-flags.confirmNoShow', ['entry_id' => $entry->id])) get(route('entry-flags.confirmNoShow', ['entry_id' => $entry->id]))
->assertOk(); ->assertOk();
}); });
it('will not work with an entry if it is in a published audition', function () {
$entry1 = Entry::factory()->create();
$entry2 = Entry::factory()->create();
$entry1->audition->addFlag('seats_published');
$entry2->audition->addFlag('advance_published');
actAsTab();
get(route('entry-flags.confirmNoShow', ['entry_id' => $entry1->id]))
->assertRedirect(route('entry-flags.noShowSelect'))
->assertSessionHas('error', 'Cannot enter a no-show for an entry in an audition where seats are published');
get(route('entry-flags.confirmNoShow', ['entry_id' => $entry2->id]))
->assertRedirect(route('entry-flags.noShowSelect'))
->assertSessionHas('error', 'Cannot enter a no-show for an entry in an audition where advancement is published');
});
it('has information for the requested entry', function () { it('has information for the requested entry', function () {
// Arrange // Arrange
$entry = Entry::factory()->create(); $entry = Entry::factory()->create();

View File

@ -0,0 +1,60 @@
<?php
use App\Models\Entry;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use function Pest\Laravel\post;
uses(RefreshDatabase::class);
it('only allows an admin or tab user to enter a no-show', function () {
$entry = Entry::factory()->create();
post(route('entry-flags.enterNoShow', $entry))
->assertRedirect(route('home'));
actAsAdmin();
post(route('entry-flags.enterNoShow', $entry))
->assertSessionHasNoErrors()
->assertSessionHas('success',
'No Show has been entered for '.$entry->audition->name.' #'.$entry->draw_number.' (ID: '.$entry->id.').')
->assertRedirect(route('entry-flags.noShowSelect'));
actAsTab();
post(route('entry-flags.enterNoShow', $entry))
->assertSessionHasNoErrors()
->assertSessionHas('success',
'No Show has been entered for '.$entry->audition->name.' #'.$entry->draw_number.' (ID: '.$entry->id.').')
->assertRedirect(route('entry-flags.noShowSelect'));
});
it('will not record an entry in a published audition as a no show', function () {
$entry1 = Entry::factory()->create();
$entry2 = Entry::factory()->create();
$entry1->audition->addFlag('seats_published');
$entry2->audition->addFlag('advance_published');
actAsAdmin();
post(route('entry-flags.enterNoShow', $entry1))
->assertRedirect(route('entry-flags.noShowSelect'))
->assertSessionHas('error', 'Cannot enter a no-show for an entry in an audition where seats are published');
post(route('entry-flags.enterNoShow', $entry2))
->assertRedirect(route('entry-flags.noShowSelect'))
->assertSessionHas('error',
'Cannot enter a no-show for an entry in an audition where advancement is published');
});
it('deletes all scores for an entry when a no-show is entered', function () {
$entry = Entry::factory()->create();
$judges = User::factory()->count(3)->create();
$entry->scoreSheets()->create(['user_id' => $judges[0]->id, 'subscores' => 10]);
$entry->scoreSheets()->create(['user_id' => $judges[1]->id, 'subscores' => 10]);
$entry->scoreSheets()->create(['user_id' => $judges[2]->id, 'subscores' => 10]);
expect($entry->scoreSheets()->count())->toBe(3);
actAsAdmin();
post(route('entry-flags.enterNoShow', $entry));
expect($entry->scoreSheets()->count())->toBe(0);
});
it('adds a no_show flag to the entry', function () {
// Arrange
$entry = Entry::factory()->create();
// Act & Assert
actAsAdmin();
post(route('entry-flags.enterNoShow', $entry));
expect(Entry::find($entry->id)->hasFlag('no_show'))->toBeTrue();
});