<?php
/**
 * @author Daniel Knudsen <d.knudsen@spawntree.de>
 * @date 12.12.23
 */


namespace App\Tests\Functional;

use App\Factory\MediaObjectLogoFactory;
use App\Factory\MediaObjectUserFactory;
use App\Factory\PartnerFactory;
use App\Factory\PartnerFollowFactory;
use App\Factory\UserFactory;
use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Zenstruck\Browser\Test\HasBrowser;
use Zenstruck\Foundry\Test\Factories;
use Zenstruck\Foundry\Test\ResetDatabase;

class PartnerFollowResourceTest extends KernelTestCase
{
    use HasBrowser;
    use ResetDatabase;
    use Factories;

    private JWTTokenManagerInterface $JWTManager;

    protected function setUp(): void
    {
        parent::setUp();
        $this->JWTManager = self::getContainer()->get('lexik_jwt_authentication.jwt_manager');
    }

    public function testPostPartnerFollow(): void
    {
        $user = UserFactory::createOne(
            [
                'firstName' => 'Peter',
                'lastName' => 'Test',
                'password' => 'test',
                'email' => 'peter@test.de',
            ]
        );
        $partner = PartnerFactory::createOne();

        $token = $this->JWTManager->create($user->object());

        $this->browser()
            ->post('/api/partner_follows' , [
                'json' => [
                    'partner' => '/api/partners/' . $partner->getId(),
                ],
                'headers' => [
                    'Authorization' => 'Bearer ' . $token,
                ]
            ])
            ->assertSuccessful()
        ;

        $this->browser()
            ->get('/api/partner_follows', [
                    'headers' => [
                    'Authorization' => 'Bearer ' . $token,
                ],
            ])
            ->assertSuccessful()
            ->assertJsonMatches('"hydra:totalItems"', 1)
        ;
    }
}