Enter and store no show #13
|
|
@ -6,10 +6,8 @@ use App\Http\Controllers\Controller;
|
|||
use App\Models\Audition;
|
||||
use App\Models\School;
|
||||
use App\Models\Student;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use function abort;
|
||||
use function to_route;
|
||||
use function view;
|
||||
|
|
@ -50,7 +48,7 @@ class StudentController extends Controller
|
|||
'school_id' => ['required', 'exists:schools,id'],
|
||||
]);
|
||||
|
||||
$student = Student::create([
|
||||
Student::create([
|
||||
'first_name' => request('first_name'),
|
||||
'last_name' => request('last_name'),
|
||||
'grade' => request('grade'),
|
||||
|
|
@ -69,11 +67,12 @@ class StudentController extends Controller
|
|||
$maxGrade = Audition::max('maximum_grade');
|
||||
$schools = School::orderBy('name')->get();
|
||||
$student->loadCount('entries');
|
||||
|
||||
return view('admin.students.edit',
|
||||
['student' => $student, 'schools' => $schools, 'minGrade' => $minGrade, 'maxGrade' => $maxGrade]);
|
||||
}
|
||||
|
||||
public function update(Request $request, Student $student)
|
||||
public function update(Student $student)
|
||||
{
|
||||
if (! Auth::user()->is_admin) {
|
||||
abort(403);
|
||||
|
|
@ -105,7 +104,6 @@ class StudentController extends Controller
|
|||
|
||||
public function destroy(Student $student)
|
||||
{
|
||||
Log::debug('Deleting student '.$student->id);
|
||||
if ($student->entries()->count() > 0) {
|
||||
return to_route('admin.students.index')->with('error', 'You cannot delete a student with entries.');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,6 +86,18 @@ class EntryFlagController extends Controller
|
|||
|
||||
public function undoNoShow(Entry $entry)
|
||||
{
|
||||
//
|
||||
if ($entry->audition->hasFlag('seats_published')) {
|
||||
return to_route('entry-flags.noShowSelect')->with('error',
|
||||
'Cannot undo a no-show for an entry in an audition where seats are published');
|
||||
}
|
||||
if ($entry->audition->hasFlag('advance_published')) {
|
||||
return to_route('entry-flags.noShowSelect')->with('error',
|
||||
'Cannot undo a no-show for an entry in an audition where advancement is published');
|
||||
}
|
||||
|
||||
$entry->removeFlag('no_show');
|
||||
|
||||
return to_route('entry-flags.noShowSelect')->with('success',
|
||||
'No Show status has been removed for '.$entry->audition->name.' #'.$entry->draw_number.' (ID: '.$entry->id.').');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,12 @@
|
|||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Ensemble;
|
||||
use App\Models\Event;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Ensemble>
|
||||
* @extends Factory<Ensemble>
|
||||
*/
|
||||
class EnsembleFactory extends Factory
|
||||
{
|
||||
|
|
@ -17,8 +19,8 @@ class EnsembleFactory extends Factory
|
|||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->name,
|
||||
'event_id' => \App\Models\Event::factory(),
|
||||
'name' => $this->faker->words(4, true),
|
||||
'event_id' => Event::factory(),
|
||||
'code' => $this->faker->randomLetter().$this->faker->randomLetter,
|
||||
'rank' => $this->faker->numberBetween(1, 10),
|
||||
];
|
||||
|
|
|
|||
|
|
@ -13,12 +13,14 @@ it('only allows an admin or tab user to enter a no-show', function () {
|
|||
post(route('entry-flags.enterNoShow', $entry))
|
||||
->assertRedirect(route('home'));
|
||||
actAsAdmin();
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
post(route('entry-flags.enterNoShow', $entry))
|
||||
->assertSessionHasNoErrors()
|
||||
->assertSessionHas('success',
|
||||
'No Show has been entered for '.$entry->audition->name.' #'.$entry->draw_number.' (ID: '.$entry->id.').')
|
||||
->assertRedirect(route('entry-flags.noShowSelect'));
|
||||
actAsTab();
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
post(route('entry-flags.enterNoShow', $entry))
|
||||
->assertSessionHasNoErrors()
|
||||
->assertSessionHas('success',
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Entry;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
use function Pest\Laravel\delete;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
it('only allows an admin or tab user to undo a no-show', function () {
|
||||
$entry = Entry::factory()->create();
|
||||
$entry->addFlag('no_show');
|
||||
delete(route('entry-flags.undoNoShow', $entry))
|
||||
->assertRedirect(route('home'));
|
||||
actAsAdmin();
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
delete(route('entry-flags.undoNoShow', $entry))
|
||||
->assertSessionHasNoErrors()
|
||||
->assertSessionHas('success',
|
||||
'No Show status has been removed for '.$entry->audition->name.' #'.$entry->draw_number.' (ID: '.$entry->id.').')
|
||||
->assertRedirect(route('entry-flags.noShowSelect'));
|
||||
actAsTab();
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
delete(route('entry-flags.undoNoShow', $entry))
|
||||
->assertSessionHasNoErrors()
|
||||
->assertSessionHas('success',
|
||||
'No Show status has been removed for '.$entry->audition->name.' #'.$entry->draw_number.' (ID: '.$entry->id.').')
|
||||
->assertRedirect(route('entry-flags.noShowSelect'));
|
||||
});
|
||||
it('will not undo a no-show flag for an entry in a published audition', function () {
|
||||
$entry1 = Entry::factory()->create();
|
||||
$entry2 = Entry::factory()->create();
|
||||
$entry1->addFlag('no_show');
|
||||
$entry2->addFlag('no_show');
|
||||
$entry1->audition->addFlag('seats_published');
|
||||
$entry2->audition->addFlag('advance_published');
|
||||
actAsAdmin();
|
||||
delete(route('entry-flags.undoNoShow', $entry1))
|
||||
->assertRedirect(route('entry-flags.noShowSelect'))
|
||||
->assertSessionHas('error', 'Cannot undo a no-show for an entry in an audition where seats are published');
|
||||
delete(route('entry-flags.undoNoShow', $entry2))
|
||||
->assertRedirect(route('entry-flags.noShowSelect'))
|
||||
->assertSessionHas('error',
|
||||
'Cannot undo a no-show for an entry in an audition where advancement is published');
|
||||
});
|
||||
|
||||
it('removes a no_show flag to the entry', function () {
|
||||
// Arrange
|
||||
$entry = Entry::factory()->create();
|
||||
$entry->addFlag('no_show');
|
||||
// Act & Assert
|
||||
actAsAdmin();
|
||||
delete(route('entry-flags.undoNoShow', $entry));
|
||||
expect(Entry::find($entry->id)->hasFlag('no_show'))->toBeFalse();
|
||||
});
|
||||
Loading…
Reference in New Issue