Some checks are pending
CI / test (push) Waiting to run
Consistent brace style, spacing, and method expansion throughout domain, infrastructure, and test files. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
110 lines
3.6 KiB
PHP
110 lines
3.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Integration\Infrastructure\Channel\Frappe;
|
|
|
|
use App\Infrastructure\Channel\Frappe\FrappeHttpClient;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Symfony\Component\HttpClient\HttpClient;
|
|
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
|
|
|
/**
|
|
* Integration tests against the live ERPNext staging instance.
|
|
* Requires FRAPPE_ERP_BASE_URL, FRAPPE_ERP_API_KEY, FRAPPE_ERP_API_SECRET in .env.local.
|
|
*
|
|
* Run with: vendor/bin/phpunit --testsuite Integration
|
|
*/
|
|
final class FrappeCustomerIntegrationTest extends TestCase
|
|
{
|
|
private FrappeHttpClient $client;
|
|
private string $createdCustomerName = '';
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$baseUrl = $_SERVER['FRAPPE_ERP_BASE_URL'] ?? getenv('FRAPPE_ERP_BASE_URL');
|
|
$apiKey = $_SERVER['FRAPPE_ERP_API_KEY'] ?? getenv('FRAPPE_ERP_API_KEY');
|
|
$apiSecret = $_SERVER['FRAPPE_ERP_API_SECRET'] ?? getenv('FRAPPE_ERP_API_SECRET');
|
|
|
|
if (!$baseUrl || !$apiKey || !$apiSecret) {
|
|
$this->markTestSkipped('FRAPPE_ERP_* env vars not set');
|
|
}
|
|
|
|
$this->client = new FrappeHttpClient(
|
|
HttpClient::create(),
|
|
(string) $baseUrl,
|
|
(string) $apiKey,
|
|
(string) $apiSecret,
|
|
);
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
if ('' !== $this->createdCustomerName) {
|
|
try {
|
|
$this->client->delete('/api/resource/Customer/'.$this->createdCustomerName);
|
|
} catch (\Throwable) {
|
|
// best-effort cleanup
|
|
}
|
|
}
|
|
}
|
|
|
|
public function testCreateCustomer(): void
|
|
{
|
|
$response = $this->client->post('/api/resource/Customer', [
|
|
'customer_name' => 'Test Superseller Integration',
|
|
'customer_type' => 'Individual',
|
|
'customer_group' => 'Individual',
|
|
'territory' => 'Germany',
|
|
]);
|
|
|
|
$this->assertArrayHasKey('data', $response);
|
|
$this->assertNotEmpty($response['data']['name']);
|
|
|
|
$this->createdCustomerName = $response['data']['name'];
|
|
}
|
|
|
|
public function testFindCreatedCustomer(): void
|
|
{
|
|
// Create first
|
|
$created = $this->client->post('/api/resource/Customer', [
|
|
'customer_name' => 'Test Superseller Integration',
|
|
'customer_type' => 'Individual',
|
|
'customer_group' => 'Individual',
|
|
'territory' => 'Germany',
|
|
]);
|
|
$this->createdCustomerName = $created['data']['name'];
|
|
|
|
// Find by name
|
|
$response = $this->client->get('/api/resource/Customer/'.$this->createdCustomerName);
|
|
|
|
$this->assertSame($this->createdCustomerName, $response['data']['name']);
|
|
$this->assertSame('Test Superseller Integration', $response['data']['customer_name']);
|
|
}
|
|
|
|
public function testFindNonexistentCustomerThrows(): void
|
|
{
|
|
$this->expectException(ClientExceptionInterface::class);
|
|
|
|
$this->client->get('/api/resource/Customer/CUST-DOES-NOT-EXIST-99999');
|
|
}
|
|
|
|
public function testDeleteCustomer(): void
|
|
{
|
|
// Create
|
|
$created = $this->client->post('/api/resource/Customer', [
|
|
'customer_name' => 'Test Superseller Integration',
|
|
'customer_type' => 'Individual',
|
|
'customer_group' => 'Individual',
|
|
'territory' => 'Germany',
|
|
]);
|
|
$name = $created['data']['name'];
|
|
|
|
// Delete
|
|
$this->client->delete('/api/resource/Customer/'.$name);
|
|
|
|
// Confirm gone
|
|
$this->expectException(ClientExceptionInterface::class);
|
|
$this->client->get('/api/resource/Customer/'.$name);
|
|
}
|
|
}
|