<?php

namespace App\Tests\Controller;

use App\Entity\Payout;
use App\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class AttestationControllerTest extends WebTestCase
{
    public function testCheckWithValidPayout(): void
    {
        $client = static::createClient();
        $em = static::getContainer()->get(EntityManagerInterface::class);

        $user = new User();
        $user->setEmail('test-attest-'.uniqid().'@example.com');
        $user->setFirstName('Test');
        $user->setLastName('User');
        $user->setPassword('$2y$13$hashed');
        $em->persist($user);

        $payout = new Payout();
        $payout->setOrganizer($user);
        $payout->setStripePayoutId('po_check_'.uniqid());
        $payout->setStatus('paid');
        $payout->setAmount(10000);
        $payout->setCurrency('eur');
        $em->persist($payout);
        $em->flush();

        $client->request('GET', '/attestation/check/'.$payout->getStripePayoutId());

        self::assertResponseIsSuccessful();
        self::assertSelectorTextContains('body', 'Attestation authentique');
    }

    public function testCheckWithInvalidPayout(): void
    {
        $client = static::createClient();
        $client->request('GET', '/attestation/check/po_fake_invalid');

        self::assertResponseIsSuccessful();
        self::assertSelectorTextContains('body', 'Attestation introuvable');
    }
}
