Assign room 0 (unassigned) to new auditions

Closes #50
This commit is contained in:
Matt Young 2024-07-27 10:33:01 -05:00
parent f0b2ec8f68
commit 7a45d4ddbc
2 changed files with 27 additions and 3 deletions

View File

@ -10,8 +10,6 @@ use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use function abort;
use function array_keys;
use function compact;
use function redirect;
use function request;
use function response;
@ -60,7 +58,7 @@ class AuditionController extends Controller
if (empty($alidData['scoring_guide_id'])) {
$validData['scoring_guide_id'] = 0;
}
// TODO Check if room 0 exists, create if not
Audition::create([
'event_id' => $validData['event_id'],
'name' => $validData['name'],
@ -71,6 +69,7 @@ class AuditionController extends Controller
'for_seating' => $validData['for_seating'],
'for_advancement' => $validData['for_advancement'],
'scoring_guide_id' => $validData['scoring_guide_id'],
'room_id' => 0,
]);
return to_route('admin.auditions.index')->with('success', 'Audition created successfully');

View File

@ -4,6 +4,7 @@ use App\Models\Audition;
use App\Models\Event;
use Illuminate\Foundation\Testing\RefreshDatabase;
use function Pest\Laravel\assertDatabaseHas;
use function Pest\Laravel\get;
use function Pest\Laravel\post;
@ -112,3 +113,27 @@ it('does not allow a normal user or guest to create an audition', function () {
->assertSessionHas('error', 'You are not authorized to perform this action');
expect(Audition::count())->toBe($precount);
});
it('sets room id 0 for a new auditions', function () {
// Arrange
$newEvent = Event::factory()->create();
$changes = [
'event_id' => $newEvent->id,
'name' => 'New Name',
'entry_deadline' => '1978-01-01',
'entry_fee' => 10000,
'minimum_grade' => 3,
'maximum_grade' => 8,
'for_advancement' => 'on',
];
actAsAdmin();
// Act
$response = post(route('admin.auditions.store'), $changes);
// Assert
/** @noinspection PhpUnhandledExceptionInspection */
$response->assertRedirect(route('admin.auditions.index'))
->assertSessionHasNoErrors()
->assertSessionHas('success', 'Audition created successfully');
$checkAudition = Audition::latest()->first();
expect($checkAudition->room_id)->toBe(0);
assertDatabaseHas('rooms', ['id' => 0]);
});