57 lines
1.6 KiB
PHP
57 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\User;
|
|
use Domain\Enums\UserRole;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
describe('Bo\DashboardController', function (): void {
|
|
beforeEach(function (): void {
|
|
/** @var \Tests\TestCase $this */
|
|
// GIVEN
|
|
$user = User::factory()->create(['role' => UserRole::Admin]);
|
|
$this->actingAs($user, 'backend');
|
|
});
|
|
|
|
it('renders dashboard for authenticated admin', function (): void {
|
|
/** @var \Tests\TestCase $this */
|
|
// WHEN
|
|
$response = $this->get('/bo');
|
|
|
|
// THEN
|
|
expect($response->status())->toBe(200);
|
|
$response->assertViewIs('bo.dashboard');
|
|
$response->assertViewHasAll([
|
|
'employeeCount',
|
|
'customersLinkedToEmployeeCount',
|
|
'adhesion',
|
|
'prevDates',
|
|
'statsShop',
|
|
'statsCustomer',
|
|
]);
|
|
});
|
|
|
|
it('renders dashboard with date range filter', function (): void {
|
|
/** @var \Tests\TestCase $this */
|
|
// WHEN
|
|
$response = $this->get('/bo?start=2026-01-01&end=2026-01-31');
|
|
|
|
// THEN
|
|
expect($response->status())->toBe(200);
|
|
$response->assertViewIs('bo.dashboard');
|
|
$response->assertViewHas('prevDates', fn ($prevDates) => $prevDates !== null);
|
|
});
|
|
|
|
it('redirects unauthenticated users to login', function (): void {
|
|
/** @var \Tests\TestCase $this */
|
|
// GIVEN
|
|
Auth::guard('backend')->logout();
|
|
|
|
// WHEN
|
|
$response = $this->get('/bo');
|
|
|
|
// THEN
|
|
$response->assertRedirect('/bo/login');
|
|
});
|
|
});
|