Create tests for app/actions/YearEndProcedures/RecordHistoricalSeats

This commit is contained in:
Matt Young 2025-07-02 22:40:18 -05:00
parent 1a3d88bfa8
commit bc12c90049
2 changed files with 55 additions and 4 deletions

View File

@ -9,10 +9,6 @@ use Carbon\Carbon;
class RecordHistoricalSeats
{
public function __construct()
{
}
public function __invoke(): void
{
$this->saveSeats();

View File

@ -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');