71 lines
2.3 KiB
PHP
71 lines
2.3 KiB
PHP
<?php
|
|
|
|
use App\Models\Audition;
|
|
use App\Models\Entry;
|
|
use App\Models\Room;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
$this->room = Room::factory()->create();
|
|
$otherRoom = Room::factory()->create();
|
|
$auditions = Audition::factory()->count(3)->create(['room_id' => $this->room->id]);
|
|
foreach ($auditions as $audition) {
|
|
Entry::factory()->count(5)->create(['audition_id' => $audition->id]);
|
|
}
|
|
$otherAuditions = Audition::factory()->count(3)->create(['room_id' => $otherRoom->id]);
|
|
foreach ($otherAuditions as $audition) {
|
|
Entry::factory()->count(5)->create(['audition_id' => $audition->id]);
|
|
}
|
|
});
|
|
|
|
test('created 30 entries in prep', function () {
|
|
expect(Entry::all()->count())->toBe(30);
|
|
});
|
|
|
|
it('has auditions', function () {
|
|
expect($this->room->auditions->count())->toBe(3)
|
|
->and($this->room->auditions->first())->toBeInstanceOf(Audition::class);
|
|
});
|
|
|
|
it('has entries', function () {
|
|
expect($this->room->entries->count())->toBe(15)
|
|
->and($this->room->entries->first())->toBeInstanceOf(Entry::class);
|
|
});
|
|
|
|
it('has users', function () {
|
|
$user = User::factory()->create();
|
|
$this->room->users()->attach($user->id);
|
|
expect($this->room->users->count())->toBe(1)
|
|
->and($this->room->users->first()->first_name)->toBe($user->first_name);
|
|
});
|
|
|
|
it('has judges', function () {
|
|
$user = User::factory()->create();
|
|
$this->room->judges()->attach($user->id);
|
|
expect($this->room->judges->count())->toBe(1)
|
|
->and($this->room->judges->first()->first_name)->toBe($user->first_name);
|
|
});
|
|
|
|
it('can add a judge', function () {
|
|
$user = User::factory()->create();
|
|
$this->room->addJudge($user->id);
|
|
expect($this->room->judges->count())->toBe(1)
|
|
->and($this->room->judges->first()->first_name)->toBe($user->first_name);
|
|
});
|
|
|
|
it('can remove a judge', function () {
|
|
// Arrange
|
|
$user = User::factory()->create();
|
|
$this->room->addJudge($user->id);
|
|
// Act & Assert
|
|
expect($this->room->judges->count())->toBe(1)
|
|
->and($this->room->judges->first()->first_name)->toBe($user->first_name);
|
|
// Re Act
|
|
$this->room->removeJudge($user->id);
|
|
// Reassert
|
|
expect($this->room->judges->count())->toBe(0);
|
|
});
|