2026-10-01 10:28:08 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
use App\Models\User;
|
2026-11-16 01:01:41 +01:00
|
|
|
use Domain\Enums\StatsShopType;
|
2026-10-01 10:28:08 +02:00
|
|
|
use Domain\Enums\UserRole;
|
2026-11-16 01:01:41 +01:00
|
|
|
use Illuminate\Support\Facades\App;
|
2026-10-02 10:59:10 +02:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2026-10-01 10:28:08 +02:00
|
|
|
|
2026-11-16 01:01:41 +01:00
|
|
|
use function Pest\Laravel\get;
|
|
|
|
|
|
2026-10-01 10:28:08 +02:00
|
|
|
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
|
2026-10-02 10:59:10 +02:00
|
|
|
Auth::guard('backend')->logout();
|
2026-10-01 10:28:08 +02:00
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$response = $this->get('/bo');
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
$response->assertRedirect('/bo/login');
|
|
|
|
|
});
|
2026-11-16 01:01:41 +01:00
|
|
|
|
|
|
|
|
it('translates shop stat enum labels in fr and en', function (): void {
|
|
|
|
|
// GIVEN
|
|
|
|
|
App::setLocale('fr');
|
|
|
|
|
$frLabel = __(StatsShopType::nbActiveClients->label());
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
App::setLocale('en');
|
|
|
|
|
$enLabel = __(StatsShopType::nbActiveClients->label());
|
|
|
|
|
$response = get('/bo?start=2026-01-01&end=2026-01-31');
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($frLabel)->toBe('Nombre de clients actifs')
|
|
|
|
|
->and($enLabel)->toBe('Number of active customers');
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertSee('Number of active customers');
|
|
|
|
|
App::setLocale('fr');
|
|
|
|
|
});
|
2026-10-01 10:28:08 +02:00
|
|
|
});
|