91 lines
3.5 KiB
PHP
91 lines
3.5 KiB
PHP
<?php
|
|
|
|
use App\Models\Audition;
|
|
use App\Models\PrelimDefinition;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
describe('PrelimDefinitionController::index', function () {
|
|
it('denies access to a non-admin user', function () {
|
|
$this->get(route('admin.prelim_definitions.index'))->assertRedirect(route('home'));
|
|
actAsNormal();
|
|
$this->get(route('admin.prelim_definitions.index'))->assertRedirect(route('dashboard'));
|
|
actAsTab();
|
|
$this->get(route('admin.prelim_definitions.index'))->assertRedirect(route('dashboard'));
|
|
actAsAdmin();
|
|
$this->get(route('admin.prelim_definitions.index'))->assertViewIs('admin.prelim_definitions.index');
|
|
});
|
|
it('lists existing prelim definitions', function () {
|
|
$audition = Audition::factory()->create();
|
|
$prelim = PrelimDefinition::create([
|
|
'audition_id' => $audition->id,
|
|
'room_id' => 0,
|
|
'scoring_guide_id' => 0,
|
|
'passing_score' => 75,
|
|
]);
|
|
actAsAdmin();
|
|
$this->get(route('admin.prelim_definitions.index'))
|
|
->assertViewIs('admin.prelim_definitions.index')
|
|
->assertSee($audition->name);
|
|
});
|
|
});
|
|
|
|
describe('PrelimDefinitionController::create', function () {
|
|
it('denies access to a non-admin user', function () {
|
|
$this->get(route('admin.prelim_definitions.create'))->assertRedirect(route('home'));
|
|
actAsNormal();
|
|
$this->get(route('admin.prelim_definitions.create'))->assertRedirect(route('dashboard'));
|
|
actAsTab();
|
|
$this->get(route('admin.prelim_definitions.create'))->assertRedirect(route('dashboard'));
|
|
actAsAdmin();
|
|
$this->get(route('admin.prelim_definitions.create'))->assertViewIs('admin.prelim_definitions.createOrUpdate');
|
|
});
|
|
});
|
|
|
|
describe('PrelimDefinitionController::store', function () {
|
|
beforeEach(function () {
|
|
$this->audition = Audition::factory()->create();
|
|
});
|
|
it('denies access to a non-admin user', function () {
|
|
$this->post(route('admin.prelim_definitions.store'))->assertRedirect(route('home'));
|
|
actAsNormal();
|
|
$this->post(route('admin.prelim_definitions.store'))->assertRedirect(route('dashboard'));
|
|
actAsTab();
|
|
$this->post(route('admin.prelim_definitions.store'))->assertRedirect(route('dashboard'));
|
|
|
|
});
|
|
it('can store a new prelim audition', function () {
|
|
actAsAdmin();
|
|
$response = $this->post(route('admin.prelim_definitions.store'), [
|
|
'audition_id' => $this->audition->id,
|
|
'room_id' => 0,
|
|
'scoring_guide_id' => 0,
|
|
'passing_score' => 75,
|
|
]);
|
|
|
|
$response
|
|
->assertRedirect(route('admin.prelim_definitions.index'))
|
|
->assertSessionDoesntHaveErrors();
|
|
});
|
|
it('will not allow us to create two prelims for the same audition', function () {
|
|
actAsAdmin();
|
|
PrelimDefinition::create([
|
|
'audition_id' => $this->audition->id,
|
|
'room_id' => 0,
|
|
'scoring_guide_id' => 0,
|
|
'passing_score' => 75,
|
|
]);
|
|
|
|
$response = $this->from(route('admin.prelim_definitions.create'))
|
|
->post(route('admin.prelim_definitions.store'), [
|
|
'audition_id' => $this->audition->id,
|
|
'room_id' => 0,
|
|
'scoring_guide_id' => 0,
|
|
'passing_score' => 75,
|
|
]);
|
|
$response->assertSessionHasErrors('audition_id')
|
|
->assertRedirect(route('admin.prelim_definitions.create'));
|
|
});
|
|
});
|