SuperSeller3000/tests/Unit/Infrastructure/Channel/Ebay/EbayAdapterTest.php

62 lines
2.1 KiB
PHP
Raw Normal View History

<?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\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 EbayAdapter $adapter;
private Article $article;
protected function setUp(): void
{
$this->apiClient = $this->createMock(EbayInventoryApiClient::class);
$this->adapter = new EbayAdapter($this->apiClient);
$this->article = new Article(new ArticleType('Notebook'), 'NB-001', 'INV-001', 1, ArticleCondition::Good);
$this->article->setEbayTitle('Dell Latitude 5520');
$this->article->setListingPrice('299.00');
}
public function test_get_type_returns_ebay(): void
{
$this->assertSame('ebay', $this->adapter->getType());
}
public function test_publish_listing_calls_upsert_create_and_publish(): void
{
$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 test_deactivate_listing_withdraws_offer(): void
{
$this->article->setEbayListingId('offer-123');
$this->apiClient->expects($this->once())->method('withdrawOffer')->with('offer-123');
$this->adapter->deactivateListing($this->article);
}
public function test_deactivate_listing_is_noop_when_no_listing_id(): void
{
$this->apiClient->expects($this->never())->method('withdrawOffer');
$this->adapter->deactivateListing($this->article);
}
}