90 lines
3.2 KiB
PHP
90 lines
3.2 KiB
PHP
<?php
|
|
|
|
use App\Models\Audition;
|
|
use App\Models\Ensemble;
|
|
use App\Models\Entry;
|
|
use App\Models\Event;
|
|
use App\Models\Seat;
|
|
use App\Models\SeatingLimit;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('has an event', function () {
|
|
$event = Event::factory()->create();
|
|
$ensemble = Ensemble::factory()->create(['event_id' => $event->id]);
|
|
expect($ensemble->event)->toBeInstanceOf(Event::class)
|
|
->and($ensemble->event->name)->toBe($event->name);
|
|
});
|
|
|
|
it('has auditions in score order', function () {
|
|
// Arrange
|
|
$ensemble = Ensemble::factory()->create();
|
|
$oboe = Audition::factory()->create(['event_id' => $ensemble->event_id, 'name' => 'Oboe', 'score_order' => 2]);
|
|
$flute = Audition::factory()->create(['event_id' => $ensemble->event_id, 'name' => 'Flute', 'score_order' => 1]);
|
|
$clarinet = Audition::factory()->create(['event_id' => $ensemble->event_id, 'name' => 'Clarinet',
|
|
'score_order' => 3,
|
|
]);
|
|
// Act & Assert
|
|
expect($ensemble->auditions)->toHaveCount(3)
|
|
->sequence(
|
|
fn ($seatingLimit) => $seatingLimit->audition_id === $flute->id,
|
|
fn ($seatingLimit) => $seatingLimit->audition_id === $oboe->id,
|
|
fn ($seatingLimit) => $seatingLimit->audition_id === $clarinet->id,
|
|
);
|
|
|
|
});
|
|
|
|
it('has seating limits',
|
|
function () {
|
|
// Arrange
|
|
$ensemble = Ensemble::factory()->create();
|
|
$auditions = Audition::factory()->count(3)->create(['event_id' => $ensemble->event_id]);
|
|
foreach ($auditions as $audition) {
|
|
SeatingLimit::create([
|
|
'ensemble_id' => $ensemble->id, 'audition_id' => $audition->id,
|
|
'maximum_accepted' => fake()->numberBetween(1, 10),
|
|
]);
|
|
}
|
|
// Act & Assert
|
|
expect($ensemble->seatingLimits)->toHaveCount(3);
|
|
});
|
|
|
|
it('has seats', function () {
|
|
// Arrange
|
|
$ensemble = Ensemble::factory()->create();
|
|
$audition = Audition::factory()->create(['event_id' => $ensemble->event_id]);
|
|
$entry = Entry::factory()->create(['audition_id' => $audition->id]);
|
|
$seat = Seat::create([
|
|
'ensemble_id' => $ensemble->id,
|
|
'audition_id' => $audition->id,
|
|
'seat' => 1,
|
|
'entry_id' => $entry->id,
|
|
]);
|
|
// Act & Assert
|
|
expect($ensemble->seats)->toHaveCount(1)
|
|
->and($ensemble->seats->first()->seat)->toBe(1);
|
|
|
|
});
|
|
|
|
it('returns only ensembles for a given audition in the audition scope', function () {
|
|
// Arrange
|
|
$audition = Audition::factory()->create();
|
|
$ensemble = Ensemble::factory()->create(['event_id' => $audition->event_id]);
|
|
$ensemble2 = Ensemble::factory()->create(['event_id' => $audition->event_id]);
|
|
$ensemble3 = Ensemble::factory()->create();
|
|
// Act & Assert
|
|
expect(Ensemble::forAudition($audition->id)->get())->toHaveCount(2);
|
|
});
|
|
|
|
it('returns only ensembles for a given event in the event scope', function () {
|
|
// Arrange
|
|
$event = Event::factory()->create();
|
|
$ensemble = Ensemble::factory()->create(['event_id' => $event->id]);
|
|
$ensemble2 = Ensemble::factory()->create(['event_id' => $event->id]);
|
|
$ensemble3 = Ensemble::factory()->create();
|
|
// Act & Assert
|
|
expect(Ensemble::forEvent($event->id)->get())->toHaveCount(2);
|
|
|
|
});
|