SuperSeller3000/tests/Unit/Infrastructure/Channel/Ebay/EbayAdapterTest.php
Simon Kuehn 6bd8e0bec8
Some checks are pending
CI / test (push) Waiting to run
feat: eBay business policies + per-adapter admin navigation
- ArticleTypePlatformConfig: fulfillmentPolicyId, paymentPolicyId,
  returnPolicyId, merchantLocationKey (all nullable)
- EbayAccountApiClient: fetches Fulfillment/Payment/Return policies
  from eBay Account API (/sell/account/v1)
- EbayInventoryApiClient: adds getLocations()
- EbayPolicyProvider: aggregates choices with 5 min cache; returns
  empty array on API failure so the form degrades to TextField
- EbayAdapter: reads real ArticleTypePlatformConfig (category ID no
  longer hardcoded), passes listingPolicies + merchantLocationKey
  into createOffer() when set
- EbayArticleTypePlatformConfigCrudController: live policy dropdowns
  from EbayPolicyProvider; fallback to TextField with help text
- DashboardController: eBay subMenu with Kategorie-Konfigurationen
- 7 new unit tests for EbayAdapter policy scenarios

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 07:13:51 +00:00

124 lines
5.1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Unit\Infrastructure\Channel\Ebay;
use App\Domain\Article\Article;
use App\Domain\Article\ArticleCondition;
use App\Domain\Article\ArticleType;
use App\Domain\Channel\ArticleTypePlatformConfig;
use App\Domain\Channel\Platform;
use App\Domain\Channel\Repository\ArticleTypePlatformConfigRepositoryInterface;
use App\Infrastructure\Channel\Ebay\EbayAdapter;
use App\Infrastructure\Channel\Ebay\EbayInventoryApiClient;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
final class EbayAdapterTest extends TestCase
{
private EbayInventoryApiClient&MockObject $apiClient;
private ArticleTypePlatformConfigRepositoryInterface&MockObject $configRepo;
private EbayAdapter $adapter;
private Article $article;
private ArticleTypePlatformConfig $platformConfig;
protected function setUp(): void
{
$this->apiClient = $this->createMock(EbayInventoryApiClient::class);
$this->configRepo = $this->createMock(ArticleTypePlatformConfigRepositoryInterface::class);
$this->adapter = new EbayAdapter($this->apiClient, $this->configRepo, 'EBAY_DE');
$articleType = new ArticleType('Notebook');
$platform = new Platform('ebay', 'eBay');
$this->platformConfig = new ArticleTypePlatformConfig($articleType, $platform, '177');
$this->article = new Article($articleType, 'NB-001', 'INV-001', 1, ArticleCondition::Good);
$this->article->setEbayTitle('Dell Latitude 5520');
$this->article->setListingPrice('299.00');
}
public function testGetTypeReturnsEbay(): void
{
$this->assertSame('ebay', $this->adapter->getType());
}
public function testPublishListingCallsUpsertCreateAndPublish(): void
{
$this->configRepo->method('findByArticleTypeAndPlatformType')->willReturn($this->platformConfig);
$this->apiClient->expects($this->once())->method('upsertInventoryItem');
$this->apiClient->expects($this->once())->method('createOffer')->willReturn('offer-123');
$this->apiClient->expects($this->once())->method('publishOffer')->with('offer-123')->willReturn('listing-456');
$listingId = $this->adapter->publishListing($this->article);
$this->assertSame('listing-456', $listingId);
}
public function testPublishListingThrowsWhenNoPlatformConfig(): void
{
$this->configRepo->method('findByArticleTypeAndPlatformType')->willReturn(null);
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('No eBay platform config found for ArticleType');
$this->adapter->publishListing($this->article);
}
public function testPublishListingIncludesPoliciesWhenSet(): void
{
$this->platformConfig->setFulfillmentPolicyId('FP-123');
$this->platformConfig->setPaymentPolicyId('PP-456');
$this->platformConfig->setReturnPolicyId('RP-789');
$this->platformConfig->setMerchantLocationKey('WAREHOUSE-1');
$this->configRepo->method('findByArticleTypeAndPlatformType')->willReturn($this->platformConfig);
$this->apiClient->expects($this->once())->method('upsertInventoryItem');
$this->apiClient->expects($this->once())
->method('createOffer')
->with($this->callback(static function (array $body): bool {
return isset($body['listingPolicies']['fulfillmentPolicyId'])
&& 'FP-123' === $body['listingPolicies']['fulfillmentPolicyId']
&& 'PP-456' === $body['listingPolicies']['paymentPolicyId']
&& 'RP-789' === $body['listingPolicies']['returnPolicyId']
&& 'WAREHOUSE-1' === $body['merchantLocationKey'];
}))
->willReturn('offer-123');
$this->apiClient->method('publishOffer')->willReturn('listing-456');
$this->adapter->publishListing($this->article);
}
public function testPublishListingOmitsPoliciesWhenNotSet(): void
{
$this->configRepo->method('findByArticleTypeAndPlatformType')->willReturn($this->platformConfig);
$this->apiClient->expects($this->once())->method('upsertInventoryItem');
$this->apiClient->expects($this->once())
->method('createOffer')
->with($this->callback(static function (array $body): bool {
return !isset($body['listingPolicies']) && !isset($body['merchantLocationKey']);
}))
->willReturn('offer-123');
$this->apiClient->method('publishOffer')->willReturn('listing-456');
$this->adapter->publishListing($this->article);
}
public function testDeactivateListingWithdrawsOffer(): void
{
$this->article->setEbayListingId('offer-123');
$this->apiClient->expects($this->once())->method('withdrawOffer')->with('offer-123');
$this->adapter->deactivateListing($this->article);
}
public function testDeactivateListingIsNoopWhenNoListingId(): void
{
$this->apiClient->expects($this->never())->method('withdrawOffer');
$this->adapter->deactivateListing($this->article);
}
}