audition = Audition::factory()->create(['minimum_grade' => 1, 'maximum_grade' => 14]); $this->windEnsemble = Ensemble::create([ 'event_id' => $this->audition->event_id, 'name' => 'Wind Ensemble', 'code' => 'we', 'rank' => 1, ]); $this->alternates = Ensemble::create([ 'event_id' => $this->audition->event_id, 'name' => 'Alternates', 'code' => 'alt', 'rank' => 2, ]); $this->entries = Entry::factory()->count(10)->create(['audition_id' => $this->audition->id]); $this->seatingArray = [ 1 => [ 'ensemble_id' => $this->windEnsemble->id, 'audition_id' => $this->audition->id, 'entry_id' => $this->entries[0]->id, 'seat' => 1, ], 2 => [ 'ensemble_id' => $this->windEnsemble->id, 'audition_id' => $this->audition->id, 'entry_id' => $this->entries[1]->id, 'seat' => 2, ], 3 => [ 'ensemble_id' => $this->windEnsemble->id, 'audition_id' => $this->audition->id, 'entry_id' => $this->entries[2]->id, 'seat' => 3, ], 4 => [ 'ensemble_id' => $this->alternates->id, 'audition_id' => $this->audition->id, 'entry_id' => $this->entries[3]->id, 'seat' => 1, ], 5 => [ 'ensemble_id' => $this->alternates->id, 'audition_id' => $this->audition->id, 'entry_id' => $this->entries[4]->id, 'seat' => 2, ], ]; $this->publisher = app(PublishSeats::class); }); it('seats an audition', function () { ($this->publisher)($this->audition, $this->seatingArray); expect($this->audition->hasFlag('seats_published'))->toBeTrue() ->and(Seat::where('ensemble_id', $this->windEnsemble->id)->where('seat', 1) ->first()->entry_id)->toEqual($this->entries[0]->id) ->and(Seat::where('ensemble_id', $this->windEnsemble->id)->where('seat', 2) ->first()->entry_id)->toEqual($this->entries[1]->id) ->and(Seat::where('ensemble_id', $this->windEnsemble->id)->where('seat', 3) ->first()->entry_id)->toEqual($this->entries[2]->id) ->and(Seat::where('ensemble_id', $this->alternates->id)->where('seat', 1) ->first()->entry_id)->toEqual($this->entries[3]->id) ->and(Seat::where('ensemble_id', $this->alternates->id)->where('seat', 2) ->first()->entry_id)->toEqual($this->entries[4]->id); }); it('clears results and set list cache', function () { $this->get(route('results')); expect(Cache::has('publicResultsPage'))->toBeTrue() ->and(Cache::has('resultsSeatList'))->toBeTrue(); ($this->publisher)($this->audition, $this->seatingArray); expect(Cache::has('publicResultsPage'))->toBeFalse() ->and(Cache::has('resultsSeatList'))->toBeFalse(); }); it('throws and exception if no seats are provided', function () { ($this->publisher)($this->audition, []); })->throws(AuditionAdminException::class, 'Cannot publish an audition with no seats.');