auditionadmin/tests-old/Feature/Pages/Tabulation/noShowUndoTest.php

56 lines
2.3 KiB
PHP

<?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('advancement_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();
});