91 lines
3.2 KiB
PHP
91 lines
3.2 KiB
PHP
<?php
|
|
|
|
use App\Models\Audition;
|
|
use App\Models\Event;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
use function Pest\Laravel\get;
|
|
use function Pest\Laravel\post;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('allows only an admin to manage auditions', function () {
|
|
get((route('admin.auditions.create')))
|
|
->assertRedirect(route('home'));
|
|
actAsNormal();
|
|
get((route('admin.auditions.create')))
|
|
->assertRedirect('/dashboard')
|
|
->assertSessionHas('error', 'You are not authorized to perform this action');
|
|
actasAdmin();
|
|
get((route('admin.auditions.create')))
|
|
->assertOk();
|
|
});
|
|
it('shows necessary fields', function () {
|
|
// Arrange
|
|
actAsAdmin();
|
|
// Act & Assert
|
|
get(route('admin.auditions.create'))
|
|
->assertOk()
|
|
->assertSee(route('admin.auditions.store'))
|
|
->assertSee('name="event_id"', false)
|
|
->assertSee('name="name"', false)
|
|
->assertSee('name="entry_deadline"', false)
|
|
->assertSee('name="entry_fee"', false)
|
|
->assertSee('name="minimum_grade"', false)
|
|
->assertSee('name="maximum_grade"', false)
|
|
->assertSee('name="for_seating"', false)
|
|
->assertSee('name="for_advancement"', false);
|
|
});
|
|
it('allows an administrator to create 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->event_id)->toBe($newEvent->id)
|
|
->and($checkAudition->name)->toBe($changes['name'])
|
|
->and($checkAudition->entry_deadline)->toBe($changes['entry_deadline'])
|
|
->and($checkAudition->entry_fee)->toBe($changes['entry_fee'] * 100)
|
|
->and($checkAudition->minimum_grade)->toBe($changes['minimum_grade'])
|
|
->and($checkAudition->maximum_grade)->toBe($changes['maximum_grade'])
|
|
->and($checkAudition->for_seating)->toBe(0)
|
|
->and($checkAudition->for_advancement)->toBe(1);
|
|
});
|
|
it('does not allow a normal user or guest to create an audition', function () {
|
|
// Arrange
|
|
$precount = Audition::count();
|
|
$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',
|
|
];
|
|
// Act & Assert
|
|
post(route('admin.auditions.store'), $changes)
|
|
->assertRedirect(route('home'));
|
|
actAsNormal();
|
|
post(route('admin.auditions.store'), $changes)
|
|
->assertRedirect('/dashboard')
|
|
->assertSessionHas('error', 'You are not authorized to perform this action');
|
|
expect(Audition::count())->toBe($precount);
|
|
});
|