<?php

namespace Tests\Feature;

use App\Models\Post;
use App\Models\User;
use Database\Seeders\RolesAndAdminSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class AdminSmokeTest extends TestCase
{
    use RefreshDatabase;

    private function actingAsAdmin(): User
    {
        $this->seed(RolesAndAdminSeeder::class);
        $admin = User::where('email', 'admin@moneywise.co.ke')->firstOrFail();
        $this->actingAs($admin);

        return $admin;
    }

    public function test_admin_dashboard_loads(): void
    {
        $this->actingAsAdmin();
        $this->get('/admin')->assertSuccessful();
    }

    public function test_post_create_and_edit_render(): void
    {
        $this->actingAsAdmin();
        $this->get('/admin/posts/create')->assertSuccessful();

        $post = Post::create(['title' => 'Smoke', 'slug' => 'smoke', 'body' => '<p>hi</p>', 'published_at' => now()]);
        $this->get("/admin/posts/{$post->getRouteKey()}/edit")->assertSuccessful();
    }

    public function test_guide_create_renders(): void
    {
        $this->actingAsAdmin();
        $this->get('/admin/guides/create')->assertSuccessful();
    }
}
