<?php

namespace Tests\Feature;

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

class DetailsAjaxTest extends TestCase
{
    use RefreshDatabase;

    public function test_donateur_details_ajax_returns_html()
    {
        $user = User::factory()->create(['is_admin' => true]);
        $donateur = Donateur::create([
            'nom' => 'Doe',
            'prenom' => 'John',
            'sexe' => 'M',
        ]);

        $response = $this->actingAs($user)
            ->get(route('donateurs.details_ajax', $donateur), [
                'HTTP_X-Requested-With' => 'XMLHttpRequest',
            ]);

        $response->assertStatus(200);
        $response->assertSee('Détails de '.$donateur->nom, false);
    }

    public function test_donateur_details_non_ajax_returns_404()
    {
        $user = User::factory()->create(['is_admin' => true]);
        $donateur = Donateur::create([
            'nom' => 'Doe',
            'prenom' => 'John',
            'sexe' => 'M',
        ]);

        $response = $this->actingAs($user)
            ->get(route('donateurs.details_ajax', $donateur));

        $response->assertStatus(404);
    }

    public function test_campaign_details_ajax_returns_html()
    {
        $user = User::factory()->create(['is_admin' => true]);
        $campaign = Campaign::create([
            'name' => 'Test',
            'slug' => 'test',
            'message' => 'msg',
        ]);

        $response = $this->actingAs($user)
            ->get(route('campaigns.details_ajax', $campaign), [
                'HTTP_X-Requested-With' => 'XMLHttpRequest',
            ]);

        $response->assertStatus(200);
        $response->assertSee('Détails Campagne : '.$campaign->name, false);
    }

    public function test_campaign_details_non_ajax_returns_404()
    {
        $user = User::factory()->create(['is_admin' => true]);
        $campaign = Campaign::create([
            'name' => 'Test',
            'slug' => 'test',
            'message' => 'msg',
        ]);

        $response = $this->actingAs($user)
            ->get(route('campaigns.details_ajax', $campaign));

        $response->assertStatus(404);
    }
}
