74 lines
2.5 KiB
PHP
74 lines
2.5 KiB
PHP
<?php
|
|
|
|
use App\Models\Audition;
|
|
use App\Models\Entry;
|
|
use App\Models\Student;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
use function Pest\Laravel\get;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
$this->audition = Audition::factory()->create();
|
|
$this->r = route('seating.audition', $this->audition);
|
|
});
|
|
|
|
it('denies access to a guest', function () {
|
|
get($this->r)
|
|
->assertRedirect(route('home'));
|
|
});
|
|
|
|
it('denies access to a normal user', function () {
|
|
actAsNormal();
|
|
get($this->r)
|
|
->assertRedirect(route('dashboard'))
|
|
->assertSessionHas('error', 'You are not authorized to perform this action');
|
|
});
|
|
it('grants access to admin', function () {
|
|
// Arrange
|
|
actAsAdmin();
|
|
// Act & Assert
|
|
get($this->r)->assertOk();
|
|
});
|
|
it('grants access to tabulators', function () {
|
|
// Arrange
|
|
actAsTab();
|
|
// Act & Assert
|
|
get($this->r)->assertOk();
|
|
});
|
|
// TODO make tests with varied information
|
|
it('returns the audition object and an array of info on each entry', function () {
|
|
// Arrange
|
|
$entry = Entry::factory()->create(['audition_id' => $this->audition->id]);
|
|
actAsAdmin();
|
|
// Act
|
|
$response = get($this->r);
|
|
$response
|
|
->assertOk()
|
|
->assertViewHas('audition', $this->audition);
|
|
$viewData = $response->viewData('entryData');
|
|
expect($viewData[0]['rank'])->toBe(1);
|
|
expect($viewData[0]['id'])->toBe($entry->id);
|
|
expect($viewData[0]['studentName'])->toBe($entry->student->full_name());
|
|
expect($viewData[0]['schoolName'])->toBe($entry->student->school->name);
|
|
expect($viewData[0]['drawNumber'])->toBe($entry->draw_number);
|
|
expect($viewData[0]['totalScore'])->toBe('No Score');
|
|
expect($viewData[0]['fullyScored'])->toBeFalse();
|
|
});
|
|
it('identifies a doubler', function () {
|
|
// Arrange
|
|
$audition1 = Audition::factory()->create(['event_id' => $this->audition->event_id]);
|
|
$audition2 = Audition::factory()->create(['event_id' => $this->audition->event_id]);
|
|
$student = Student::factory()->create();
|
|
Entry::factory()->create(['audition_id' => $audition1->id, 'student_id' => $student->id]);
|
|
Entry::factory()->create(['audition_id' => $audition2->id, 'student_id' => $student->id]);
|
|
Entry::factory()->create(['audition_id' => $this->audition->id, 'student_id' => $student->id]);
|
|
actAsAdmin();
|
|
// Act & Assert
|
|
$response = get($this->r);
|
|
$response->assertOk();
|
|
$viewData = $response->viewData('entryData');
|
|
expect($viewData[0]['isDoubler'])->toBeTrue();
|
|
});
|