Create tests for app/actions/YearEndProcedures/RecordHistoricalSeats
This commit is contained in:
parent
1a3d88bfa8
commit
bc12c90049
|
|
@ -9,10 +9,6 @@ use Carbon\Carbon;
|
||||||
|
|
||||||
class RecordHistoricalSeats
|
class RecordHistoricalSeats
|
||||||
{
|
{
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public function __invoke(): void
|
public function __invoke(): void
|
||||||
{
|
{
|
||||||
$this->saveSeats();
|
$this->saveSeats();
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,55 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Actions\YearEndProcedures\RecordHistoricalSeats;
|
||||||
|
use App\Exceptions\AuditionAdminException;
|
||||||
|
use App\Models\Audition;
|
||||||
|
use App\Models\Ensemble;
|
||||||
|
use App\Models\Entry;
|
||||||
|
use App\Models\Event;
|
||||||
|
use App\Models\HistoricalSeat;
|
||||||
|
use App\Models\Seat;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
|
|
||||||
|
uses(RefreshDatabase::class);
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
$this->event = Event::factory()->create();
|
||||||
|
$this->auditions = Audition::factory()->count(5)->create([
|
||||||
|
'event_id' => $this->event->id, 'minimum_grade' => 1,
|
||||||
|
'maximum_grade' => 14,
|
||||||
|
]);
|
||||||
|
$this->ensemble = Ensemble::factory()->create(['event_id' => $this->event->id]);
|
||||||
|
foreach ($this->auditions as $audition) {
|
||||||
|
Entry::factory()->count(5)->create(['audition_id' => $audition->id]);
|
||||||
|
$n = 1;
|
||||||
|
foreach ($audition->entries as $entry) {
|
||||||
|
Seat::create([
|
||||||
|
'ensemble_id' => $this->ensemble->id,
|
||||||
|
'audition_id' => $audition->id,
|
||||||
|
'seat' => $n,
|
||||||
|
'entry_id' => $entry->id,
|
||||||
|
]);
|
||||||
|
$n++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('saves historical seats for current seats', function () {
|
||||||
|
actAsAdmin();
|
||||||
|
$historian = app(RecordHistoricalSeats::class);
|
||||||
|
$historian();
|
||||||
|
foreach (Seat::all() as $seat) {
|
||||||
|
$seatString = $seat->ensemble->name.' - '.$seat->audition->name.' - '.$seat->seat;
|
||||||
|
expect(HistoricalSeat::where('student_id', $seat->entry->student_id)
|
||||||
|
->where('year', Carbon::now()->year)
|
||||||
|
->where('seat_description', $seatString)
|
||||||
|
->exists())->toBeTrue();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('will not run for a non-admin user', function () {
|
||||||
|
actAsNormal();
|
||||||
|
$historian = app(RecordHistoricalSeats::class);
|
||||||
|
$historian();
|
||||||
|
})->throws(AuditionAdminException::class, 'Only administrators may perform this action');
|
||||||
Loading…
Reference in New Issue