<?php

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

use Prophecy\PhpUnit\ProphecyTrait;


class DonorRepositoryTest extends AbstractApiRepositoryTestCase
{
    use ProphecyTrait;

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

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

        $expected_uri = "api/public/donors?_format=json&organizationId=1&page=1&itemsPerPage=99";
        $this->injectClientFor($expected_uri);

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

    /**
     * findParentsByOrganizationId should return an ApiPagedCollection object containing
     * the donor(s) of the parent of the given organization
     *
     * @test
     */
    public function findParentsByOrganizationId() {
        $organization_id = 1;

        $expected_uri = "api/public/donors?_format=json&organizationId=1&parent=1&page=1&itemsPerPage=99";
        $this->injectClientFor($expected_uri);

        $actual = $this->repository->findParentsByOrganizationId($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'])
        );
    }
}
