diff --git a/phpunit.xml b/phpunit.xml index c1c967f..4b2df2d 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -18,6 +18,7 @@ + diff --git a/tests/Feature/app/Http/Controllers/MonitorControllerTest.php b/tests/Feature/app/Http/Controllers/MonitorControllerTest.php index 930401d..332935c 100644 --- a/tests/Feature/app/Http/Controllers/MonitorControllerTest.php +++ b/tests/Feature/app/Http/Controllers/MonitorControllerTest.php @@ -1,6 +1,5 @@ get(route('monitor.index')); $response->assertForbidden(); }); + it('needs additional tests written', function () { + // TODO: Write tests for new monitor pabe - 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(); - }); - -});