CluPilotCloud/tests/Feature/Admin/AdminConsoleTest.php

32 lines
1.3 KiB
PHP

<?php
use App\Models\Operator;
use App\Models\User;
$adminRoutes = ['admin.overview', 'admin.customers', 'admin.instances', 'admin.hosts', 'admin.provisioning', 'admin.revenue'];
it('redirects guests from the admin console to login', function (string $route) {
$this->get(route($route))->assertRedirect('/login');
})->with($adminRoutes);
it('forbids non-admin users from the admin console', function (string $route) {
$user = User::factory()->create();
$this->actingAs($user)->get(route($route))->assertForbidden();
})->with($adminRoutes);
it('renders the admin console for admins', function (string $route) {
$admin = Operator::factory()->role('Owner')->create();
// Asserted on the console badge and the sign-out control rather than on the
// wordmark: the wordmark is split across an element so its second half can
// carry the accent, so "CluPilot" is not a contiguous string in the markup.
// These two say what the assertion actually meant — the console shell, with
// its navigation, rendered for this route.
$this->actingAs($admin, 'operator')->get(route($route))
->assertOk()
->assertSee(__('admin.badge'))
->assertSee(__('admin.nav.overview'))
->assertSee(__('dashboard.logout'));
})->with($adminRoutes);