100 lines
3.4 KiB
PHP
100 lines
3.4 KiB
PHP
<?php
|
|
|
|
app_require('classes/economic.php');
|
|
|
|
use classes\economic;
|
|
use endpoints\economic_customers_endpoint;
|
|
use endpoints\customers\economic_customers_endpoint as economic_customers_resource_endpoint;
|
|
|
|
if (!class_exists('EconomicCreateCustomerInnerStub')) {
|
|
class EconomicCreateCustomerInnerStub extends economic_customers_resource_endpoint
|
|
{
|
|
public array $lastPayload = [];
|
|
|
|
public function __construct(private readonly object $stubResponse)
|
|
{
|
|
}
|
|
|
|
public function create(array $data): object
|
|
{
|
|
$this->lastPayload = $data;
|
|
|
|
return $this->stubResponse;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!class_exists('EconomicCreateCustomerEndpointStub')) {
|
|
class EconomicCreateCustomerEndpointStub extends economic_customers_endpoint
|
|
{
|
|
public function __construct(public EconomicCreateCustomerInnerStub $inner)
|
|
{
|
|
$this->customers = $inner;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!class_exists('EconomicCreateCustomerProbe')) {
|
|
class EconomicCreateCustomerProbe extends economic
|
|
{
|
|
public EconomicCreateCustomerInnerStub $inner;
|
|
|
|
public function __construct(object $stubResponse)
|
|
{
|
|
$this->inner = new EconomicCreateCustomerInnerStub($stubResponse);
|
|
$this->customers = new EconomicCreateCustomerEndpointStub($this->inner);
|
|
}
|
|
}
|
|
}
|
|
|
|
it('returns the raw upstream create response and preserves the requested payload', function (): void {
|
|
$stubResponse = (object)[
|
|
'customerNumber' => 42331123,
|
|
'name' => 'Truckwash ApS',
|
|
];
|
|
|
|
$probe = new EconomicCreateCustomerProbe($stubResponse);
|
|
$result = $probe->createCustomer(42331123, 'Truckwash ApS', 37781258, 'jb@truckwash.dk', 42331123);
|
|
|
|
expect($result)->toBe($stubResponse);
|
|
expect($probe->inner->lastPayload['customerNumber'])->toBe(42331123);
|
|
expect($probe->inner->lastPayload['corporateIdentificationNumber'])->toBe('37781258');
|
|
expect($probe->inner->lastPayload['phone'])->toBe(42331123);
|
|
expect($probe->inner->lastPayload['telephoneAndFaxNumber'])->toBe('42331123');
|
|
expect($probe->inner->lastPayload['mobilePhone'])->toBe('42331123');
|
|
});
|
|
|
|
it('adds supported CVR company fields to the e-conomic customer payload', function (): void {
|
|
$stubResponse = (object)[
|
|
'customerNumber' => 42331123,
|
|
'name' => 'Truckwash ApS',
|
|
];
|
|
$companyInformation = (object)[
|
|
'address' => 'Testvej 12',
|
|
'zipcode' => 2630,
|
|
'city' => 'Taastrup',
|
|
'website' => 'https://truckwash.test',
|
|
'industrycode' => 953190,
|
|
];
|
|
|
|
$probe = new EconomicCreateCustomerProbe($stubResponse);
|
|
$result = $probe->createCustomer(
|
|
42331123,
|
|
'Truckwash ApS',
|
|
37781258,
|
|
'invoice@truckwash.test',
|
|
42331123,
|
|
55667788,
|
|
$companyInformation,
|
|
);
|
|
|
|
expect($result)->toBe($stubResponse);
|
|
expect($probe->inner->lastPayload['address'])->toBe('Testvej 12');
|
|
expect($probe->inner->lastPayload['zip'])->toBe('2630');
|
|
expect($probe->inner->lastPayload['city'])->toBe('Taastrup');
|
|
expect($probe->inner->lastPayload['website'])->toBe('https://truckwash.test');
|
|
expect($probe->inner->lastPayload['telephoneAndFaxNumber'])->toBe('42331123');
|
|
expect($probe->inner->lastPayload['mobilePhone'])->toBe('55667788');
|
|
expect(array_key_exists('industrycode', $probe->inner->lastPayload))->toBeFalse();
|
|
});
|