108 lines
3.9 KiB
PHP
108 lines
3.9 KiB
PHP
<?php
|
|
|
|
use App\Actions\Entries\CreateEntry;
|
|
use App\Exceptions\ManageEntryException;
|
|
use App\Models\Audition;
|
|
use App\Models\School;
|
|
use App\Models\Student;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
use function Pest\Laravel\actingAs;
|
|
use function Pest\Laravel\get;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('denies a guest', function () {
|
|
$request = get(route('doubler_request.index'));
|
|
$request->assertRedirect(route('home'));
|
|
});
|
|
it('denies access to a user with no school', function () {
|
|
// Arrange
|
|
actAsNormal();
|
|
// Act & Assert
|
|
get(route('doubler_request.index'))
|
|
->assertStatus(405);
|
|
});
|
|
it('allows access to a user with a school', function () {
|
|
// Arrange
|
|
$school = School::factory()->create();
|
|
$user = User::factory()->create(['school_id' => $school->id]);
|
|
actingAs($user);
|
|
// Act & Assert
|
|
get(route('doubler_request.index'))
|
|
->assertOk()
|
|
->assertSessionHasNoErrors();
|
|
});
|
|
it('includes a section for each event', function () {
|
|
// Arrange
|
|
$events = \App\Models\Event::factory()->count(3)->create();
|
|
$school = School::factory()->create();
|
|
$user = User::factory()->create(['school_id' => $school->id]);
|
|
actingAs($user);
|
|
// Act & Assert
|
|
$response = get(route('doubler_request.index'));
|
|
$response->assertOk()
|
|
->assertViewHas('events', \App\Models\Event::all());
|
|
foreach ($events as $event) {
|
|
$response->assertSee($event->name);
|
|
}
|
|
});
|
|
it(/**
|
|
* @throws ManageEntryException
|
|
*/ 'includes all doublers for the users school', function () {
|
|
// Arrange
|
|
$school = School::factory()->create();
|
|
$user = User::factory()->create(['school_id' => $school->id]);
|
|
$concert_event = \App\Models\Event::create(['name' => 'Concert Band']);
|
|
$jazz_event = \App\Models\Event::create(['name' => 'Jazz Band']);
|
|
$jas_audition = Audition::factory()->create([
|
|
'name' => 'Jazz Alto Sax',
|
|
'event_id' => $jazz_event->id,
|
|
'minimum_grade' => 1,
|
|
'maximum_grade' => 99,
|
|
]);
|
|
$jts_audition = Audition::factory()->create([
|
|
'name' => 'Jazz Tenor Sax',
|
|
'event_id' => $jazz_event->id,
|
|
'minimum_grade' => 1,
|
|
'maximum_grade' => 99,
|
|
]);
|
|
$cas_audition = Audition::factory()->create([
|
|
'name' => 'Alto Sax',
|
|
'event_id' => $concert_event->id,
|
|
'minimum_grade' => 1,
|
|
'maximum_grade' => 99,
|
|
]);
|
|
$cts_audition = Audition::factory()->create([
|
|
'name' => 'Tenor Sax',
|
|
'event_id' => $concert_event->id,
|
|
'minimum_grade' => 1,
|
|
'maximum_grade' => 99,
|
|
]);
|
|
$concert_student = Student::factory()->create(['school_id' => $school->id]);
|
|
$jazz_student = Student::factory()->create(['school_id' => $school->id]);
|
|
$singleton_student = Student::factory()->create(['school_id' => $school->id]);
|
|
$other_school_student = Student::factory()->create();
|
|
$entryCreator = new CreateEntry();
|
|
$entryCreator->createEntry($concert_student, $cas_audition);
|
|
$entryCreator->createEntry($singleton_student, $cas_audition);
|
|
$entryCreator->createEntry($concert_student, $cts_audition);
|
|
$entryCreator->createEntry($jazz_student, $jas_audition);
|
|
$entryCreator->createEntry($jazz_student, $jts_audition);
|
|
$entryCreator->createEntry($singleton_student, $jts_audition);
|
|
$entryCreator->createEntry($other_school_student, $cas_audition);
|
|
$entryCreator->createEntry($other_school_student, $cts_audition);
|
|
$entryCreator->createEntry($other_school_student, $jts_audition);
|
|
$entryCreator->createEntry($other_school_student, $jas_audition);
|
|
actingAs($user);
|
|
// Act
|
|
$response = get(route('doubler_request.index'));
|
|
// Assert
|
|
$response->assertOk()
|
|
->assertSee($concert_student->full_name())
|
|
->assertSee($jazz_student->full_name())
|
|
->assertDontSee($singleton_student->full_name())
|
|
->assertDontSee($other_school_student->full_name());
|
|
});
|