Select audition and generate forms for setting and removing no_show flags

This commit is contained in:
Matt Young 2024-07-07 19:33:52 -05:00
parent 87f091ee5b
commit 0f18a7c62e
8 changed files with 187 additions and 2 deletions

View File

@ -0,0 +1,11 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="tests - paralell" type="PestRunConfigurationType">
<option name="pestRunnerSettings">
<PestRunner directory="$PROJECT_DIR$/tests" method="" options="--parallel --recreate-databases" />
</option>
<option name="runnerSettings">
<PhpTestRunnerSettings directory="$PROJECT_DIR$/tests" method="" options="--parallel --recreate-databases" />
</option>
<method v="2" />
</configuration>
</component>

View File

@ -0,0 +1,41 @@
<?php
namespace App\Http\Controllers\Tabulation;
use App\Http\Controllers\Controller;
use App\Models\Entry;
use Illuminate\Http\Request;
class EntryFlagController extends Controller
{
public function noShowSelect()
{
$method = 'GET';
$formRoute = 'entry-flags.confirmNoShow';
return view('tabulation.choose_entry', compact('method', 'formRoute'));
}
public function noShowConfirm(Request $request)
{
$validData = $request->validate([
'entry_id' => 'required|exists:entries,id',
]);
$entry = Entry::with('flags')->find($validData['entry_id']);
if ($entry->hasFlag('no_show')) {
$formId = 'no-show-cancellation-form';
$buttonName = 'Remove No Show';
$submitRouteName = 'entry-flags.enterNoShow';
$cardHeading = 'Undo No Show';
} else {
$formId = 'no-show-confirmation-form';
$buttonName = 'Confirm No Show';
$submitRouteName = 'entry-flags.enterNoShow';
$cardHeading = 'Confirm No Show';
}
return view('tabulation.no_show_confirm',
compact('entry', 'formId', 'buttonName', 'submitRouteName', 'cardHeading'));
}
}

View File

@ -25,7 +25,7 @@ class CheckIfCanTab
return $next($request);
}
return redirect('/')->with('error', 'You do not have access to score tabulation.');
return redirect('dashboard')->with('error', 'You are not authorized to perform this action');
}
}

View File

@ -10,7 +10,7 @@
<x-card.card class="mx-auto max-w-sm">
<x-card.heading>Choose Entry</x-card.heading>
<div class="">
<x-form.form method="{{ $method }}" action="{{ route($formRoute) }}" class="mb-4 mt-3">
<x-form.form method="{{ $method }}" action="{{ route($formRoute) }}" class="mb-4 mt-3" id="entry-select-form">
<x-form.field name="entry_id" label_text="Entry ID"></x-form.field>
<x-form.footer >
<x-form.button>Select</x-form.button>

View File

@ -0,0 +1,19 @@
<x-layout.app>
<x-card.card class="mx-auto max-w-md">
<x-card.heading>{{ $cardHeading }}</x-card.heading>
<x-card.list.body>
<x-card.list.row>
{{ $entry->student->full_name() }}
<x-card.list.row-text-subtext>{{$entry->school->name}}</x-card.list.row-text-subtext>
</x-card.list.row>
<x-card.list.row>
{{ $entry->audition->name }} #{{ $entry->draw_number ?? ' no draw number' }}
</x-card.list.row>
</x-card.list.body>
<x-form.footer class="mb-4">
<x-form.form method="POST" action="{{route($submitRouteName, $entry)}}" id="{{ $formId }}">
<x-form.button type="submit">{{ $buttonName }}</x-form.button>
</x-form.form>
</x-form.footer>
</x-card.card>
</x-layout.app>

View File

