Log-Analyse 26.08. (P0-2, P1-5, P2-3): - Produktcode fuer DHL Paket International ist V53WPAK; mit V53PAK wurde kein einziges Auslandslabel erzeugt. Alte Codes werden gemappt (LEGACY_PRODUCT_CODE_ALIASES), Abrechnungsnummer und Masse suchen auch unter den alten Setting-Schluesseln (dhl_account_v53pak) und Env-Namen. - Zu lange Felder (Name, Stadt, Telefon, Referenz) werden auf die DHL-Grenzen gekuerzt bzw. bereinigt statt den Versand abzulehnen; refNo mindestens 8 Zeichen, sonst die Bestellreferenz. - Tracking wiederholt bei HTTP 5xx der Unified-API bis zu dreimal. Zolldaten fuer die Schweiz (P0-3) sind nicht Teil dieses Commits. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
60 lines
1.8 KiB
PHP
60 lines
1.8 KiB
PHP
<?php
|
|
|
|
use App\Http\Controllers\SettingController;
|
|
use App\Services\DhlTrackingService;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
beforeEach(function () {
|
|
$reflection = new ReflectionClass(SettingController::class);
|
|
$property = $reflection->getProperty('cachedDhlConfig');
|
|
$property->setAccessible(true);
|
|
$property->setValue(null, [
|
|
'api_key' => 'cached-test-api-key-1234',
|
|
]);
|
|
});
|
|
|
|
afterEach(function () {
|
|
SettingController::flushDhlConfigCache();
|
|
DhlTrackingService::clearQuotaPause();
|
|
});
|
|
|
|
it('retries a transient server error and returns the successful response', function () {
|
|
Http::fakeSequence()
|
|
->push(['title' => 'Internal Server Error'], 500)
|
|
->push(['shipments' => [[
|
|
'id' => '00340434292135100148',
|
|
'status' => ['statusCode' => 'delivered', 'description' => 'Zugestellt'],
|
|
]]], 200);
|
|
|
|
$result = (new DhlTrackingService)->trackShipment('00340434292135100148');
|
|
|
|
expect($result)->toHaveKey('success', true)
|
|
->and($result['status'])->toBe('delivered');
|
|
|
|
Http::assertSentCount(2);
|
|
});
|
|
|
|
it('gives up after the configured number of attempts and reports the status once', function () {
|
|
Http::fake([
|
|
'api-eu.dhl.com/track/shipments*' => Http::response(['title' => 'Internal Server Error'], 500),
|
|
]);
|
|
|
|
$result = (new DhlTrackingService)->trackShipment('00340434292135100148');
|
|
|
|
expect($result)->toHaveKey('success', false)
|
|
->toHaveKey('http_status', 500);
|
|
|
|
Http::assertSentCount(3);
|
|
});
|
|
|
|
it('does not retry a client error', function () {
|
|
Http::fake([
|
|
'api-eu.dhl.com/track/shipments*' => Http::response(['title' => 'Not Found'], 404),
|
|
]);
|
|
|
|
$result = (new DhlTrackingService)->trackShipment('00340434292135100148');
|
|
|
|
expect($result)->toHaveKey('not_found', true);
|
|
|
|
Http::assertSentCount(1);
|
|
});
|