128 lines
6.1 KiB
PHP
128 lines
6.1 KiB
PHP
<?php
|
|
|
|
use App\Actions\Entries\CreateEntry;
|
|
use App\Exceptions\ManageEntryException;
|
|
use App\Models\Audition;
|
|
use App\Models\Entry;
|
|
use App\Models\Student;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\App;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
$this->createEntry = App::make(CreateEntry::class);
|
|
});
|
|
|
|
it('throws an exception if the student does not exist', function () {
|
|
$audition = Audition::factory()->create();
|
|
$student = Student::factory()->make();
|
|
$this->createEntry->__invoke($student, $audition);
|
|
})->throws(ManageEntryException::class, 'Invalid student provided');
|
|
it('throws an exception if the audition does not exist', function () {
|
|
$audition = Audition::factory()->make();
|
|
$student = Student::factory()->create();
|
|
$this->createEntry->__invoke($student, $audition);
|
|
})->throws(ManageEntryException::class, 'Invalid audition provided');
|
|
it('throws an exception if the student is already entered in the audition', function () {
|
|
// Arrange
|
|
$audition = Audition::factory()->create();
|
|
$student = Student::factory()->create();
|
|
$entry = Entry::create([
|
|
'student_id' => $student->id,
|
|
'audition_id' => $audition->id,
|
|
]);
|
|
// Act & Assert
|
|
$this->createEntry->createEntry($student, $audition);
|
|
})->throws(ManageEntryException::class, 'That student is already entered in that audition');
|
|
it('throws an exception if seats are published for the audition', function () {
|
|
// Arrange
|
|
$audition = Audition::factory()->create();
|
|
$student = Student::factory()->create();
|
|
$audition->addFlag('seats_published');
|
|
// Act & Assert
|
|
$this->createEntry->createEntry($student, $audition);
|
|
})->throws(ManageEntryException::class, 'Cannot add an entry to an audition where seats are published');
|
|
it('throws an exception if advancement is published for the audition', function () {
|
|
// Arrange
|
|
$audition = Audition::factory()->create();
|
|
$student = Student::factory()->create();
|
|
$audition->addFlag('advancement_published');
|
|
// Act & Assert
|
|
$this->createEntry->createEntry($student, $audition);
|
|
})->throws(ManageEntryException::class, 'Cannot add an entry to an audition where advancement is published');
|
|
it('throws an exception if the grade of the student exceeds the maximum grade for the audition', function () {
|
|
// Arrange
|
|
$audition = Audition::factory()->create(['minimum_grade' => 8, 'maximum_grade' => 9]);
|
|
$student = Student::factory()->create(['grade' => 11]);
|
|
// Act & Assert
|
|
$this->createEntry->createEntry($student, $audition);
|
|
})->throws(ManageEntryException::class, 'The grade of the student exceeds the maximum for that audition');
|
|
it('throws an exception if the grade of the student does not meet the minimum grade for the audition', function () {
|
|
// Arrange
|
|
$audition = Audition::factory()->create(['minimum_grade' => 8, 'maximum_grade' => 9]);
|
|
$student = Student::factory()->create(['grade' => 7]);
|
|
// Act & Assert
|
|
$this->createEntry->createEntry($student, $audition);
|
|
})->throws(ManageEntryException::class, 'The grade of the student does not meet the minimum for that audition');
|
|
it('returns an entry object', function () {
|
|
// Arrange
|
|
$audition = Audition::factory()->create(['minimum_grade' => 8, 'maximum_grade' => 9]);
|
|
$student = Student::factory()->create(['grade' => 8]);
|
|
// Act & Assert
|
|
$entry = $this->createEntry->createEntry($student, $audition);
|
|
expect($entry instanceof Entry)->toBeTrue();
|
|
});
|
|
it('creates an entry with a null draw number if the audition is not drawn', function () {
|
|
$audition = Audition::factory()->create(['minimum_grade' => 8, 'maximum_grade' => 9]);
|
|
$student = Student::factory()->create(['grade' => 8]);
|
|
// Act & Assert
|
|
$entry = $this->createEntry->createEntry($student, $audition);
|
|
expect($entry->draw_number)->toBeNull();
|
|
});
|
|
it('assigns the next highest draw_number available if the audition is drawn', function () {
|
|
$audition = Audition::factory()->create(['minimum_grade' => 8, 'maximum_grade' => 9]);
|
|
$student = Student::factory()->create(['grade' => 8]);
|
|
$audition->addFlag('drawn');
|
|
foreach (range(1, 5) as $number) {
|
|
Entry::factory()->create([
|
|
'audition_id' => $audition->id,
|
|
'draw_number' => $number,
|
|
]);
|
|
}
|
|
$entry = $this->createEntry->createEntry($student, $audition);
|
|
expect($entry->draw_number)->toBe(6);
|
|
});
|
|
it('makes the entry for both seating and advancement if nothing is specified', function () {
|
|
$audition = Audition::factory()->create(['minimum_grade' => 8, 'maximum_grade' => 9]);
|
|
$student = Student::factory()->create(['grade' => 8]);
|
|
// Act & Assert
|
|
$entry = $this->createEntry->createEntry($student, $audition);
|
|
expect($entry->for_seating)->toBeTrue()
|
|
->and($entry->for_advancement)->toBeTrue();
|
|
});
|
|
it('makes the entry for only seating if only seating is specified', function () {
|
|
$audition = Audition::factory()->create(['minimum_grade' => 8, 'maximum_grade' => 9]);
|
|
$student = Student::factory()->create(['grade' => 8]);
|
|
// Act & Assert
|
|
$entry = $this->createEntry->createEntry($student, $audition, 'seating');
|
|
expect($entry->for_seating)->toBeTrue()
|
|
->and($entry->for_advancement)->toBeFalse();
|
|
});
|
|
it('makes the entry for only advancement if only advancement is specified', function () {
|
|
$audition = Audition::factory()->create(['minimum_grade' => 8, 'maximum_grade' => 9]);
|
|
$student = Student::factory()->create(['grade' => 8]);
|
|
// Act & Assert
|
|
$entry = $this->createEntry->createEntry($student, $audition, 'advancement');
|
|
expect($entry->for_seating)->toBeFalse()
|
|
->and($entry->for_advancement)->toBeTrue();
|
|
});
|
|
it('makes the entry for both seating and advancement if both are specified', function () {
|
|
$audition = Audition::factory()->create(['minimum_grade' => 8, 'maximum_grade' => 9]);
|
|
$student = Student::factory()->create(['grade' => 8]);
|
|
// Act & Assert
|
|
$entry = $this->createEntry->createEntry($student, $audition, ['seating', 'advancement']);
|
|
expect($entry->for_seating)->toBeTrue()
|
|
->and($entry->for_advancement)->toBeTrue();
|
|
});
|