Add scopes to models #10
|
|
@ -191,4 +191,14 @@ class Audition extends Model
|
||||||
{
|
{
|
||||||
$query->where('entry_deadline', '>=', Carbon::now());
|
$query->where('entry_deadline', '>=', Carbon::now());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scopeForSeating(Builder $query): void
|
||||||
|
{
|
||||||
|
$query->where('for_seating', 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function scopeForAdvancement(Builder $query): void
|
||||||
|
{
|
||||||
|
$query->where('for_advancement', 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,3 +15,25 @@ test('only returns open auditions for open scope', function () {
|
||||||
->toHaveCount(1)
|
->toHaveCount(1)
|
||||||
->first()->id->toEqual($openAudition->id);
|
->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);
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue