diff --git a/app/Models/Audition.php b/app/Models/Audition.php index dfa3057..160f6db 100644 --- a/app/Models/Audition.php +++ b/app/Models/Audition.php @@ -2,6 +2,8 @@ namespace App\Models; +use Carbon\Carbon; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -24,7 +26,6 @@ class Audition extends Model protected $scored_entries_count; //Set by TabulationService - public static function deadlineNotPast() { return Audition::where('entry_deadline', '>=', now())->get(); @@ -185,4 +186,9 @@ class Audition extends Model // remove related auditionFlag where flag_name = $flag $this->flags()->where('flag_name', $flag)->delete(); } + + public function scopeOpen(Builder $query): void + { + $query->where('entry_deadline', '>=', Carbon::now()); + } } diff --git a/database/factories/AuditionFactory.php b/database/factories/AuditionFactory.php index 3b52d27..4cefeff 100644 --- a/database/factories/AuditionFactory.php +++ b/database/factories/AuditionFactory.php @@ -2,6 +2,8 @@ namespace Database\Factories; +use App\Models\Event; +use Carbon\Carbon; use Illuminate\Database\Eloquent\Factories\Factory; /** @@ -16,8 +18,44 @@ class AuditionFactory extends Factory */ public function definition(): array { + $instruments = [ + 'Flute', + 'Oboe', + 'Clarinet', + 'Bass Clarinet', + 'Contra Clarinet', + 'Bassoon', + 'Alto Sax', + 'Tenor Sax', + 'Bari Sax', + 'Trumpet', + 'Horn', + 'Trombone', + 'Euphonium', + 'Tuba', + 'String Bass', + 'Percussion', + ]; + + $event = Event::factory()->create(); + return [ - // + 'event_id' => $event->id, + 'name' => $this->faker->randomElement($instruments).$this->faker->randomNumber(1), + 'score_order' => 1, + 'entry_deadline' => Carbon::tomorrow(), + 'entry_fee' => 1000, + 'minimum_grade' => 7, + 'maximum_grade' => 12, + 'for_seating' => 1, + 'for_advancement' => 1, ]; } + + public function closed(?Carbon $entryDeadline = null): self + { + return $this->state( + fn (array $attributes) => ['entry_deadline' => $entryDeadline ?? Carbon::yesterday()] + ); + } } diff --git a/database/factories/EventFactory.php b/database/factories/EventFactory.php index 19b0bf9..006a07b 100644 --- a/database/factories/EventFactory.php +++ b/database/factories/EventFactory.php @@ -17,7 +17,9 @@ class EventFactory extends Factory public function definition(): array { return [ - 'name' => 'Concert Band Auditions' + 'name' => $this->faker->randomElement([ + 'Concert Auditions', 'Jazz Auditions ', + ]).$this->faker->randomNumber(1), ]; } } diff --git a/resources/views/test.blade.php b/resources/views/test.blade.php index ddd5fa6..88a3835 100644 --- a/resources/views/test.blade.php +++ b/resources/views/test.blade.php @@ -16,9 +16,7 @@ Test Page @php - dump($totalFees); - dump($lines); - + dump(Audition::open()->get()); @endphp diff --git a/tests/Feature/Models/AuditionTest.php b/tests/Feature/Models/AuditionTest.php new file mode 100644 index 0000000..901cd48 --- /dev/null +++ b/tests/Feature/Models/AuditionTest.php @@ -0,0 +1,17 @@ +create(); + $closedAudition = Audition::factory()->closed()->create(); + + // Act & Assert + expect(Audition::open()->get()) + ->toHaveCount(1) + ->first()->id->toEqual($openAudition->id); +});