<?php

namespace Opentalent\OtCore\Tests\Unit\Domain\Repository;

use Prophecy\PhpUnit\ProphecyTrait;


class MemberRepositoryTest extends AbstractApiRepositoryTestCase
{
    use ProphecyTrait;

    const TESTED_CLASS = "Opentalent\OtCore\Domain\Repository\MemberRepository";

    /**
     * findByOrganizationId should return an ApiPagedCollection object containing
     * the member(s) matching the given organizationId
     *
     * @test
     */
    public function findByOrganizationId() {
        $organization_id = 1;

        $expected_uri = "api/public/members?_format=json&filter%5Bwhere%5D%5BorganizationId%5D=1&itemsPerPage=20000";
        $this->injectClientFor($expected_uri);

        $actual = $this->repository->findByOrganizationId($organization_id);
        $this->assertEquals($organization_id, $actual->getMembers()[0]->getOrganizationId());
    }

    /**
     * memberToObject should return null if the given
     * member has not the good type
     *
     * @test
     */
    public function memberToObjectError() {
        $this->assertEquals(
            null,
            $this->callMemberToObject(['@type' => 'Invalid'])
        );
    }
}
