Files
api/services/nginx/app/tests/Unit/Invoicing/EconomicCustomerEanHelperTest.php
T
59107a6bb2 Enforce e-conomic discount template + EAN draft metadata (#349)
## What changed
- enforce EAN draft delivery wiring by setting
`recipient.nemHandelType=ean` when customer EAN is present
- copy existing e-conomic customer metadata into draft payload:
`recipient.attention`, `references.customerContact`,
`references.salesPerson`, and `deliveryLocation`
- keep `references.other` external-id mapping intact
- remove legacy explicit `Rabat:` text-line injection and use line-level
`discountPercentage` instead
- add/update unit tests for helper extraction and discount/EAN wiring

## Tests
- `vendor/bin/pest
tests/Unit/Invoicing/EconomicCustomerEanHelperTest.php
tests/Unit/Invoicing/EconomicInvoiceDraftRecipientEanWiringTest.php
tests/Unit/Invoicing/EconomicLegacyDraftDiscountWiringTest.php
tests/Unit/Invoicing/EconomicInvoiceDraftDiscountLineModeWiringTest.php
tests/Unit/Invoicing/CollectedInvoiceEconomicBatchTransferWiringTest.php
tests/Unit/Invoicing/EconomicInvoiceDraftItemizedDiscountTest.php
--colors=never`

## Notes
- full unit suite in this environment still has an unrelated
pre-existing failure in
`Tests\\Unit\\Bird\\BirdControlPlaneActivationTest` requiring
`PLENO_REPO_ROOT_FOR_TESTS`.
- live manual verification against customer `12345679` remains
environment-blocked due missing e-conomic credentials.

---------

Co-authored-by: Jeppe Bundgaard <jb@truckwash.dk>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-08-05 14:44:40 +02:00

65 lines
2.4 KiB
PHP

<?php
app_require('modules/economic/helpers/economic_customer.php');
use helpers\economic_customer;
function economic_customer_helper_from_payload(object $payload): economic_customer
{
$reflection = new ReflectionClass(economic_customer::class);
/** @var economic_customer $customer */
$customer = $reflection->newInstanceWithoutConstructor();
$property = $reflection->getProperty('customer_data_object');
$property->setValue($customer, $payload);
return $customer;
}
it('exposes optional EAN and public entry number from fetched e-conomic customer data', function (): void {
$customer = economic_customer_helper_from_payload((object)[
'customerNumber' => 42331123,
'ean' => ' 5790001234567 ',
'publicEntryNumber' => ' DK123456789 ',
'attention' => (object)[
'customerContactNumber' => 9,
],
'customerContact' => (object)[
'customerContactNumber' => 10,
],
'salesPerson' => (object)[
'employeeNumber' => 12,
],
'vendorReference' => (object)[
'employeeNumber' => 14,
],
'defaultDeliveryLocation' => (object)[
'deliveryLocationNumber' => 7,
],
]);
expect($customer->getEan())->toBe('5790001234567');
expect($customer->getPublicEntryNumber())->toBe('DK123456789');
expect($customer->getAttentionCustomerContactNumber())->toBe(9);
expect($customer->getReferenceCustomerContactNumber())->toBe(10);
expect($customer->getSalesPersonEmployeeNumber())->toBe(12);
expect($customer->getVendorReferenceEmployeeNumber())->toBe(14);
expect($customer->getDefaultDeliveryLocationNumber())->toBe(7);
});
it('returns null for blank optional e-conomic customer recipient identifiers', function (): void {
$customer = economic_customer_helper_from_payload((object)[
'customerNumber' => 42331123,
'ean' => ' ',
'publicEntryNumber' => '',
]);
expect($customer->getEan())->toBeNull();
expect($customer->getPublicEntryNumber())->toBeNull();
expect($customer->getAttentionCustomerContactNumber())->toBeNull();
expect($customer->getReferenceCustomerContactNumber())->toBeNull();
expect($customer->getSalesPersonEmployeeNumber())->toBeNull();
expect($customer->getVendorReferenceEmployeeNumber())->toBeNull();
expect($customer->getDefaultDeliveryLocationNumber())->toBeNull();
});