SuperSeller3000/tests/Unit/Infrastructure/Channel/Frappe/FrappeErpAdapterTest.php

83 lines
2.6 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace App\Tests\Unit\Infrastructure\Channel\Frappe;
use App\Domain\Article\Article;
use App\Domain\Article\ArticleCondition;
use App\Domain\Article\ArticleType;
use App\Domain\Channel\Platform;
use App\Domain\Order\Customer;
use App\Domain\Order\Order;
use App\Infrastructure\Channel\Frappe\FrappeErpAdapter;
use App\Infrastructure\Channel\Frappe\FrappeHttpClient;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
final class FrappeErpAdapterTest extends TestCase
{
private FrappeHttpClient&MockObject $frappe;
private FrappeErpAdapter $adapter;
protected function setUp(): void
{
$this->frappe = $this->createMock(FrappeHttpClient::class);
$this->adapter = new FrappeErpAdapter($this->frappe, 'REFURB-HW');
}
public function test_create_customer_returns_frappe_id(): void
{
$this->frappe
->method('post')
->with('/api/resource/Customer', $this->isType('array'))
->willReturn(['data' => ['name' => 'CUST-00001']]);
$customer = new Customer('Max Mustermann', 'max@test.de', ['street' => 'Str 1', 'city' => 'Berlin', 'zip' => '10115']);
$customer->addPlatformId('ebay', 'buyer123');
$result = $this->adapter->createCustomer($customer);
$this->assertSame('CUST-00001', $result);
}
public function test_create_sales_invoice_submits_and_returns_id(): void
{
$this->frappe
->expects($this->exactly(2))
->method('post')
->willReturnOnConsecutiveCalls(
['data' => ['name' => 'SINV-00001']],
['data' => ['name' => 'SINV-00001', 'docstatus' => 1]],
);
$customer = new Customer('Max Mustermann', 'max@test.de', ['street' => 'Str 1', 'city' => 'Berlin', 'zip' => '10115']);
$customer->setFrappeCustomerId('CUST-00001');
$order = new Order(
new Article(new ArticleType('Laptop'), 'LAP-001', 'INV-001', 1, ArticleCondition::Good),
$customer,
new Platform('ebay', 'eBay DE'),
'ORDER-001',
'299.99',
new \DateTimeImmutable('2026-05-13'),
);
$result = $this->adapter->createSalesInvoice($order);
$this->assertSame('SINV-00001', $result);
}
public function test_fetch_invoice_pdf_returns_binary(): void
{
$this->frappe
->method('getContent')
->with($this->stringContains('SINV-00001'))
->willReturn('%PDF-binary-content');
$result = $this->adapter->fetchInvoicePdf('SINV-00001');
$this->assertStringStartsWith('%PDF', $result);
}
}