<?php

namespace Tests\Feature;

use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class AdminDashboardMetricsTest extends TestCase
{
    use RefreshDatabase;

    public function test_guest_cannot_view_admin_dashboard(): void
    {
        $this->get(route('admin.home'))->assertRedirect(route('login'));
    }

    public function test_non_admin_cannot_view_admin_dashboard(): void
    {
        $user = User::factory()->create(['is_admin' => false]);

        $this->actingAs($user)->get(route('admin.home'))->assertForbidden();
    }

    public function test_admin_views_metrics_dashboard(): void
    {
        $admin = User::factory()->admin()->create();

        $response = $this->actingAs($admin)->get(route('admin.home'));

        $response->assertOk();
        $response->assertInertia(fn ($page) => $page
            ->component('admin/dashboard')
            ->has('metrics', fn ($metrics) => $metrics
                ->where('investors_registered', 0)
                ->where('withdrawals_pending_approval', 0)
                ->etc()));
    }
}
