Write tests - Write tests for what was done to this point that will be kept #11
|
|
@ -20,7 +20,7 @@ class CheckIfAdmin
|
|||
return $next($request);
|
||||
}
|
||||
|
||||
return redirect(route('home'))->with('error', 'You do not have admin access.');
|
||||
return redirect(route('dashboard'))->with('error', 'You do not have admin access.');
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use App\Http\Middleware\CheckIfAdmin;
|
|||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::middleware(['auth', 'verified', CheckIfAdmin::class])->prefix('admin/')->group(function () {
|
||||
Route::view('/', 'admin.dashboard');
|
||||
Route::view('/', 'admin.dashboard')->name('admin.dashboard');
|
||||
|
||||
Route::post('/auditions/roomUpdate', [\App\Http\Controllers\Admin\AuditionController::class, 'roomUpdate']); // Endpoint for JS assigning auditions to rooms
|
||||
Route::post('/scoring/assign_guide_to_audition', [\App\Http\Controllers\Admin\AuditionController::class, 'scoringGuideUpdate']); // Endpoint for JS assigning scoring guides to auditions
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Room;
|
||||
use App\Models\User;
|
||||
use App\Settings;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use function Pest\Laravel\actingAs;
|
||||
use function Pest\Laravel\get;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
it('only shows the judging option when a user is assigned to judge and judging is enabled', function () {
|
||||
// Arrange
|
||||
$room = Room::factory()->create();
|
||||
$noJudgeUser = User::factory()->create();
|
||||
$judgeUser = User::factory()->create();
|
||||
$adminNoJudgeUser = User::factory()->admin()->create();
|
||||
$room->judges()->attach($judgeUser);
|
||||
|
||||
Settings::set('judging_enabled', false);
|
||||
actingAs($noJudgeUser);
|
||||
get(route('dashboard'))->assertDontSee('Judging');
|
||||
actingAs($judgeUser);
|
||||
get(route('dashboard'))->assertDontSee('Judging');
|
||||
actingAs($adminNoJudgeUser);
|
||||
get(route('dashboard'))->assertDontSee('Judging');
|
||||
|
||||
Settings::set('judging_enabled', true);
|
||||
actingAs($noJudgeUser);
|
||||
get(route('dashboard'))->assertDontSee('Judging');
|
||||
actingAs($judgeUser);
|
||||
get(route('dashboard'))->assertSee('Judging');
|
||||
actingAs($adminNoJudgeUser);
|
||||
get(route('dashboard'))->assertDontSee('Judging');
|
||||
});
|
||||
|
||||
it('only shows Administration and Setup menus when the user is an administrator', function () {
|
||||
// Arrange
|
||||
$adminUser = User::factory()->admin()->create();
|
||||
$nonAdminUser = User::factory()->create();
|
||||
|
||||
actingAs($adminUser);
|
||||
get(route('dashboard'))->assertSee('Administration')->assertSee('Setup');
|
||||
actingAs($nonAdminUser);
|
||||
get(route('dashboard'))->assertDontSee('Administration')->assertDontSee('Setup');
|
||||
});
|
||||
|
||||
it('only shows the Tabulation dropdown to tabulators and administrators', function () {
|
||||
// Arrange
|
||||
$adminUser = User::factory()->admin()->create();
|
||||
$tabUser = User::factory()->tab()->create();
|
||||
$normalUser = User::factory()->create();
|
||||
// Act & Assert
|
||||
actingAs($adminUser);
|
||||
get(route('dashboard'))->assertSee('Tabulation');
|
||||
actingAs($tabUser);
|
||||
get(route('dashboard'))->assertSee('Tabulation');
|
||||
actingAs($normalUser);
|
||||
get(route('dashboard'))->assertDontSee('Tabulation');
|
||||
|
||||
});
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use function Pest\Laravel\actingAs;
|
||||
use function Pest\Laravel\get;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
it('only shows for an admin user', function () {
|
||||
// Arrange
|
||||
$adminUser = User::factory()->admin()->create();
|
||||
$nonAdminUser = User::factory()->create();
|
||||
|
||||
// Act & Assert
|
||||
get(route('dashboard'))->assertRedirect(route('home'));
|
||||
actingAs($adminUser);
|
||||
get(route('admin.dashboard'))->assertOk();
|
||||
actingAs($nonAdminUser);
|
||||
get(route('admin.dashboard'))->assertRedirect(route('dashboard'));
|
||||
});
|
||||
Loading…
Reference in New Issue