93 lines
4.0 KiB
PHP
93 lines
4.0 KiB
PHP
<?php
|
|
|
|
use App\Models\Audition;
|
|
use App\Models\Entry;
|
|
use App\Models\EntryTotalScore;
|
|
use App\Models\Event;
|
|
use App\Models\Student;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
$this->event = Event::factory()->create();
|
|
$this->ASaudition = Audition::factory()->create(['event_id' => $this->event->id, 'name' => 'Alto Sax']);
|
|
$this->TSaudition = Audition::factory()->create(['event_id' => $this->event->id, 'name' => 'Tenor Sax']);
|
|
$this->BSaudition = Audition::factory()->create(['event_id' => $this->event->id, 'name' => 'Bari Sax']);
|
|
$this->student = Student::factory()->create();
|
|
$this->ASentry = Entry::factory()->create([
|
|
'audition_id' => $this->ASaudition->id, 'student_id' => $this->student->id,
|
|
]);
|
|
$this->TSentry = Entry::factory()->create([
|
|
'audition_id' => $this->TSaudition->id, 'student_id' => $this->student->id,
|
|
]);
|
|
$this->BSentry = Entry::factory()->create([
|
|
'audition_id' => $this->BSaudition->id, 'student_id' => $this->student->id,
|
|
]);
|
|
DB::table('entry_total_scores')->insert([
|
|
'entry_id' => $this->ASentry->id,
|
|
'seating_total' => 34,
|
|
'advancement_total' => 4,
|
|
'seating_subscore_totals' => json_encode([22, 2]),
|
|
'advancement_subscore_totals' => json_encode([22, 2]),
|
|
]);
|
|
DB::table('entry_total_scores')->insert([
|
|
'entry_id' => $this->TSentry->id,
|
|
'seating_total' => 34,
|
|
'advancement_total' => 4,
|
|
'seating_subscore_totals' => json_encode([22, 2]),
|
|
'advancement_subscore_totals' => json_encode([22, 2]),
|
|
]);
|
|
DB::table('entry_total_scores')->insert([
|
|
'entry_id' => $this->BSentry->id,
|
|
'seating_total' => 34,
|
|
'advancement_total' => 4,
|
|
'seating_subscore_totals' => json_encode([22, 2]),
|
|
'advancement_subscore_totals' => json_encode([22, 2]),
|
|
]);
|
|
});
|
|
|
|
describe('DoublerDecisionController::accept', function () {
|
|
it('denies access to normal users and guests', function () {
|
|
$this->post(route('doubler.accept', $this->ASentry))->assertRedirect(route('home'));
|
|
actAsNormal();
|
|
$this->post(route('doubler.accept', $this->ASentry))->assertRedirect(route('dashboard'));
|
|
});
|
|
it('can accept an entry', function () {
|
|
actAsAdmin();
|
|
$response = $this->post(route('doubler.accept', $this->ASentry));
|
|
$response->assertRedirect()->assertSessionHas('success');
|
|
expect($this->ASentry->fresh()->hasFlag('declined'))->toBeFalse();
|
|
expect($this->TSentry->fresh()->hasFlag('declined'))->toBeTrue();
|
|
expect($this->BSentry->fresh()->hasFlag('declined'))->toBeTrue();
|
|
});
|
|
it('catches exceptions for invalid requests', function () {
|
|
actAsAdmin();
|
|
EntryTotalScore::truncate();
|
|
$response = $this->post(route('doubler.accept', $this->ASentry));
|
|
$response->assertRedirect()->assertSessionHas('error');
|
|
});
|
|
});
|
|
|
|
describe('DoublerDecisionController::decline', function () {
|
|
it('denies access to normal users and guests', function () {
|
|
$this->post(route('doubler.decline', $this->ASentry))->assertRedirect(route('home'));
|
|
actAsNormal();
|
|
$this->post(route('doubler.decline', $this->ASentry))->assertRedirect(route('dashboard'));
|
|
});
|
|
it('can decline an entry', function () {
|
|
actAsAdmin();
|
|
$response = $this->post(route('doubler.decline', $this->ASentry));
|
|
$response->assertRedirect()->assertSessionHas('success');
|
|
expect($this->ASentry->fresh()->hasFlag('declined'))->toBeTrue();
|
|
expect($this->TSentry->fresh()->hasFlag('declined'))->toBeFalse();
|
|
expect($this->BSentry->fresh()->hasFlag('declined'))->toBeFalse();
|
|
});
|
|
it('catches exceptions for invalid requests', function () {
|
|
actAsAdmin();
|
|
EntryTotalScore::truncate();
|
|
$response = $this->post(route('doubler.decline', $this->ASentry));
|
|
$response->assertRedirect()->assertSessionHas('error');
|
|
});
|
|
});
|