176 lines
7.1 KiB
PHP
176 lines
7.1 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'));
|
|
});
|
|
});
|
|
|
|
describe('PrelimDefinitionController::edit', function () {
|
|
beforeEach(function () {
|
|
$this->audition = Audition::factory()->create();
|
|
$this->prelim = PrelimDefinition::create([
|
|
'audition_id' => $this->audition->id,
|
|
'room_id' => 0,
|
|
'scoring_guide_id' => 0,
|
|
'passing_score' => 75,
|
|
]);
|
|
});
|
|
it('denies access to a non-admin user', function () {
|
|
$this->get(route('admin.prelim_definitions.edit', $this->prelim))->assertRedirect(route('home'));
|
|
actAsNormal();
|
|
$this->get(route('admin.prelim_definitions.edit', $this->prelim))->assertRedirect(route('dashboard'));
|
|
actAsTab();
|
|
$this->get(route('admin.prelim_definitions.edit', $this->prelim))->assertRedirect(route('dashboard'));
|
|
});
|
|
it('shows a form to edit a prelim definition', function () {
|
|
actAsAdmin();
|
|
$response = $this->get(route('admin.prelim_definitions.edit', $this->prelim))
|
|
->assertViewIs('admin.prelim_definitions.createOrUpdate')
|
|
->assertSee($this->audition->name)
|
|
->assertSee('PATCH')
|
|
->assertSee(route('admin.prelim_definitions.update', $this->prelim));
|
|
});
|
|
});
|
|
|
|
describe('PrelimDefinitionController::update', function () {
|
|
beforeEach(function () {
|
|
$this->audition = Audition::factory()->create();
|
|
$this->prelim = PrelimDefinition::create([
|
|
'audition_id' => $this->audition->id,
|
|
'room_id' => 0,
|
|
'scoring_guide_id' => 0,
|
|
'passing_score' => 75,
|
|
]);
|
|
});
|
|
it('denies access to a non-admin user', function () {
|
|
$this->patch(route('admin.prelim_definitions.update', $this->prelim))->assertRedirect(route('home'));
|
|
actAsNormal();
|
|
$this->patch(route('admin.prelim_definitions.update', $this->prelim))->assertRedirect(route('dashboard'));
|
|
actAsTab();
|
|
$this->patch(route('admin.prelim_definitions.update', $this->prelim))->assertRedirect(route('dashboard'));
|
|
});
|
|
it('can update a prelim definition', function () {
|
|
actAsAdmin();
|
|
$response = $this->patch(route('admin.prelim_definitions.update', $this->prelim), [
|
|
'audition_id' => $this->audition->id,
|
|
'room_id' => 0,
|
|
'scoring_guide_id' => 0,
|
|
'passing_score' => 90,
|
|
]);
|
|
$response
|
|
->assertRedirect(route('admin.prelim_definitions.index'));
|
|
expect($this->prelim->fresh()->passing_score)->toEqual(90);
|
|
});
|
|
});
|
|
|
|
describe('PrelimDefinitionController::destroy', function () {
|
|
beforeEach(function () {
|
|
$this->audition = Audition::factory()->create();
|
|
$this->prelim = PrelimDefinition::create([
|
|
'audition_id' => $this->audition->id,
|
|
'room_id' => 0,
|
|
'scoring_guide_id' => 0,
|
|
'passing_score' => 75,
|
|
]);
|
|
});
|
|
it('denies access to a non-admin user', function () {
|
|
$this->delete(route('admin.prelim_definitions.destroy', $this->prelim))->assertRedirect(route('home'));
|
|
actAsNormal();
|
|
$this->delete(route('admin.prelim_definitions.destroy', $this->prelim))->assertRedirect(route('dashboard'));
|
|
actAsTab();
|
|
$this->delete(route('admin.prelim_definitions.destroy', $this->prelim))->assertRedirect(route('dashboard'));
|
|
});
|
|
|
|
it('deletes a prelim definition', function () {
|
|
actAsAdmin();
|
|
$response = $this->delete(route('admin.prelim_definitions.destroy', $this->prelim));
|
|
$response
|
|
->assertRedirect(route('admin.prelim_definitions.index'));
|
|
expect(PrelimDefinition::count())->toEqual(0);
|
|
});
|
|
});
|