99 lines
2.9 KiB
PHP
99 lines
2.9 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;
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| Analysis Module Tests
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
|
|
describe('Analysis Module - Authorization', function () {
|
|
it('redirects to login when accessing analysis unauthenticated', function () {
|
|
get(route('analysis'))
|
|
->assertRedirect(route('login'));
|
|
});
|
|
|
|
it('returns 403 when user has no permission to view analysis', function () {
|
|
actingAs(createUnauthorizedUser())
|
|
->get(route('analysis'))
|
|
->assertStatus(403);
|
|
});
|
|
});
|
|
|
|
describe('Analysis Module - Authorized Actions', function () {
|
|
beforeEach(function () {
|
|
$user = createAuthorizedUser([
|
|
'View:Analysis',
|
|
]);
|
|
actingAs($user);
|
|
});
|
|
|
|
it('can access analysis page and view statistics', function () {
|
|
// Create dummy data
|
|
Order::factory()->count(2)->create([
|
|
'created_at' => now(),
|
|
'total' => 150000,
|
|
'cogs' => 75000,
|
|
]);
|
|
|
|
Expense::factory()->create([
|
|
'created_at' => now(),
|
|
'amount' => 10000,
|
|
]);
|
|
|
|
Purchase::factory()->create([
|
|
'created_at' => now(),
|
|
'total' => 50000,
|
|
]);
|
|
|
|
get(route('analysis'))
|
|
->assertOk()
|
|
->assertInertia(fn ($page) => $page
|
|
->component('analysis')
|
|
->has('stats')
|
|
->has('salesByMonth')
|
|
->has('revenueVsProfit')
|
|
->has('transactionVolume')
|
|
->has('salesByHour')
|
|
->has('paymentMethods')
|
|
->has('orderStatuses')
|
|
->has('orderChannels')
|
|
->has('topProducts')
|
|
->has('topCustomers')
|
|
->has('topCategories')
|
|
);
|
|
});
|
|
|
|
it('can filter analysis by period', function () {
|
|
get(route('analysis', ['period' => 'month']))
|
|
->assertOk()
|
|
->assertInertia(fn ($page) => $page
|
|
->component('analysis')
|
|
->has('filters', fn ($f) => $f
|
|
->where('period', 'month')
|
|
->where('start_date', null)
|
|
->where('end_date', null)
|
|
)
|
|
);
|
|
});
|
|
|
|
it('can filter analysis by date range', function () {
|
|
get(route('analysis', ['start_date' => '2026-01-01', 'end_date' => '2026-01-31']))
|
|
->assertOk()
|
|
->assertInertia(fn ($page) => $page
|
|
->component('analysis')
|
|
->has('filters', fn ($f) => $f
|
|
->where('period', 'all')
|
|
->where('start_date', '2026-01-01')
|
|
->where('end_date', '2026-01-31')
|
|
)
|
|
);
|
|
});
|
|
});
|