<commit_before><?php

namespace eCamp\ApiTest\Rest;

use Doctrine\Common\DataFixtures\Loader;
use eCamp\Core\Entity\CampCollaboration;
use eCamp\Core\Entity\User;
use eCamp\CoreTest\Data\CampCollaborationTestData;
use eCamp\CoreTest\Data\UserTestData;
use eCamp\LibTest\PHPUnit\AbstractApiControllerTestCase;

/**
 * @internal
 */
class CampCollaborationTest extends AbstractApiControllerTestCase {
    /** @var CampCollaboration */
    protected $campCollaboration1;
    /** @var CampCollaboration */
    protected $campCollaborationInvited;

    /** @var User */
    protected $user;

    private $apiEndpoint = '/api/camp-collaborations';

    public function setUp(): void {
        parent::setUp();

        $userLoader = new UserTestData();
        $campCollaborationLoader = new CampCollaborationTestData();

        $loader = new Loader();
        $loader->addFixture($userLoader);
        $loader->addFixture($campCollaborationLoader);
        $this->loadFixtures($loader);

        $this->user = $userLoader->getReference(UserTestData::$USER1);
        $this->campCollaboration1 = $campCollaborationLoader->getReference(CampCollaborationTestData::$COLLAB1);
        $this->campCollaborationInvited = $campCollaborationLoader->getReference(CampCollaborationTestData::$COLLAB_INVITED);

        $this->authenticateUser($this->user);
    }

    public function testFetch() {
        $this->dispatch("{$this->apiEndpoint}/{$this->campCollaboration1->getId()}", 'GET');

        $this->assertResponseStatusCode(200);

        $expectedBody = <<<JSON
            {
                "id": "{$this->campCollaboration1->getId()}",
                "role": "member",
                "status": "established",
                "inviteEmail": null
            }
JSON;

        $expectedLinks = <<<JSON
            {
                "self": {
                    "href": "http://{$this->host}{$this->apiEndpoint}/{$this->campCollaboration1->getId()}"
                }
            }
JSON;
        $expectedEmbeddedObjects = [
            'camp',
            'user',
        ]; // TODO discuss: wouldn't 'campCollaborationResponsibles' be more intuitive than 'campCollaborations'

        $this->verifyHalResourceResponse($expectedBody, $expectedLinks, $expectedEmbeddedObjects);
    }

    public function testFetchOnlyEmail() {
        $this->dispatch("{$this->apiEndpoint}/{$this->campCollaborationInvited->getId()}", 'GET');

        $this->assertResponseStatusCode(200);

        $expectedBody = <<<JSON
            {
                "id": "{$this->campCollaborationInvited->getId()}",
                "role": "{$this->campCollaborationInvited->getRole()}",
                "status": "{$this->campCollaborationInvited->getStatus()}",
                "inviteEmail": "{$this->campCollaborationInvited->getInviteEmail()}",
                "user": null
            }
JSON;

        $expectedLinks = <<<JSON
            {
                "self": {
                    "href": "http://{$this->host}{$this->apiEndpoint}/{$this->campCollaborationInvited->getId()}"
                }
            }
JSON;
        $expectedEmbeddedObjects = ['camp']; // TODO discuss: wouldn't 'campCollaborationResponsibles' be more intuitive than 'campCollaborations'

        $this->verifyHalResourceResponse($expectedBody, $expectedLinks, $expectedEmbeddedObjects);
    }

    public function testFetchAll() {
        $campId = $this->campCollaboration1->getCamp()->getId();
        $userId = $this->user->getId();
        $this->dispatch("{$this->apiEndpoint}?page_size=10&userId={$userId}&campId={$campId}", 'GET');

        $this->assertResponseStatusCode(200);<commit_msg>CampCollaborationTest: remove TODO comments for discussions<commit_after><?php

namespace eCamp\ApiTest\Rest;

use Doctrine\Common\DataFixtures\Loader;
use eCamp\Core\Entity\CampCollaboration;
use eCamp\Core\Entity\User;
use eCamp\CoreTest\Data\CampCollaborationTestData;
use eCamp\CoreTest\Data\UserTestData;
use eCamp\LibTest\PHPUnit\AbstractApiControllerTestCase;

/**
 * @internal
 */
class CampCollaborationTest extends AbstractApiControllerTestCase {
    /** @var CampCollaboration */
    protected $campCollaboration1;
    /** @var CampCollaboration */
    protected $campCollaborationInvited;

    /** @var User */
    protected $user;

    private $apiEndpoint = '/api/camp-collaborations';

    public function setUp(): void {
        parent::setUp();

        $userLoader = new UserTestData();
        $campCollaborationLoader = new CampCollaborationTestData();

        $loader = new Loader();
        $loader->addFixture($userLoader);
        $loader->addFixture($campCollaborationLoader);
        $this->loadFixtures($loader);

        $this->user = $userLoader->getReference(UserTestData::$USER1);
        $this->campCollaboration1 = $campCollaborationLoader->getReference(CampCollaborationTestData::$COLLAB1);
        $this->campCollaborationInvited = $campCollaborationLoader->getReference(CampCollaborationTestData::$COLLAB_INVITED);

        $this->authenticateUser($this->user);
    }

    public function testFetch() {
        $this->dispatch("{$this->apiEndpoint}/{$this->campCollaboration1->getId()}", 'GET');

        $this->assertResponseStatusCode(200);

        $expectedBody = <<<JSON
            {
                "id": "{$this->campCollaboration1->getId()}",
                "role": "member",
                "status": "established",
                "inviteEmail": null
            }
JSON;

        $expectedLinks = <<<JSON
            {
                "self": {
                    "href": "http://{$this->host}{$this->apiEndpoint}/{$this->campCollaboration1->getId()}"
                }
            }
JSON;
        $expectedEmbeddedObjects = [
            'camp',
            'user',
        ];

        $this->verifyHalResourceResponse($expectedBody, $expectedLinks, $expectedEmbeddedObjects);
    }

    public function testFetchOnlyEmail() {
        $this->dispatch("{$this->apiEndpoint}/{$this->campCollaborationInvited->getId()}", 'GET');

        $this->assertResponseStatusCode(200);

        $expectedBody = <<<JSON
            {
                "id": "{$this->campCollaborationInvited->getId()}",
                "role": "{$this->campCollaborationInvited->getRole()}",
                "status": "{$this->campCollaborationInvited->getStatus()}",
                "inviteEmail": "{$this->campCollaborationInvited->getInviteEmail()}",
                "user": null
            }
JSON;

        $expectedLinks = <<<JSON
            {
                "self": {
                    "href": "http://{$this->host}{$this->apiEndpoint}/{$this->campCollaborationInvited->getId()}"
                }
            }
JSON;
        $expectedEmbeddedObjects = ['camp'];

        $this->verifyHalResourceResponse($expectedBody, $expectedLinks, $expectedEmbeddedObjects);
    }

    public function testFetchAll() {
        $campId = $this->campCollaboration1->getCamp()->getId();
        $userId = $this->user->getId();
        $this->dispatch("{$this->apiEndpoint}?page_size=10&userId={$userId}&campId={$campId}", 'GET');

        $this->assertResponseStatusCode(200);
{'fraction_non_alphanumeric': 0.15084033613445377, 'fraction_numerical': 0.005322128851540616, 'mean_word_length': 2.7663502109704643, 'pattern_counts': {'":': 26, '<': 29, '<?xml version=': 0, '>': 101, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4937694', 'n_tokens_mistral': 2061, 'n_tokens_neox': 1992, 'n_words': 278}