auditionadmin/tests-old/Feature/Pages/Setup/DrawEditTest.php

77 lines
2.5 KiB
PHP

<?php
use App\Models\Audition;
use App\Models\Entry;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
it('only allows admin users to manage the draw', function () {
$this->get(route('admin.draw.edit'))
->assertRedirect(route('home'));
actAsNormal();
$this->get(route('admin.draw.edit'))
->assertSessionHas('error', 'You are not authorized to perform this action')
->assertRedirect(route('dashboard'));
actAsAdmin();
$this->get(route('admin.draw.edit'))
->assertOk()
->assertViewIs('admin.draw.edit');
});
it('lists auditions that have been drawn', function () {
$audition = Audition::factory()->create();
$drawnAudition = Audition::factory()->create();
$drawnAudition->addFlag('drawn');
actAsAdmin();
$response = $this->get(route('admin.draw.edit'));
$response->assertOk()
->assertSee($drawnAudition->name)
->assertDontSee($audition->name);
});
it('has a warning message', function () {
actAsAdmin();
$response = $this->get(route('admin.draw.edit'));
$response->assertOk()
->assertSee('Caution');
});
it('submits to the admin.draw.destroy route', function () {
actAsAdmin();
$this->get(route('admin.draw.edit'))
->assertOk()
->assertSee(route('admin.draw.destroy'));
});
it('does not allow a non-admin user to clear a draw', function () {
$this->delete(route('admin.draw.destroy'))
->assertRedirect(route('home'));
actAsNormal();
$this->delete(route('admin.draw.destroy'))
->assertSessionHas('error', 'You are not authorized to perform this action')
->assertRedirect(route('dashboard'));
});
it('allows an administrator to clear a draw', function () {
$audition = Audition::factory()->create();
$audition->addFlag('drawn');
$entries = Entry::factory()->count(3)->create(['audition_id' => $audition->id]);
$n = 1;
$entries->each(function ($entry) use (&$n) {
$entry->draw_number = $n;
$entry->save();
$n++;
});
actAsAdmin();
/** @noinspection PhpUnhandledExceptionInspection */
$this->delete(route('admin.draw.destroy'), ['audition' => [$audition->id => 'on']])
->assertSessionHasNoErrors()
->assertRedirect(route('admin.draw.index'));
$entries->each(function ($entry) {
$entry->refresh();
expect($entry->draw_number)->toBeNull();
});
$checkAudition = Audition::find($audition->id);
expect($checkAudition->hasFlag('drawn'))->toBeFalse();
});