171 lines
5.2 KiB
PHP
171 lines
5.2 KiB
PHP
<?php
|
|
|
|
use App\Models\Audition;
|
|
use App\Models\AuditionFlag;
|
|
use App\Models\Entry;
|
|
use App\Models\Event;
|
|
use App\Models\Room;
|
|
use App\Models\ScoringGuide;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
test('only returns open auditions for open scope', function () {
|
|
// Arrange
|
|
$openAudition = Audition::factory()->create();
|
|
Audition::factory()->closed()->create();
|
|
|
|
// Act & Assert
|
|
expect(Audition::open()->get())
|
|
->toHaveCount(1)
|
|
->first()->id->toEqual($openAudition->id);
|
|
});
|
|
|
|
it('only returns auditions for seating with forSeating scope', function () {
|
|
// Arrange
|
|
Audition::factory(['for_seating' => 0])->create();
|
|
$seatingAudition = Audition::factory()->create();
|
|
|
|
// Act & Assert
|
|
expect(Audition::forSeating()->get())
|
|
->toHaveCount(1)
|
|
->first()->id->toEqual($seatingAudition->id);
|
|
});
|
|
|
|
it('only returns auditions for advancement with for forAdvancement scope', function () {
|
|
// Arrange
|
|
Audition::factory(['for_advancement' => 0])->create();
|
|
$advancementAudition = Audition::factory()->create();
|
|
|
|
// Act & Assert
|
|
expect(Audition::forAdvancement()->get())
|
|
->toHaveCount(1)
|
|
->first()->id->toEqual($advancementAudition->id);
|
|
});
|
|
|
|
it('only returns published auditions for seatsPublished scope', function () {
|
|
// Arrange
|
|
Audition::factory()->create();
|
|
$published = Audition::factory()->create();
|
|
$published->addFlag('seats_published');
|
|
|
|
// Act & Assert
|
|
expect(Audition::seatsPublished()->get())
|
|
->toHaveCount(1)
|
|
->first()->id->toEqual($published->id);
|
|
|
|
});
|
|
|
|
it('only returns published advancement auditions for advancementPublished scope', function () {
|
|
// Arrange
|
|
Audition::factory()->create();
|
|
$published = Audition::factory()->create();
|
|
$published->addFlag('advancement_published');
|
|
|
|
// Act & Assert
|
|
expect(Audition::advancementPublished()->get())
|
|
->toHaveCount(1)
|
|
->first()->id->toEqual($published->id);
|
|
|
|
});
|
|
|
|
it('has an event', function () {
|
|
// Arrange
|
|
$event = Event::factory()->create(['name' => 'Symphonic Concert Wind Ensemble Band']);
|
|
$audition = Audition::factory()->create(['event_id' => $event->id]);
|
|
// Act & Assert
|
|
expect($audition->event->name)->toEqual('Symphonic Concert Wind Ensemble Band');
|
|
|
|
});
|
|
|
|
it('has entries', function () {
|
|
// Arrange
|
|
$audition = Audition::factory()->create();
|
|
Entry::factory()->count(10)->create(['audition_id' => $audition->id]);
|
|
// Act & Assert
|
|
expect($audition->entries->count())->toEqual(10);
|
|
});
|
|
|
|
it('has a room', function () {
|
|
// Arrange
|
|
$room = Room::factory()->create(['name' => 'Room 1']);
|
|
$audition = Audition::factory()->create(['room_id' => $room->id]);
|
|
|
|
// Act & Assert
|
|
expect($audition->room->name)->toEqual('Room 1');
|
|
|
|
});
|
|
|
|
it('has a scoring guide', function () {
|
|
// Arrange
|
|
$sg = ScoringGuide::factory()->create(['name' => 'Sight Reading']);
|
|
$audition = Audition::factory()->create(['scoring_guide_id' => $sg->id]);
|
|
// Act & Assert
|
|
expect($audition->scoringGuide->name)->toEqual('Sight Reading');
|
|
|
|
});
|
|
|
|
it('displays the entry fee', function () {
|
|
// Arrange
|
|
$audition = Audition::factory()->create(['entry_fee' => 1000]);
|
|
// Act & Assert
|
|
expect($audition->display_fee())->toEqual('$10.00');
|
|
});
|
|
|
|
it('has many judges', function () {
|
|
// Arrange
|
|
$room = Room::factory()->create();
|
|
$audition = Audition::factory()->create(['room_id' => $room->id]);
|
|
$judges = User::factory()->count(5)->create();
|
|
foreach ($judges as $judge) {
|
|
$room->addJudge($judge->id);
|
|
}
|
|
// Act & Assert
|
|
expect($audition->judges->count())->toEqual(5);
|
|
});
|
|
|
|
it('has a judges_count available', function () {
|
|
// Arrange
|
|
$room = Room::factory()->create();
|
|
$audition = Audition::factory()->create(['room_id' => $room->id]);
|
|
$judges = User::factory()->count(5)->create();
|
|
foreach ($judges as $judge) {
|
|
$room->addJudge($judge->id);
|
|
}
|
|
// Act & Assert
|
|
expect($audition->judges_count)->toEqual(5);
|
|
});
|
|
|
|
it('can have flags', function () {
|
|
// Arrange
|
|
$audition = Audition::factory()->create();
|
|
AuditionFlag::create(['audition_id' => $audition->id, 'flag_name' => 'seats_published']);
|
|
AuditionFlag::create(['audition_id' => $audition->id, 'flag_name' => 'advance_published']);
|
|
// Act
|
|
// Assert
|
|
expect($audition->hasFlag('seats_published'))->toBeTrue();
|
|
expect($audition->hasFlag('notaflag'))->toBeFalse();
|
|
expect($audition->flags->count())->toEqual(2);
|
|
});
|
|
|
|
it('can add flags', function () {
|
|
// Arrange
|
|
$audition = Audition::factory()->create();
|
|
// Act
|
|
$audition->addFlag('seats_published');
|
|
// Assert
|
|
expect($audition->hasFlag('seats_published'))->toBeTrue();
|
|
});
|
|
|
|
it('can remove flags', function () {
|
|
// Arrange
|
|
$audition = Audition::factory()->create();
|
|
AuditionFlag::create(['audition_id' => $audition->id, 'flag_name' => 'seats_published']);
|
|
// Act & Assert
|
|
$audition->addFlag('seats_published');
|
|
expect($audition->hasFlag('seats_published'))->toBeTrue();
|
|
$audition->removeFlag('seats_published');
|
|
expect($audition->hasFlag('seats_published'))->toBeFalse();
|
|
});
|