50 lines
1.7 KiB
PHP
50 lines
1.7 KiB
PHP
<?php
|
|
|
|
use App\Models\Audition;
|
|
use App\Models\Student;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
use function Pest\Laravel\get;
|
|
use function PHPUnit\Framework\assertEquals;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('does not respond to an ordinary user', function () {
|
|
actAsNormal();
|
|
get(route('admin.entries.create'))
|
|
->assertRedirect(route('dashboard'));
|
|
});
|
|
it('does not respond to a guest', function () {
|
|
// Act & Assert
|
|
get(route('admin.entries.create'))
|
|
->assertRedirect(route('home'));
|
|
});
|
|
it('passes a collection of all students with thier schools to the view', function () {
|
|
// Arrange
|
|
Student::factory()->count(8)->create();
|
|
$students = Student::with('school')->orderBy('last_name')->orderBy('first_name')->get();
|
|
actAsAdmin();
|
|
// Act & Assert
|
|
get(route('admin.entries.create'))
|
|
->assertViewHas('students', $students);
|
|
});
|
|
it('passes a collection of available auditions to the view', function () {
|
|
// Arrange
|
|
for ($i = 3; $i < 9; $i++) {
|
|
Audition::factory()->create(['score_order' => $i]);
|
|
}
|
|
Audition::factory()->count(5)->create();
|
|
$auditions = Audition::with('flags')->orderBy('score_order')->get();
|
|
$auditions = $auditions->toArray();
|
|
$seatedAudition = Audition::factory()->create(['score_order' => 1]);
|
|
$seatedAudition->addFlag('seats_published');
|
|
$advancedAudition = Audition::factory()->create(['score_order' => 2]);
|
|
$advancedAudition->addFlag('advancement_published');
|
|
actAsAdmin();
|
|
// Act & Assert
|
|
$response = get(route('admin.entries.create'));
|
|
$viewAuditions = $response->viewData('auditions')->toArray();
|
|
$response->assertOk();
|
|
assertEquals(array_values($auditions), array_values($viewAuditions));
|
|
});
|