Add open scope to auditoins
This commit is contained in:
parent
97ec6ca75b
commit
d5b5b2b84a
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
@ -24,7 +26,6 @@ class Audition extends Model
|
||||||
|
|
||||||
protected $scored_entries_count; //Set by TabulationService
|
protected $scored_entries_count; //Set by TabulationService
|
||||||
|
|
||||||
|
|
||||||
public static function deadlineNotPast()
|
public static function deadlineNotPast()
|
||||||
{
|
{
|
||||||
return Audition::where('entry_deadline', '>=', now())->get();
|
return Audition::where('entry_deadline', '>=', now())->get();
|
||||||
|
|
@ -185,4 +186,9 @@ class Audition extends Model
|
||||||
// remove related auditionFlag where flag_name = $flag
|
// remove related auditionFlag where flag_name = $flag
|
||||||
$this->flags()->where('flag_name', $flag)->delete();
|
$this->flags()->where('flag_name', $flag)->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scopeOpen(Builder $query): void
|
||||||
|
{
|
||||||
|
$query->where('entry_deadline', '>=', Carbon::now());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace Database\Factories;
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Models\Event;
|
||||||
|
use Carbon\Carbon;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -16,8 +18,44 @@ class AuditionFactory extends Factory
|
||||||
*/
|
*/
|
||||||
public function definition(): array
|
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 [
|
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()]
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,9 @@ class EventFactory extends Factory
|
||||||
public function definition(): array
|
public function definition(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'name' => 'Concert Band Auditions'
|
'name' => $this->faker->randomElement([
|
||||||
|
'Concert Auditions', 'Jazz Auditions ',
|
||||||
|
]).$this->faker->randomNumber(1),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,7 @@
|
||||||
<x-layout.app>
|
<x-layout.app>
|
||||||
<x-slot:page_title>Test Page</x-slot:page_title>
|
<x-slot:page_title>Test Page</x-slot:page_title>
|
||||||
@php
|
@php
|
||||||
dump($totalFees);
|
dump(Audition::open()->get());
|
||||||
dump($lines);
|
|
||||||
|
|
||||||
@endphp
|
@endphp
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Audition;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
|
||||||
|
uses(RefreshDatabase::class);
|
||||||
|
|
||||||
|
test('only returns open auditions for open scope', function () {
|
||||||
|
// Arrange
|
||||||
|
$openAudition = Audition::factory()->create();
|
||||||
|
$closedAudition = Audition::factory()->closed()->create();
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
expect(Audition::open()->get())
|
||||||
|
->toHaveCount(1)
|
||||||
|
->first()->id->toEqual($openAudition->id);
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue