Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 181 additions & 0 deletions Tests/Feature/AffiliateSeller/IndexAffiliateSellersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
<?php

/** @noinspection PhpUnhandledExceptionInspection */

declare(strict_types=1);

namespace PlugAndPay\Sdk\Tests\Feature\AffiliateSeller;

use DateTime;
use PHPUnit\Framework\TestCase;
use PlugAndPay\Sdk\Enum\AffiliateSellerIncludes;
use PlugAndPay\Sdk\Enum\Direction;
use PlugAndPay\Sdk\Enum\SellerSortType;
use PlugAndPay\Sdk\Enum\SellerStatus;
use PlugAndPay\Sdk\Filters\AffiliateSellerFilter;
use PlugAndPay\Sdk\Service\AffiliateSellerService;
use PlugAndPay\Sdk\Tests\Feature\AffiliateSeller\Mock\AffiliateSellerIndexMockClient;

class IndexAffiliateSellersTest extends TestCase
Comment thread
reindert-vetter marked this conversation as resolved.
{
/**
* @test
* @dataProvider relationsProvider
*/
public function index_sellers_with_relations(AffiliateSellerIncludes $include, string $includeValue): void
{
$client = (new AffiliateSellerIndexMockClient());
$service = new AffiliateSellerService($client);

$sellers = $service->include($include)->get();

static::assertSame(1, $sellers[0]->id());
static::assertSame("/v2/affiliates/sellers?include=$includeValue", $client->path());
}

/**
* Data provider for index_sellers_with_relations.
*/
public static function relationsProvider(): array
{
return [
'address' => [AffiliateSellerIncludes::ADDRESS, 'address'],
'contact' => [AffiliateSellerIncludes::CONTACT, 'contact'],
'profile' => [AffiliateSellerIncludes::PROFILE, 'profile'],
'statistics' => [AffiliateSellerIncludes::STATISTICS, 'statistics'],
'payoutOptions' => [AffiliateSellerIncludes::PAYOUT_OPTIONS, 'payout_options'],
'payoutMethods' => [AffiliateSellerIncludes::PAYOUT_METHODS, 'payout_methods'],
];
}

/**
* @dataProvider sellerFilterDataProvider
* @test
*/
public function index_sellers_with_filter(string $method, mixed $value, string $queryKey, string $queryValue): void
{
$client = (new AffiliateSellerIndexMockClient());
$service = new AffiliateSellerService($client);

$filter = (new AffiliateSellerFilter())->$method($value);
$service->get($filter);

static::assertSame("/v2/affiliates/sellers?$queryKey=$queryValue", $client->path());
}

/**
* @test
*/
public function index_sellers_with_null_decline_reason(): void
{
$client = (new AffiliateSellerIndexMockClient([
[
'id' => 1,
'name' => 'John Doe',
'email' => 'john@example.com',
'decline_reason' => null,
'profile_id' => 1,
'status' => 'accepted',
'payout_methods' => null,
],
]));
$service = new AffiliateSellerService($client);
$sellers = $service->get();

static::assertSame(1, $sellers[0]->id());
static::assertNull($sellers[0]->declineReason());
}

/**
* Data provider for index_sellers_with_filter.
*/
public static function sellerFilterDataProvider(): array
{
return [
[
'method' => 'limit',
'value' => 10,
'queryKey' => 'limit',
'queryValue' => '10',
],
[
'method' => 'sort',
'value' => SellerSortType::NAME,
'queryKey' => 'sort',
'queryValue' => 'name',
],
[
'method' => 'sort',
'value' => SellerSortType::COMMISSION,
'queryKey' => 'sort',
'queryValue' => 'commission',
],
[
'method' => 'sort',
'value' => SellerSortType::LOCKED_REVENUE,
'queryKey' => 'sort',
'queryValue' => 'locked_revenue',
],
[
'method' => 'sort',
'value' => SellerSortType::PAID_REVENUE,
'queryKey' => 'sort',
'queryValue' => 'paid_revenue',
],
[
'method' => 'sort',
'value' => SellerSortType::PENDING_REVENUE,
'queryKey' => 'sort',
'queryValue' => 'pending_revenue',
],
[
'method' => 'sort',
'value' => SellerSortType::SALES,
'queryKey' => 'sort',
'queryValue' => 'sales',
],
[
'method' => 'sort',
'value' => SellerSortType::TOTAL_REVENUE,
'queryKey' => 'sort',
'queryValue' => 'total_revenue',
],
[
'method' => 'direction',
'value' => Direction::DESC,
'queryKey' => 'direction',
'queryValue' => 'desc',
],
[
'method' => 'query',
'value' => 'John',
'queryKey' => 'q',
'queryValue' => 'John',
],
[
'method' => 'status',
'value' => SellerStatus::ACCEPTED,
'queryKey' => 'status',
'queryValue' => 'accepted',
],
[
'method' => 'eligibleForPayout',
'value' => true,
'queryKey' => 'eligible_for_payout',
'queryValue' => '1',
],
[
'method' => 'since',
'value' => new DateTime('2023-01-01'),
'queryKey' => 'since',
'queryValue' => '2023-01-01',
],
[
'method' => 'until',
'value' => new DateTime('2023-12-31'),
'queryKey' => 'until',
'queryValue' => '2023-12-31',
],
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace PlugAndPay\Sdk\Tests\Feature\AffiliateSeller\Mock;

use PlugAndPay\Sdk\Entity\Response;
use PlugAndPay\Sdk\Tests\Feature\ClientMock;

class AffiliateSellerIndexMockClient extends ClientMock
{
private string $path;

/** @noinspection PhpMissingParentConstructorInspection */
public function __construct(array $data = [[]])
{
foreach ($data as $sellerData) {
$this->responseBody[] = $sellerData + AffiliateSellerShowMockClient::BASIC_SELLER;
}
}

public function get(string $path): Response
{
$this->path = $path;

return new Response(Response::HTTP_OK, ['data' => $this->responseBody]);
}

public function path(): string
{
return $this->path;
}
}
149 changes: 149 additions & 0 deletions Tests/Feature/AffiliateSeller/Mock/AffiliateSellerShowMockClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<?php

declare(strict_types=1);

namespace PlugAndPay\Sdk\Tests\Feature\AffiliateSeller\Mock;

use JsonException;
use PlugAndPay\Sdk\Entity\Response;
use PlugAndPay\Sdk\Exception\ExceptionFactory;
use PlugAndPay\Sdk\Exception\NotFoundException;
use PlugAndPay\Sdk\Exception\ValidationException;
use PlugAndPay\Sdk\Tests\Feature\ClientMock;

class AffiliateSellerShowMockClient extends ClientMock
{
public const BASIC_SELLER = [
'id' => 1,
'name' => 'John Doe',
'email' => 'john@example.com',
'decline_reason' => '',
Comment thread
reindert-vetter marked this conversation as resolved.
'profile_id' => 1,
'status' => 'accepted',
];
protected string $path;

/** @noinspection PhpMissingParentConstructorInspection */
public function __construct(array $data = [])
{
$this->responseBody = ['data' => $data + self::BASIC_SELLER];
}

public function address(array $data = []): self
{
$this->responseBody['data']['address'] = $data + [
'city' => 'New York',
'country' => 'US',
'street' => 'Main St',
'housenumber' => '123',
'zipcode' => '10001',
];

return $this;
}

public function contact(array $data = []): self
{
$this->responseBody['data']['contact'] = $data + [
'company' => 'ACME Corp',
'email' => 'john@example.com',
'firstname' => 'John',
'lastname' => 'Doe',
'telephone' => '+1234567890',
'website' => 'https://example.com',
'vat_id_number' => 'US123456789',
'tax_exempt' => 'none',
];

return $this;
}

/**
* @throws NotFoundException
* @throws ValidationException
* @throws JsonException
*/
public function get(string $path): Response
{
$this->path = $path;
$response = new Response(Response::HTTP_OK, $this->responseBody);

$exception = ExceptionFactory::create($response->status(), json_encode($response->body(), JSON_THROW_ON_ERROR));
if ($exception) {
throw $exception;
}

return $response;
}

public function path(): string
{
return $this->path;
}

public function profile(array $data = []): self
{
$this->responseBody['data']['profile'] = $data + [
'id' => 14,
'default_recurring' => false,
'default_type' => 'percentage',
'default_value' => '50.00',
'default_form_value' => '2.50',
'label' => '',
'session_lifetime' => 120,
'tenant_id' => 3,
];

return $this;
}

public function statistics(array $data = []): self
{
$this->responseBody['data']['statistics'] = $data + [
'clicks' => null,
'commission' => 0,
'locked' => 0,
'orders' => 0,
'paidout' => 0,
'pending' => 0,
'recurring' => 0,
'sales' => 0,
'value' => 0,
];

return $this;
}

public function payoutOptions(array $data = []): self
{
$this->responseBody['data']['payout_options'] = $data + [
'method' => 'paypal',
'settings' => [
'email' => 'oramcharan@example.com',
'phone' => '+3177 4223366',
'paypal_me_link' => 'https://paypal.me/lopes.jennifer',
],
];

return $this;
}

public function payoutMethods(?array $data = null): self
{
if ($data === null) {
$data = [
[
'method' => 'bank_transfer',
'settings' => [
'iban' => 'NL91ABNA0417164300',
'bic' => 'ABNANL2A',
],
],
];
}

$this->responseBody['data']['payout_methods'] = $data;

return $this;
}
}
Loading