119 lines
4.3 KiB
PHP
119 lines
4.3 KiB
PHP
<?php
|
|
|
|
use App\Models\Audition;
|
|
use App\Models\Entry;
|
|
use App\Models\Student;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
use function Pest\Laravel\assertDatabaseHas;
|
|
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 their 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));
|
|
});
|
|
it('can create an entry', function () {
|
|
$audition = Audition::factory()->create(['maximum_grade' => 12, 'minimum_grade' => 7]);
|
|
$student = Student::factory()->create(['grade' => 9]);
|
|
actAsAdmin();
|
|
$response = $this->post(route('admin.entries.store'), [
|
|
'student_id' => $student->id,
|
|
'audition_id' => $audition->id,
|
|
'for_seating' => 'on',
|
|
]);
|
|
$response->assertRedirect(route('admin.entries.index'))
|
|
->assertSessionDoesntHaveErrors()
|
|
->assertSessionHas('success', 'The entry has been added.');
|
|
assertDatabaseHas('entries', [
|
|
'student_id' => $student->id,
|
|
'audition_id' => $audition->id,
|
|
'for_seating' => 1,
|
|
'for_advancement' => 0,
|
|
]);
|
|
});
|
|
it('can create a late entry', function () {
|
|
$audition = Audition::factory()->closed()->create(['maximum_grade' => 12, 'minimum_grade' => 7]);
|
|
$student = Student::factory()->create(['grade' => 9]);
|
|
actAsAdmin();
|
|
$response = $this->post(route('admin.entries.store'), [
|
|
'student_id' => $student->id,
|
|
'audition_id' => $audition->id,
|
|
'for_seating' => 'on',
|
|
]);
|
|
$response->assertRedirect(route('admin.entries.index'))
|
|
->assertSessionDoesntHaveErrors()
|
|
->assertSessionMissing('error')
|
|
->assertSessionHas('success', 'The entry has been added.');
|
|
assertDatabaseHas('entries', [
|
|
'student_id' => $student->id,
|
|
'audition_id' => $audition->id,
|
|
'for_seating' => 1,
|
|
'for_advancement' => 0,
|
|
]);
|
|
});
|
|
it('can mark a late fee waived for an entry', function () {
|
|
$audition = Audition::factory()->closed()->create(['maximum_grade' => 12, 'minimum_grade' => 7]);
|
|
$student = Student::factory()->create(['grade' => 9]);
|
|
actAsAdmin();
|
|
$response = $this->post(route('admin.entries.store'), [
|
|
'student_id' => $student->id,
|
|
'audition_id' => $audition->id,
|
|
'for_seating' => 'on',
|
|
'late_fee_waived' => 'on',
|
|
]);
|
|
$response->assertRedirect(route('admin.entries.index'))
|
|
->assertSessionDoesntHaveErrors()
|
|
->assertSessionMissing('error')
|
|
->assertSessionHas('success', 'The entry has been added.');
|
|
assertDatabaseHas('entries', [
|
|
'student_id' => $student->id,
|
|
'audition_id' => $audition->id,
|
|
'for_seating' => 1,
|
|
'for_advancement' => 0,
|
|
]);
|
|
$entry = Entry::where('student_id', $student->id)->where('audition_id', $audition->id)->first();
|
|
|
|
assertDatabaseHas('entry_flags', [
|
|
'entry_id' => 1,
|
|
'flag_name' => 'late_fee_waived',
|
|
]);
|
|
|
|
});
|