SuperSeller3000/tests/Unit/Infrastructure/Order/CustomerResolverTest.php
Simon Kuehn 46cff4553f feat: add eBay and Frappe channel adapters with order infrastructure
eBay adapter covers OAuth, inventory API, fulfillment API, taxonomy
service and webhook signature verification. Frappe ERP adapter wraps
the Frappe HTTP client for order/invoice sync.

Includes CustomerResolver, InvoiceMailer, and the EbayWebhookController
for inbound eBay marketplace notifications.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 22:43:52 +00:00

89 lines
3.4 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Unit\Infrastructure\Order;
use App\Application\Order\ErpAdapterInterface;
use App\Domain\Order\Customer;
use App\Domain\Order\Repository\CustomerRepositoryInterface;
use App\Infrastructure\Order\CustomerResolver;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
final class CustomerResolverTest extends TestCase
{
private CustomerRepositoryInterface&MockObject $customerRepo;
private ErpAdapterInterface&MockObject $erp;
private CustomerResolver $resolver;
protected function setUp(): void
{
$this->customerRepo = $this->createMock(CustomerRepositoryInterface::class);
$this->erp = $this->createMock(ErpAdapterInterface::class);
$this->resolver = new CustomerResolver($this->customerRepo, $this->erp);
}
public function test_stage_1_platform_id_match_returns_existing_customer_without_erp_call(): void
{
$existing = new Customer('Max Mustermann', 'max@test.de', ['street' => 'Musterstr 1', 'city' => 'Berlin', 'zip' => '10115']);
$existing->addPlatformId('ebay', 'buyer123');
$this->customerRepo
->method('findByPlatformId')
->with('ebay', 'buyer123')
->willReturn($existing);
$this->erp->expects($this->never())->method('createCustomer');
$this->customerRepo->expects($this->never())->method('save');
$result = $this->resolver->resolve(
'ebay', 'buyer123',
'Max Mustermann', 'max@test.de',
['street' => 'Musterstr 1', 'city' => 'Berlin', 'zip' => '10115'],
);
$this->assertSame($existing, $result);
}
public function test_stage_2_address_match_adds_platform_id_and_saves(): void
{
$existing = new Customer('Max Mustermann', 'max@test.de', ['street' => 'Musterstr 1', 'city' => 'Berlin', 'zip' => '10115']);
$this->customerRepo->method('findByPlatformId')->willReturn(null);
$this->customerRepo
->method('findByMatchingKey')
->with($existing->getMatchingKey())
->willReturn($existing);
$this->customerRepo->expects($this->once())->method('save')->with($existing);
$this->erp->expects($this->never())->method('createCustomer');
$result = $this->resolver->resolve(
'ebay', 'buyer456',
'Max Mustermann', 'max@test.de',
['street' => 'Musterstr 1', 'city' => 'Berlin', 'zip' => '10115'],
);
$this->assertSame($existing, $result);
$this->assertSame('buyer456', $result->getPlatformId('ebay'));
}
public function test_no_match_creates_new_customer_via_erp(): void
{
$this->customerRepo->method('findByPlatformId')->willReturn(null);
$this->customerRepo->method('findByMatchingKey')->willReturn(null);
$this->customerRepo->expects($this->once())->method('save');
$this->erp->method('createCustomer')->willReturn('CUST-99999');
$result = $this->resolver->resolve(
'ebay', 'newbuyer',
'Neue Käuferin', 'neu@test.de',
['street' => 'Neustr 5', 'city' => 'München', 'zip' => '80333'],
);
$this->assertSame('CUST-99999', $result->getFrappeCustomerId());
$this->assertSame('newbuyer', $result->getPlatformId('ebay'));
$this->assertSame('Neue Käuferin', $result->getName());
}
}