112 lines
3.7 KiB
PHP
112 lines
3.7 KiB
PHP
<?php
|
|
|
|
use App\Models\Audition;
|
|
use App\Models\Entry;
|
|
use App\Models\Event;
|
|
use App\Models\Room;
|
|
use App\Models\ScoringGuide;
|
|
use App\Models\SubscoreDefinition;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Sinnbeck\DomAssertions\Asserts\AssertForm;
|
|
|
|
use function Pest\Laravel\get;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
function testData(): array
|
|
{
|
|
$data['judge'] = User::factory()->create();
|
|
$data['room'] = Room::factory()->create();
|
|
$data['room']->addJudge($data['judge']);
|
|
$data['event'] = Event::factory()->create();
|
|
$data['scoringGuide'] = ScoringGuide::factory()->create();
|
|
$data['subscores'] = SubscoreDefinition::factory()->count(3)->create([
|
|
'scoring_guide_id' => $data['scoringGuide']->id,
|
|
]);
|
|
$data['audition'] = Audition::factory()->create([
|
|
'room_id' => $data['room']->id,
|
|
'event_id' => $data['event']->id,
|
|
'scoring_guide_id' => $data['scoringGuide']->id,
|
|
]);
|
|
$data['entry'] = Entry::factory()->create([
|
|
'audition_id' => $data['audition']->id,
|
|
]);
|
|
|
|
return $data;
|
|
}
|
|
|
|
/** @noinspection PhpMissingReturnTypeInspection */
|
|
function validRequest(array $data = [])
|
|
{
|
|
if (! $data) {
|
|
$data = testData();
|
|
}
|
|
actAsTab();
|
|
|
|
return get(route('scores.entryScoreSheet', ['entry_id' => $data['entry']->id]));
|
|
}
|
|
|
|
it('does not allow guests or normal users to access the admin score form', function () {
|
|
get(route('scores.entryScoreSheet'))->assertRedirect(route('home'));
|
|
actAsNormal();
|
|
get(route('scores.entryScoreSheet'))->assertRedirect(route('dashboard'))->assertSessionHas('error',
|
|
'You are not authorized to perform this action');
|
|
});
|
|
it('grants an admin or tab user access', function () {
|
|
// Arrange
|
|
$response = validRequest();
|
|
// Act & Assert
|
|
$response->assertOk();
|
|
});
|
|
it('has a form with field for each subscore for each judge', function () {
|
|
// Arrange
|
|
$data = testData();
|
|
$response = validRequest($data);
|
|
// Act & Assert
|
|
$response->assertOk();
|
|
$fieldsToCheck = [];
|
|
foreach ($data['subscores'] as $subscore) {
|
|
$fieldsToCheck[] = 'j'.$data['judge']->id.'ss'.$subscore->id;
|
|
}
|
|
/** @noinspection PhpExpressionResultUnusedInspection */
|
|
$response->assertFormExists('#scoreForm', function (AssertForm $form) use ($fieldsToCheck) {
|
|
$form->hasCSRF();
|
|
$form->hasMethod('POST');
|
|
$form->hasAction(route('scores.saveEntryScoreSheet', ['entry' => 1]));
|
|
foreach ($fieldsToCheck as $field) {
|
|
$form->contains('#'.$field);
|
|
}
|
|
});
|
|
});
|
|
it('will not accept scores for an entry in a an audition with published seats', function () {
|
|
// Arrange
|
|
$data = testData();
|
|
$data['audition']->addFlag('seats_published');
|
|
$response = validRequest($data);
|
|
// Act & Assert
|
|
$expectedError = 'Cannot enter scores for entry '.$data['entry']->id.'. '.$data['entry']->audition->name.' seats are published';
|
|
$response
|
|
->assertRedirect(route('scores.chooseEntry'))
|
|
->assertSessionHas('error', $expectedError);
|
|
});
|
|
it('will not accept scores for an entry in an audition with published advancement', function () {
|
|
// Arrange
|
|
$data = testData();
|
|
$data['audition']->addFlag('advancement_published');
|
|
$response = validRequest($data);
|
|
// Act & Assert
|
|
$expectedError = 'Cannot enter scores for entry '.$data['entry']->id.'. '.$data['entry']->audition->name.' advancement is published';
|
|
$response
|
|
->assertRedirect(route('scores.chooseEntry'))
|
|
->assertSessionHas('error', $expectedError);
|
|
});
|
|
it('warns if the entry is flagged as a no-show', function () {
|
|
// Arrange
|
|
$response = validRequest();
|
|
// Act & Assert
|
|
$response
|
|
->assertOk()
|
|
->assertSee('marked as a no-show');
|
|
});
|