27-05-2026 Update DHL Modul v2.0
This commit is contained in:
parent
53bdba33cd
commit
036595be94
41 changed files with 3346 additions and 310 deletions
96
tests/Unit/Dhl/DhlShipmentStatusTest.php
Normal file
96
tests/Unit/Dhl/DhlShipmentStatusTest.php
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
|
||||
use Acme\Dhl\Models\DhlShipment;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Services\DhlTrackingService;
|
||||
|
||||
it('normalizes legacy cancelled status to internal canceled status', function () {
|
||||
expect(DhlShipment::normalizeStatus('cancelled'))->toBe('canceled')
|
||||
->and(DhlShipment::normalizeStatus('canceled'))->toBe('canceled');
|
||||
});
|
||||
|
||||
it('translates canceled and legacy cancelled shipments consistently', function () {
|
||||
app()->setLocale('de');
|
||||
|
||||
$canceledShipment = new DhlShipment(['status' => 'canceled']);
|
||||
$legacyShipment = new DhlShipment(['status' => 'cancelled']);
|
||||
|
||||
expect($canceledShipment->getStatusTranslation())->toBe('Storniert')
|
||||
->and($legacyShipment->getStatusTranslation())->toBe('Storniert')
|
||||
->and($canceledShipment->getStatusBadgeClass())->toBe('warning')
|
||||
->and($legacyShipment->getStatusBadgeClass())->toBe('warning');
|
||||
});
|
||||
|
||||
it('returns tracking email history with latest entries first', function () {
|
||||
$shipment = new DhlShipment([
|
||||
'api_response_data' => [
|
||||
'tracking_email_history' => [
|
||||
[
|
||||
'sent_at' => '2026-05-27T08:00:00+00:00',
|
||||
'type' => 'auto',
|
||||
'status' => 'in_transit',
|
||||
'recipient_email' => 'first@example.test',
|
||||
],
|
||||
[
|
||||
'sent_at' => '2026-05-27T09:00:00+00:00',
|
||||
'type' => 'manual',
|
||||
'status' => 'out_for_delivery',
|
||||
'recipient_email' => 'second@example.test',
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$history = $shipment->getTrackingEmailHistory();
|
||||
|
||||
expect($history)->toHaveCount(2)
|
||||
->and($history[0]['recipient_email'])->toBe('second@example.test')
|
||||
->and($history[0]['status'])->toBe('out_for_delivery')
|
||||
->and(DhlShipment::getStatusBadgeClassFor($history[0]['status']))->toBe('primary');
|
||||
});
|
||||
|
||||
it('returns empty tracking email history for legacy shipments without history', function () {
|
||||
$shipment = new DhlShipment(['api_response_data' => ['items' => []]]);
|
||||
|
||||
expect($shipment->getTrackingEmailHistory())->toBe([]);
|
||||
});
|
||||
|
||||
it('triggers tracking emails for relevant status changes only once', function () {
|
||||
$order = new ShoppingOrder;
|
||||
|
||||
$shipment = new DhlShipment([
|
||||
'status' => 'out_for_delivery',
|
||||
'dhl_shipment_no' => '00340435065133',
|
||||
'email' => 'customer@example.test',
|
||||
]);
|
||||
$shipment->setRelation('shoppingOrder', $order);
|
||||
|
||||
expect($shipment->shouldTriggerTrackingEmail('created'))->toBeTrue()
|
||||
->and($shipment->shouldTriggerTrackingEmail('out_for_delivery'))->toBeFalse();
|
||||
|
||||
$shipment->tracking_email_sent_at = now();
|
||||
|
||||
expect($shipment->shouldTriggerTrackingEmail('created'))->toBeFalse();
|
||||
});
|
||||
|
||||
it('does not trigger tracking emails for terminal delivered status', function () {
|
||||
$order = new ShoppingOrder;
|
||||
|
||||
$shipment = new DhlShipment([
|
||||
'status' => 'delivered',
|
||||
'dhl_shipment_no' => '00340435065133',
|
||||
'email' => 'customer@example.test',
|
||||
]);
|
||||
$shipment->setRelation('shoppingOrder', $order);
|
||||
|
||||
expect($shipment->shouldTriggerTrackingEmail('in_transit'))->toBeFalse();
|
||||
});
|
||||
|
||||
it('maps DHL status variants to internal tracking statuses', function (string $dhlStatus, string $internalStatus) {
|
||||
expect(DhlTrackingService::mapDhlStatusToInternal($dhlStatus))->toBe($internalStatus);
|
||||
})->with([
|
||||
'transit' => ['transit', 'in_transit'],
|
||||
'in-transit' => ['in-transit', 'in_transit'],
|
||||
'out-for-delivery' => ['out-for-delivery', 'out_for_delivery'],
|
||||
'out_for_delivery' => ['out_for_delivery', 'out_for_delivery'],
|
||||
]);
|
||||
Loading…
Add table
Add a link
Reference in a new issue