create([ 'order_number' => 'TEST-001', 'customer_name' => 'John Doe', 'customer_email' => 'john@example.com', 'customer_phone' => '+1234567890', 'delivery_street' => '123 Main Street', 'delivery_unit' => 'Apt 5B', 'delivery_city' => 'New York', 'delivery_zone' => 'NY', 'delivery_code' => '10001', 'delivery_country' => 'US', 'packing_length' => 30, 'packing_width' => 20, 'packing_height' => 10, 'packing_weight' => 2.5, 'status' => 'ready_to_ship', ]); // Dispatch the ReadyToShipIntent event to trigger shipment creation // This would normally be triggered by user action in Filament event(new \App\Events\ReadyToShipIntent($order)); // Verify the order now has shipment metadata $order->refresh(); $this->assertNotNull($order->courier_shipment_id); $this->assertNotNull($order->courier_service_level_code); $this->assertNotNull($order->courier_rate); // Verify PDFs were stored $this->assertTrue(\Illuminate\Support\Facades\Storage::exists( "public/shipments/{$order->uuid}/Shipment Label.pdf" )); $this->assertTrue(\Illuminate\Support\Facades\Storage::exists( "public/shipments/{$order->uuid}/Shipment Sticker.pdf" )); } /** * Test that ECO service level is selected when available */ public function test_eco_service_level_selection(): void { ShiplogicMockClient::setup(); $order = Order::factory()->create([ 'order_number' => 'TEST-002', 'customer_name' => 'Jane Smith', 'customer_email' => 'jane@example.com', 'delivery_street' => '456 Oak Ave', 'delivery_city' => 'London', 'delivery_country' => 'GB', 'packing_weight' => 1.5, 'status' => 'ready_to_ship', ]); event(new \App\Events\ReadyToShipIntent($order)); $order->refresh(); // ECO variant should be selected (FEDEX_INTERNATIONAL_ECONOMY) $this->assertStringContainsString('ECONOMY', $order->courier_service_level_code); } }