@ -14,6 +14,13 @@ Route::middleware(['auth', 'verified', CheckIfCanTab::class])->group(function ()
Route::delete('/{score}', [\App\Http\Controllers\Tabulation\ScoreController::class, 'destroyScore'])->name('scores.destroy');
});
// Entry Flagging
Route::prefix('entry-flags/')->controller(\App\Http\Controllers\Tabulation\EntryFlagController::class)->group(function () {
Route::get('/choose_no_show', 'noShowSelect')->name('entry-flags.noShowSelect');
Route::get('/propose-no-show', 'noShowConfirm')->name('entry-flags.confirmNoShow');
Route::post('/no-show/{entry}', 'enterNoShow')->name('entry-flags.enterNoShow');
});
// Generic Tabulation Routes
Route::prefix('tabulation/')->controller(\App\Http\Controllers\Tabulation\TabulationController::class)->group(function () {
Route::get('/status', 'status')->name('tabulation.status');

View File

@ -0,0 +1,66 @@
<?php
use App\Models\Entry;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Sinnbeck\DomAssertions\Asserts\AssertForm;
use function Pest\Laravel\get;
uses(RefreshDatabase::class);
it('only allows an admin or tab user to confirm a no-show', function () {
$entry = Entry::factory()->create();
get(route('entry-flags.confirmNoShow', ['entry_id' => $entry->id]))
->assertRedirect(route('home'));
actAsNormal();
get(route('entry-flags.confirmNoShow', ['entry_id' => $entry->id]))
->assertRedirect(route('dashboard'))
->assertSessionHas('error', 'You are not authorized to perform this action');
actAsTab();
get(route('entry-flags.confirmNoShow', ['entry_id' => $entry->id]))
->assertOk();
actAsAdmin();
get(route('entry-flags.confirmNoShow', ['entry_id' => $entry->id]))
->assertOk();
});
it('has information for the requested entry', function () {
// Arrange
$entry = Entry::factory()->create();
// Act & Assert
actAsTab();
get(route('entry-flags.confirmNoShow', ['entry_id' => $entry->id]))
->assertOk()
->assertSee($entry->student->full_name())
->assertSee($entry->audition->name)
->assertSee($entry->student->school->name)
->assertSee($entry->draw_number);
});
it('posts to entry-flags.enterNoShow and has a submit button', function () {
// Arrange
$entry = Entry::factory()->create();
// Act & Assert
actAsTab();
get(route('entry-flags.confirmNoShow', ['entry_id' => $entry->id]))
->assertOk()
->assertFormExists('#no-show-confirmation-form', function (AssertForm $form) use ($entry) {
$form->hasMethod('POST')
->hasAction(route('entry-flags.enterNoShow', ['entry' => $entry->id]))
->contains('button', ['type' => 'submit'])
->hasCSRF();
});
});
it('posts to entry-flags.undoNoShow and has a remove button if the entry is already a noshow', function () {
// Arrange
$entry = Entry::factory()->create();
$entry->addFlag('no_show');
// Act & Assert
actAsTab();
get(route('entry-flags.confirmNoShow', ['entry_id' => $entry->id]))
->assertOk()
->assertFormExists('#no-show-cancellation-form', function (AssertForm $form) use ($entry) {
$form->hasMethod('POST')
->hasAction(route('entry-flags.undoNoShow', ['entry' => $entry->id]))
->contains('button', ['type' => 'submit'])
->hasCSRF();
});
});

View File

@ -0,0 +1,41 @@
<?php
use Illuminate\Foundation\Testing\RefreshDatabase;
use Sinnbeck\DomAssertions\Asserts\AssertElement;
use Sinnbeck\DomAssertions\Asserts\AssertForm;
use function Pest\Laravel\get;
uses(RefreshDatabase::class);
it('responds to only admin and tab users', function () {
get(route('entry-flags.noShowSelect'))
->assertRedirect(route('home'));
actAsAdmin();
get(route('entry-flags.noShowSelect'))
->assertOk();
actAsTab();
get(route('entry-flags.noShowSelect'))
->assertOk();
actAsNormal();
get(route('entry-flags.noShowSelect'))
->assertRedirect(route('dashboard'))
->assertSessionHas('error', 'You are not authorized to perform this action');
});
it('has an input for entry_id', function () {
actAsAdmin();
get(route('entry-flags.noShowSelect'))
->assertOk()
->assertElementExists('#entry_id', function (AssertElement $element) {
$element->is('input');
});
});
it('submits to entry-flags.confirmNoShow', function () {
actAsAdmin();
get(route('entry-flags.noShowSelect'))
->assertOk()
->assertFormExists('#entry-select-form', function (AssertForm $form) {
$form->hasMethod('GET')
->hasAction(route('entry-flags.confirmNoShow'));
});
});