106 lines
4.4 KiB
PHP
106 lines
4.4 KiB
PHP
<?php
|
|
|
|
use App\Models\Audition;
|
|
use App\Models\Entry;
|
|
use App\Models\Room;
|
|
use App\Models\ScoringGuide;
|
|
use App\Models\SubscoreDefinition;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Artisan;
|
|
use Sinnbeck\DomAssertions\Asserts\AssertForm;
|
|
|
|
use function Pest\Laravel\get;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('only allows an admin or tab user to confirm a no-show', function () {
|
|
$entry = Entry::factory()->create();
|
|
get(route('entry-flags.confirmNoShow', ['entry_id' => $entry->id]))
|
|
->assertRedirect(route('home'));
|
|
actAsNormal();
|
|
get(route('entry-flags.confirmNoShow', ['entry_id' => $entry->id]))
|
|
->assertRedirect(route('dashboard'))
|
|
->assertSessionHas('error', 'You are not authorized to perform this action');
|
|
actAsTab();
|
|
get(route('entry-flags.confirmNoShow', ['entry_id' => $entry->id]))
|
|
->assertOk();
|
|
actAsAdmin();
|
|
get(route('entry-flags.confirmNoShow', ['entry_id' => $entry->id]))
|
|
->assertOk();
|
|
});
|
|
it('will not work with an entry if it is in a published audition', function () {
|
|
$entry1 = Entry::factory()->create();
|
|
$entry2 = Entry::factory()->create();
|
|
$entry1->audition->addFlag('seats_published');
|
|
$entry2->audition->addFlag('advancement_published');
|
|
actAsTab();
|
|
get(route('entry-flags.confirmNoShow', ['entry_id' => $entry1->id]))
|
|
->assertRedirect(route('entry-flags.noShowSelect'))
|
|
->assertSessionHas('error', 'Cannot enter a no-show for an entry in an audition where seats are published');
|
|
get(route('entry-flags.confirmNoShow', ['entry_id' => $entry2->id]))
|
|
->assertRedirect(route('entry-flags.noShowSelect'))
|
|
->assertSessionHas('error', 'Cannot enter a no-show for an entry in an audition where advancement is published');
|
|
});
|
|
it('has information for the requested entry', function () {
|
|
// Arrange
|
|
$entry = Entry::factory()->create();
|
|
// Act & Assert
|
|
actAsTab();
|
|
get(route('entry-flags.confirmNoShow', ['entry_id' => $entry->id]))
|
|
->assertOk()
|
|
->assertSee($entry->student->full_name())
|
|
->assertSee($entry->audition->name)
|
|
->assertSee($entry->student->school->name)
|
|
->assertSee($entry->draw_number);
|
|
});
|
|
it('posts to entry-flags.enterNoShow and has a submit button', function () {
|
|
// Arrange
|
|
$entry = Entry::factory()->create();
|
|
// Act & Assert
|
|
actAsTab();
|
|
get(route('entry-flags.confirmNoShow', ['entry_id' => $entry->id]))
|
|
->assertOk()
|
|
->assertFormExists('#no-show-confirmation-form', function (AssertForm $form) use ($entry) {
|
|
$form->hasMethod('POST')
|
|
->hasAction(route('entry-flags.enterNoShow', ['entry' => $entry->id]))
|
|
->contains('button', ['type' => 'submit'])
|
|
->hasCSRF();
|
|
});
|
|
});
|
|
it('posts to entry-flags.undoNoShow and has a remove button if the entry is already a noshow', function () {
|
|
// Arrange
|
|
$entry = Entry::factory()->create();
|
|
$entry->addFlag('no_show');
|
|
// Act & Assert
|
|
actAsTab();
|
|
get(route('entry-flags.confirmNoShow', ['entry_id' => $entry->id]))
|
|
->assertOk()
|
|
->assertFormExists('#no-show-cancellation-form', function (AssertForm $form) use ($entry) {
|
|
$form->hasMethod('POST')
|
|
->hasAction(route('entry-flags.undoNoShow', ['entry' => $entry->id]))
|
|
->contains('button', ['type' => 'submit'])
|
|
->hasCSRF();
|
|
});
|
|
});
|
|
it('shows a box with scores if the entry is scored', function () {
|
|
// Arrange
|
|
$judges = User::factory()->count(3)->create();
|
|
$room = Room::factory()->create();
|
|
$judges->each(fn($judge) => $room->addJudge($judge->id));
|
|
$scoringGuide = ScoringGuide::factory()->create();
|
|
SubscoreDefinition::factory()->count(5)->create(['scoring_guide_id' => $scoringGuide->id]);
|
|
$audition = Audition::factory()->create(['room_id' => $room->id, 'scoring_guide_id' => $scoringGuide->id]);
|
|
$entry = Entry::factory()->create(['audition_id' => $audition->id]);
|
|
// Run the ScoreAllAuditions seeder
|
|
Artisan::call('db:seed', ['--class' => 'ScoreAllAuditions']);
|
|
// Act & Assert
|
|
actAsTab();
|
|
$response = get(route('entry-flags.confirmNoShow', ['entry_id' => $entry->id]));
|
|
$response->assertOk()
|
|
->assertSee('WARNING')
|
|
->assertSee('existing scores');
|
|
$judges->each(fn($judge) => $response->assertSee($judge->full_name()));
|
|
|
|
});
|