74 lines
2.1 KiB
PHP
74 lines
2.1 KiB
PHP
<?php
|
|
|
|
use App\Models\Expense;
|
|
use App\Models\Order;
|
|
use App\Models\Purchase;
|
|
|
|
use function Pest\Laravel\actingAs;
|
|
use function Pest\Laravel\get;
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| Dashboard Module Tests
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
|
|
describe('Dashboard Module - Authorization', function () {
|
|
it('redirects to login when accessing dashboard unauthenticated', function () {
|
|
get(route('dashboard'))
|
|
->assertRedirect(route('login'));
|
|
});
|
|
|
|
it('returns 403 when user has no permission to view dashboard', function () {
|
|
actingAs(createUnauthorizedUser())
|
|
->get(route('dashboard'))
|
|
->assertStatus(403);
|
|
});
|
|
});
|
|
|
|
describe('Dashboard Module - Authorized Actions', function () {
|
|
beforeEach(function () {
|
|
$user = createAuthorizedUser([
|
|
'View:Dashboard',
|
|
]);
|
|
actingAs($user);
|
|
});
|
|
|
|
it('can access dashboard page and view statistics', function () {
|
|
// Create some dummy data to ensure queries don't fail and aggregations work
|
|
Order::factory()->count(3)->create([
|
|
'created_at' => now(),
|
|
'total' => 100000,
|
|
'cogs' => 50000,
|
|
]);
|
|
|
|
Expense::factory()->count(2)->create([
|
|
'created_at' => now(),
|
|
'amount' => 20000,
|
|
]);
|
|
|
|
Purchase::factory()->create([
|
|
'created_at' => now(),
|
|
'total' => 150000,
|
|
]);
|
|
|
|
get(route('dashboard'))
|
|
->assertOk()
|
|
->assertInertia(fn ($page) => $page
|
|
->component('dashboard')
|
|
->has('stats')
|
|
->has('stats.total_sales')
|
|
->has('stats.total_revenue')
|
|
->has('stats.total_expenses')
|
|
->has('stats.gross_profit')
|
|
->has('stats.net_profit')
|
|
->has('salesByHour')
|
|
->has('paymentMethods')
|
|
->has('orderStatuses')
|
|
->has('orderChannels')
|
|
->has('topProducts')
|
|
->has('topCustomers')
|
|
);
|
|
});
|
|
});
|