Files
api/services/nginx/app/tests/Unit/Invoicing/EconomicUpstreamErrorFormattingTest.php
T
8735bae8d5 Fix queue export 400 by aligning e-conomic reference payloads (#351)
## Context
Queue job **#3572** failed in `COLLECTED_INVOICE_EXPORT` with e-conomic
HTTP 400 (`Validation failed. 2 errors found.`) while creating draft for
customer `35131752`.

## Fix
- align draft payload optional references to e-conomic object references
(not id-only fragments):
  - `recipient.attention`
  - `references.customerContact`
  - `references.salesPerson`
  - `references.vendorReference` (legacy path)
  - `deliveryLocation`
- include upstream `self` links when available from customer payload
- keep both collected and legacy draft creation paths consistent
- improve e-conomic error formatting so nested annotated validation
errors and `developerHint` are included in thrown messages

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

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

47 lines
1.7 KiB
PHP

<?php
app_require('modules/economic/economic_m.php');
it('includes nested annotated e-conomic validation errors and developer hint in runtime exceptions', function (): void {
$economic = new class extends economic_m {
public function __construct()
{
// Intentionally skip parent constructor to avoid credential requirements in tests.
}
public function formatForTest(int $httpStatusCode, string $response): string
{
return $this->format_upstream_error_message($httpStatusCode, $response);
}
};
$response = json_encode([
'message' => 'Validation failed. 2 errors found.',
'developerHint' => 'Review annotated errors for payload details.',
'errors' => [
'recipient' => [
'attention' => [
'errorMessage' => 'Customer contact not found for recipient attention.',
],
],
'references' => [
'customerContact' => [
'errorMessage' => 'Customer contact reference is invalid.',
],
],
],
'logId' => 'abc123',
'httpStatusCode' => 400,
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
expect($response)->not->toBeFalse();
$formatted = $economic->formatForTest(400, (string)$response);
expect($formatted)
->toContain('Validation failed. 2 errors found.')
->toContain('errors.recipient.attention: Customer contact not found for recipient attention.')
->toContain('errors.references.customerContact: Customer contact reference is invalid.')
->toContain('developerHint')
->toContain('abc123');
});