diff --git a/app/Actions/YearEndProcedures/RecordHistoricalSeats.php b/app/Actions/YearEndProcedures/RecordHistoricalSeats.php index 08701f1..6a34155 100644 --- a/app/Actions/YearEndProcedures/RecordHistoricalSeats.php +++ b/app/Actions/YearEndProcedures/RecordHistoricalSeats.php @@ -9,10 +9,6 @@ use Carbon\Carbon; class RecordHistoricalSeats { - public function __construct() - { - } - public function __invoke(): void { $this->saveSeats(); diff --git a/tests/Feature/app/Actions/YearEndProcedures/RecordHistoricalSeatsTest.php b/tests/Feature/app/Actions/YearEndProcedures/RecordHistoricalSeatsTest.php new file mode 100644 index 0000000..3623207 --- /dev/null +++ b/tests/Feature/app/Actions/YearEndProcedures/RecordHistoricalSeatsTest.php @@ -0,0 +1,55 @@ +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');