mivita/tests/Unit/Dhl/DhlShipmentManualWeightTest.php
Kevin 42ef4dd1c6 DHL-Versand: Sendungs-Info-Button in Bestelllisten & Absenderadresse
Neuer schlanker DHL-Info-Button (getDhlShippingButton) in den Order- und
Shop-Sales-Datatables, oeffnet ein Read-only-Modal (modal_dhl_shipping_info)
mit den Tracking-Daten; dhlShipments wird dafuer eager geladen.
Absenderadresse in config/dhl.php aktualisiert, plus kleinere Fixes in
DhlShipmentController/Service/DataHelper und CreateReturnLabelJob.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-25 13:37:13 +00:00

113 lines
3.6 KiB
PHP

<?php
use App\Http\Controllers\SettingController;
use App\Jobs\CreateShipmentJob;
use App\Models\ShoppingOrder;
use App\Services\DhlDataHelper;
use App\Services\DhlShipmentService;
use App\Services\DhlShipmentWeightCalculator;
use Illuminate\Support\Facades\Bus;
beforeEach(function () {
SettingController::flushDhlConfigCache();
});
afterEach(function () {
SettingController::flushDhlConfigCache();
});
it('uses the manually entered weight for DHL order data even below the calculated order weight', function () {
$orderData = DhlDataHelper::prepareOrderData(
tap(new ShoppingOrder, fn (ShoppingOrder $order) => $order->id = 98765),
0.5,
[
'product_code' => 'V01PAK',
'shipping_address' => [
'firstname' => 'Max',
'lastname' => 'Mustermann',
'company' => '',
'address' => 'Hauptstrasse',
'houseNumber' => '5',
'zipcode' => '10115',
'city' => 'Berlin',
'country' => (object) ['code' => 'DE'],
'email' => 'max@example.com',
'phone' => '+4930123456',
'postnumber' => null,
],
],
[
'default_product' => 'V01PAK',
'label_format' => 'PDF',
'dimensions' => [
'V01PAK' => ['length' => 30, 'width' => 20, 'height' => 10],
'default' => ['length' => 30, 'width' => 20, 'height' => 10],
],
'sender' => [
'company' => 'mivita care gmbh',
'name' => '',
'street' => 'Waldstr.',
'houseNumber' => '3e',
'postalCode' => '86498',
'city' => 'Kettershausen',
'country' => 'DE',
'email' => 'versand@example.com',
'phone' => '+4987654321',
],
]
);
expect($orderData['weight_kg'])->toBe(0.5);
});
it('allows manually entered weights below the calculated order weight within DHL limits', function () {
(new DhlShipmentWeightCalculator)->assertWithinProductLimit(0.5, 'V01PAK');
expect(true)->toBeTrue();
});
it('passes the manually entered weight to the shipment creation job', function () {
Bus::fake();
$reflection = new ReflectionClass(SettingController::class);
$property = $reflection->getProperty('cachedDhlConfig');
$property->setAccessible(true);
$property->setValue(null, [
'use_queue' => true,
'print_only_if_codeable' => false,
'base_url' => 'https://api-eu.dhl.com',
'default_product' => 'V01PAK',
'label_format' => 'PDF',
'dimensions' => [
'V01PAK' => ['length' => 30, 'width' => 20, 'height' => 10],
'default' => ['length' => 30, 'width' => 20, 'height' => 10],
],
'sender' => [
'company' => 'mivita care gmbh',
'street' => 'Waldstr.',
'houseNumber' => '3e',
'postalCode' => '86498',
'city' => 'Kettershausen',
'country' => 'DE',
],
]);
$order = new ShoppingOrder;
$order->id = 12345;
$order->weight = 2500;
$order->exists = true;
$service = new DhlShipmentService;
$result = $service->createShipment($order, 0.5, [
'shipping_address' => [
'country' => (object) ['code' => 'AT'],
],
]);
expect($result['success'])->toBeTrue()
->and($result['queued'])->toBeTrue();
Bus::assertDispatched(CreateShipmentJob::class, function (CreateShipmentJob $job) {
return $job->weight === 0.5;
});
});