UpdateEntry action fully tested
This commit is contained in:
parent
30862271f2
commit
bed4e0671e
|
|
@ -7,6 +7,7 @@ use App\Actions\Entries\UpdateEntry;
|
||||||
use App\Exceptions\AuditionAdminException;
|
use App\Exceptions\AuditionAdminException;
|
||||||
use App\Models\Audition;
|
use App\Models\Audition;
|
||||||
use App\Models\AuditionFlag;
|
use App\Models\AuditionFlag;
|
||||||
|
use App\Models\AuditLogEntry;
|
||||||
use App\Models\Entry;
|
use App\Models\Entry;
|
||||||
use App\Models\Room;
|
use App\Models\Room;
|
||||||
use App\Models\ScoringGuide;
|
use App\Models\ScoringGuide;
|
||||||
|
|
@ -69,19 +70,23 @@ it('will not move to an audition for which the student is too young', function (
|
||||||
$newAudition = Audition::factory()->create([
|
$newAudition = Audition::factory()->create([
|
||||||
'event_id' => $this->entry->audition->event_id,
|
'event_id' => $this->entry->audition->event_id,
|
||||||
'minimum_grade' => 10,
|
'minimum_grade' => 10,
|
||||||
|
'maximum_grade' => 11,
|
||||||
]);
|
]);
|
||||||
$this->entry->student->update(['grade' => 9]);
|
$this->entry->student->update(['grade' => 9]);
|
||||||
|
dump('student grade: '.$this->entry->student->grade);
|
||||||
|
dump('new audition minimum: '.$newAudition->minimum_grade);
|
||||||
($this->entryScribe)($this->entry, ['audition_id' => $newAudition->id]);
|
($this->entryScribe)($this->entry, ['audition_id' => $newAudition->id]);
|
||||||
})->throws(AuditionAdminException::class, 'The student is too young to enter that audition')->skip('test needs work');
|
})->throws(AuditionAdminException::class, 'The student is too young to enter that audition');
|
||||||
|
|
||||||
it('will not move to an audition for which the student is too old', function () {
|
it('will not move to an audition for which the student is too old', function () {
|
||||||
$newAudition = Audition::factory()->create([
|
$newAudition = Audition::factory()->create([
|
||||||
'event_id' => $this->entry->audition->event_id,
|
'event_id' => $this->entry->audition->event_id,
|
||||||
'maximum_grade' => 8,
|
'maximum_grade' => 8,
|
||||||
|
'minimum_grade' => 7,
|
||||||
]);
|
]);
|
||||||
$this->entry->student->update(['grade' => 9]);
|
$this->entry->student->update(['grade' => 9]);
|
||||||
($this->entryScribe)($this->entry, ['audition_id' => $newAudition->id]);
|
($this->entryScribe)($this->entry, ['audition_id' => $newAudition->id]);
|
||||||
})->throws(AuditionAdminException::class, 'The student is too old to enter that audition')->skip('test needs work');
|
})->throws(AuditionAdminException::class, 'The student is too old to enter that audition');
|
||||||
|
|
||||||
it('will not change auditions for an entry with scores', function () {
|
it('will not change auditions for an entry with scores', function () {
|
||||||
$scoreFaker = app(FakeScoresForEntry::class);
|
$scoreFaker = app(FakeScoresForEntry::class);
|
||||||
|
|
@ -194,3 +199,37 @@ it('cannot add forSeating if seating is published', function () {
|
||||||
($this->entryScribe)($this->entry, ['for_seating' => true]);
|
($this->entryScribe)($this->entry, ['for_seating' => true]);
|
||||||
})->throws(AuditionAdminException::class,
|
})->throws(AuditionAdminException::class,
|
||||||
'Cannot add seating to an entry in an audition where seats are published');
|
'Cannot add seating to an entry in an audition where seats are published');
|
||||||
|
|
||||||
|
it('logs changes', function () {
|
||||||
|
actAsAdmin();
|
||||||
|
$originalEntry = Entry::find($this->entry->id);
|
||||||
|
$newAudition = Audition::factory()->create(['minimum_grade' => 9, 'maximum_grade' => 10, 'name' => 'Alphorn']);
|
||||||
|
($this->entryScribe)($this->entry, ['audition' => $newAudition]);
|
||||||
|
$logEntry = AuditLogEntry::latest()->first();
|
||||||
|
expect($logEntry->affected['auditions'])->toEqual([$originalEntry->audition_id, $newAudition->id])
|
||||||
|
->and($logEntry->affected['entries'])->toEqual([$this->entry->id])
|
||||||
|
->and($logEntry->affected['students'])->toEqual([$this->entry->student_id])
|
||||||
|
->and($logEntry->affected['schools'])->toEqual([$this->entry->student->school_id])
|
||||||
|
->and($logEntry->message)->toEqual('Changed entry '.$this->entry->id.' from '.$originalEntry->audition->name.' to '.$newAudition->name.'<br>');
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('will not change to a non-existent audition', function () {
|
||||||
|
$newAudition = Audition::factory()->make();
|
||||||
|
($this->entryScribe)($this->entry, ['audition' => $newAudition]);
|
||||||
|
})->throws(AuditionAdminException::class, 'Invalid audition provided');
|
||||||
|
|
||||||
|
it('wont change if we give it the same audition', function () {
|
||||||
|
($this->entryScribe)($this->entry, ['audition' => $this->entry->audition]);
|
||||||
|
expect($this->entry->audition_id)->toBe($this->entry->audition->id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('wont change seating if we give the same value', function () {
|
||||||
|
($this->entryScribe)($this->entry, ['for_seating' => 1]);
|
||||||
|
expect($this->entry->for_seating)->toBe($this->entry->for_seating);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('wont change advancement if we give the same value', function () {
|
||||||
|
($this->entryScribe)($this->entry, ['for_advancement' => 1]);
|
||||||
|
expect($this->entry->for_advancement)->toBe($this->entry->for_advancement);
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue