111 lines
4.2 KiB
PHP
111 lines
4.2 KiB
PHP
<?php
|
|
|
|
use App\Models\Audition;
|
|
use App\Models\Event;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
describe('EventController::Index', function () {
|
|
it('denies access to a non-admin user', function () {
|
|
$this->get(route('admin.events.index'))->assertRedirect(route('home'));
|
|
actAsNormal();
|
|
$this->get(route('admin.events.index'))->assertRedirect(route('dashboard'));
|
|
actAsTab();
|
|
$this->get(route('admin.events.index'))->assertRedirect(route('dashboard'));
|
|
});
|
|
it('shows the event index page', function () {
|
|
$events = Event::factory()->count(3)->create();
|
|
actAsAdmin();
|
|
$response = $this->get(route('admin.events.index'))->assertOk();
|
|
foreach ($events as $event) {
|
|
$response->assertSee($event->name);
|
|
}
|
|
});
|
|
it('includes the count of auditions in each event', function () {
|
|
$event1 = Event::factory()->create();
|
|
$event2 = Event::factory()->create();
|
|
Audition::factory()->count(3)->create([
|
|
'event_id' => $event1->id,
|
|
]);
|
|
Audition::factory()->count(2)->create([
|
|
'event_id' => $event2->id,
|
|
]);
|
|
actAsAdmin();
|
|
$response = $this->get(route('admin.events.index'))
|
|
->assertOk();
|
|
$response->assertSeeInOrder([
|
|
$event1->name,
|
|
'3 Auditions',
|
|
]);
|
|
$response->assertSeeInOrder([
|
|
$event1->name,
|
|
'2 Auditions',
|
|
]);
|
|
});
|
|
it('includes a form to add an event', function () {
|
|
$events = \App\Models\Event::factory()->count(3)->create();
|
|
actAsAdmin();
|
|
$response = $this->get(route('admin.events.index'))
|
|
->assertOk()
|
|
->assertSee(route('admin.events.store'));
|
|
});
|
|
});
|
|
|
|
describe('EventController::Store', function () {
|
|
it('denies access to a non-admin user', function () {
|
|
$this->post(route('admin.events.store'), [])->assertRedirect(route('home'));
|
|
actAsNormal();
|
|
$this->post(route('admin.events.store'), [])->assertRedirect(route('dashboard'));
|
|
actAsTab();
|
|
$this->post(route('admin.events.store'), [])->assertRedirect(route('dashboard'));
|
|
});
|
|
it('creates an event', function () {
|
|
actAsAdmin();
|
|
$this->post(route('admin.events.store'), [
|
|
'name' => 'Test Event',
|
|
])->assertRedirect(route('admin.events.index'))->assertSessionHas('success');
|
|
$this->assertDatabaseHas('events', [
|
|
'name' => 'Test Event',
|
|
]);
|
|
});
|
|
it('will not create an event with a duplicate name', function () {
|
|
\App\Models\Event::create(['name' => 'Test Event']);
|
|
actAsAdmin();
|
|
$this->post(route('admin.events.store'), [
|
|
'name' => 'Test Event',
|
|
])->assertRedirect()->assertSessionHasErrors('name');
|
|
$this->assertDatabaseCount('events', 1);
|
|
});
|
|
});
|
|
|
|
describe('EventController::Destroy', function () {
|
|
it('denies access to a non-admin user', function () {
|
|
$event = \App\Models\Event::factory()->create();
|
|
$this->delete(route('admin.events.destroy', $event))->assertRedirect(route('home'));
|
|
actAsNormal();
|
|
$this->delete(route('admin.events.destroy', $event))->assertRedirect(route('dashboard'));
|
|
actAsTab();
|
|
$this->delete(route('admin.events.destroy', $event))->assertRedirect(route('dashboard'));
|
|
});
|
|
it('deletes an event', function () {
|
|
$event = \App\Models\Event::factory()->create();
|
|
actAsAdmin();
|
|
$this->delete(route('admin.events.destroy',
|
|
$event))->assertRedirect(route('admin.events.index'))->assertSessionHas('success');
|
|
$this->assertDatabaseMissing('events', [
|
|
'id' => $event->id,
|
|
]);
|
|
});
|
|
it('will not delete an event with auditions', function () {
|
|
$event = \App\Models\Event::factory()->create();
|
|
\App\Models\Audition::factory()->count(3)->create([
|
|
'event_id' => $event->id,
|
|
]);
|
|
actAsAdmin();
|
|
$this->delete(route('admin.events.destroy', $event))
|
|
->assertRedirect(route('admin.events.index'));
|
|
$this->assertDatabaseCount('events', 1);
|
|
});
|
|
});
|