198 lines
8.0 KiB
PHP
198 lines
8.0 KiB
PHP
<?php
|
|
|
|
use App\Models\Entry;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
use function Pest\Laravel\actingAs;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
describe('index method', function () {
|
|
it('only allows those assigned to monitor to access this page', function () {
|
|
$user = User::factory()->create();
|
|
actingAs($user);
|
|
$response = $this->get(route('monitor.index'));
|
|
$response->assertForbidden();
|
|
});
|
|
|
|
it('presents a form to choose an entry', function () {
|
|
$user = User::factory()->create();
|
|
$user->addFlag('monitor');
|
|
actingAs($user);
|
|
$response = $this->get(route('monitor.index'));
|
|
$response->assertOk()
|
|
->assertViewIs('tabulation.choose_entry');
|
|
});
|
|
});
|
|
|
|
describe('method flagForm is a form to decide what type of flag to put on an entry', function () {
|
|
it('only allows those assigned to monitor to access this page', function () {
|
|
$user = User::factory()->create();
|
|
actingAs($user);
|
|
$response = $this->post(route('monitor.enterFlag'));
|
|
$response->assertStatus(403);
|
|
});
|
|
it('wont add flags to an entry in an audition with published seats', function () {
|
|
$user = User::factory()->create();
|
|
$user->addFlag('monitor');
|
|
$user->refresh();
|
|
actingAs($user);
|
|
$entry = Entry::factory()->create();
|
|
$entry->audition->addFlag('seats_published');
|
|
$response = $this->post(route('monitor.enterFlag'), ['entry_id' => $entry->id]);
|
|
$response->assertRedirect(route('monitor.index'))
|
|
->assertSessionHas('error');
|
|
expect($response->getSession()->get('error'))->toBe('Cannot set flags while results are published');
|
|
});
|
|
|
|
it('wont add flags to an entry in an audition with published advancement', function () {
|
|
$user = User::factory()->create();
|
|
$user->addFlag('monitor');
|
|
$user->refresh();
|
|
actingAs($user);
|
|
$entry = Entry::factory()->create();
|
|
$entry->audition->addFlag('advancement_published');
|
|
$response = $this->post(route('monitor.enterFlag'), ['entry_id' => $entry->id]);
|
|
$response->assertRedirect(route('monitor.index'))
|
|
->assertSessionHas('error');
|
|
expect($response->getSession()->get('error'))->toBe('Cannot set flags while results are published');
|
|
});
|
|
|
|
it('wont add flags to an entry in an audition with scores', function () {
|
|
$user = User::factory()->create();
|
|
$user->addFlag('monitor');
|
|
$user->refresh();
|
|
actingAs($user);
|
|
$entry = Entry::factory()->create();
|
|
DB::table('score_sheets')->insert([
|
|
'user_id' => $user->id,
|
|
'entry_id' => $entry->id,
|
|
'subscores' => json_encode([12, 3, 5]),
|
|
'seating_total' => 1,
|
|
'advancement_total' => 1,
|
|
]);
|
|
$response = $this->post(route('monitor.enterFlag'), ['entry_id' => $entry->id]);
|
|
$response->assertRedirect(route('monitor.index'))
|
|
->assertSessionHas('error');
|
|
expect($response->getSession()->get('error'))->toBe('That entry has existing scores');
|
|
});
|
|
|
|
it('displays a form to choose a flag for the entry', function () {
|
|
$user = User::factory()->create();
|
|
$user->addFlag('monitor');
|
|
$user->refresh();
|
|
actingAs($user);
|
|
$entry = Entry::factory()->create();
|
|
$response = $this->post(route('monitor.enterFlag'), ['entry_id' => $entry->id]);
|
|
$response->assertOk()
|
|
->assertViewIs('monitor_entry_flag_form');
|
|
});
|
|
});
|
|
|
|
describe('method storeFlag stores the flag and returns to the select entry form', function () {
|
|
it('only allows those assigned to monitor to access this page', function () {
|
|
$user = User::factory()->create();
|
|
$entry = Entry::factory()->create();
|
|
actingAs($user);
|
|
$response = $this->post(route('monitor.storeFlag', $entry), ['flag' => 'no_show']);
|
|
$response->assertForbidden();
|
|
});
|
|
it('wont add flags to an entry in an audition with published seats', function () {
|
|
$user = User::factory()->create();
|
|
$user->addFlag('monitor');
|
|
$user->refresh();
|
|
actingAs($user);
|
|
$entry = Entry::factory()->create();
|
|
$entry->audition->addFlag('seats_published');
|
|
$response = $this->post(route('monitor.storeFlag', $entry), ['flag' => 'no_show']);
|
|
$response->assertRedirect(route('monitor.index'))
|
|
->assertSessionHas('error');
|
|
expect($response->getSession()->get('error'))->toBe('Cannot set flags while results are published');
|
|
});
|
|
|
|
it('wont add flags to an entry in an audition with published advancement', function () {
|
|
$user = User::factory()->create();
|
|
$user->addFlag('monitor');
|
|
$user->refresh();
|
|
actingAs($user);
|
|
$entry = Entry::factory()->create();
|
|
$entry->audition->addFlag('advancement_published');
|
|
$response = $this->post(route('monitor.storeFlag', $entry), ['flag' => 'no_show']);
|
|
$response->assertRedirect(route('monitor.index'))
|
|
->assertSessionHas('error');
|
|
expect($response->getSession()->get('error'))->toBe('Cannot set flags while results are published');
|
|
});
|
|
|
|
it('wont add flags to an entry in an audition with scores', function () {
|
|
$user = User::factory()->create();
|
|
$user->addFlag('monitor');
|
|
$user->refresh();
|
|
actingAs($user);
|
|
$entry = Entry::factory()->create();
|
|
DB::table('score_sheets')->insert([
|
|
'user_id' => $user->id,
|
|
'entry_id' => $entry->id,
|
|
'subscores' => json_encode([12, 3, 5]),
|
|
'seating_total' => 1,
|
|
'advancement_total' => 1,
|
|
]);
|
|
$response = $this->post(route('monitor.storeFlag', $entry), ['flag' => 'no_show']);
|
|
$response->assertRedirect(route('monitor.index'))
|
|
->assertSessionHas('error');
|
|
expect($response->getSession()->get('error'))->toBe('That entry has existing scores');
|
|
});
|
|
|
|
it('wont add a bogus flag', function () {
|
|
$user = User::factory()->create();
|
|
$user->addFlag('monitor');
|
|
$user->refresh();
|
|
actingAs($user);
|
|
$entry = Entry::factory()->create();
|
|
$response = $this->post(route('monitor.storeFlag', $entry), ['action' => 'nonsense']);
|
|
$response->assertRedirect(route('monitor.index'))
|
|
->assertSessionHas('error');
|
|
expect($response->getSession()->get('error'))->toBe('Invalid action requested');
|
|
});
|
|
|
|
it('can add a failed-prelim tag to an entry', function () {
|
|
$user = User::factory()->create();
|
|
$user->addFlag('monitor');
|
|
$user->refresh();
|
|
actingAs($user);
|
|
$entry = Entry::factory()->create();
|
|
$response = $this->post(route('monitor.storeFlag', $entry), ['action' => 'failed-prelim']);
|
|
$response->assertRedirect(route('monitor.index'));
|
|
$entry->refresh();
|
|
expect($entry->hasFlag('failed_prelim'))->toBeTrue();
|
|
});
|
|
|
|
it('can add a no-show tag to an entry', function () {
|
|
$user = User::factory()->create();
|
|
$user->addFlag('monitor');
|
|
$user->refresh();
|
|
actingAs($user);
|
|
$entry = Entry::factory()->create();
|
|
$response = $this->post(route('monitor.storeFlag', $entry), ['action' => 'no-show']);
|
|
$response->assertRedirect(route('monitor.index'));
|
|
$entry->refresh();
|
|
expect($entry->hasFlag('no_show'))->toBeTrue();
|
|
});
|
|
|
|
it('can clear flags', function () {
|
|
$user = User::factory()->create();
|
|
$user->addFlag('monitor');
|
|
$user->refresh();
|
|
actingAs($user);
|
|
$entry = Entry::factory()->create();
|
|
$entry->addFlag('no_show');
|
|
$entry->refresh();
|
|
expect($entry->hasFlag('no_show'))->toBeTrue();
|
|
$response = $this->post(route('monitor.storeFlag', $entry), ['action' => 'clear']);
|
|
$response->assertRedirect(route('monitor.index'));
|
|
$entry->refresh();
|
|
expect($entry->hasFlag('no_show'))->toBeFalse();
|
|
});
|
|
|
|
});
|