auditionadmin/tests-old/Feature/Actions/RecordHistoricalSeatsTest.php

57 lines
1.7 KiB
PHP

<?php
use App\Actions\YearEndProcedures\RecordHistoricalSeats;
use App\Exceptions\AuditionAdminException;
use App\Models\Ensemble;
use App\Models\Entry;
use App\Models\HistoricalSeat;
use App\Models\Seat;
use App\Models\Student;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
it('only executes for an admin user', function () {
$action = new RecordHistoricalSeats();
expect(fn () => $action())->toThrow(
AuditionAdminException::class,
'Only administrators may perform this action'
);
actAsNormal();
expect(fn () => $action())->toThrow(
AuditionAdminException::class,
'Only administrators may perform this action'
);
actAsAdmin();
expect($action->saveSeats())->toBeTrue();
});
it('saves a seated student to the historical table', function () {
actAsAdmin();
$entry = Entry::factory()->create();
Entry::factory(5)->create();
$action = new RecordHistoricalSeats();
$ensemble = Ensemble::create([
'event_id' => $entry->audition->event_id,
'name' => 'Test Ensemble',
'code' => 'te',
'rank' => 1,
]);
$seat = Seat::create([
'ensemble_id' => $ensemble->id,
'audition_id' => $entry->audition_id,
'seat' => '1',
'entry_id' => $entry->id,
]);
$action->saveSeats();
$historical_seats = HistoricalSeat::all();
$test_seat = $historical_seats->first();
expect($test_seat->student_id)->toBe($entry->student_id)
->and($historical_seats)->toHaveCount(1)
->and($test_seat->seat_description)->toBe($ensemble->name.' - '.$entry->audition->name.' - '.$seat->seat)
->and(Student::count())->toBe(6);
});