'profit_margin', 'value' => 1.0]); // بدون سود SystemSetting::create(['key' => 'aed_to_irr', 'value' => 1.0]); // بدون تبدیل ارز SystemSetting::create(['key' => 'vat_rate', 'value' => 0.0]); // بدون مالیات SystemSetting::create(['key' => 'packing_cost_default', 'value' => 0]); // بدون هزینه بسته‌بندی // 2. ایجاد کشور $country = Country::factory()->create([ 'iso_code' => 'US', 'name' => 'United States', 'export_zone_parcel' => 1, 'export_zone_doc' => 1, 'import_zone_parcel' => 1, 'import_zone_doc' => 1, 'is_active' => true, ]); // 3. ایجاد نرخ‌های حمل‌ونقل ShippingRate::create([ 'direction' => 'export', 'type' => 'DOC_NORMAL', 'weight' => 1.0, 'zone_1' => 20.00, 'zone_2' => 0, 'zone_3' => 0, 'zone_4' => 0, 'zone_5' => 0, 'zone_6' => 0, 'zone_7' => 0, 'zone_8' => 0, 'zone_9' => 0, 'zone_10' => 0, ]); ShippingRate::create([ 'direction' => 'export', 'type' => 'DOC_NORMAL', 'weight' => 3.0, 'zone_1' => 40.00, 'zone_2' => 0, 'zone_3' => 0, 'zone_4' => 0, 'zone_5' => 0, 'zone_6' => 0, 'zone_7' => 0, 'zone_8' => 0, 'zone_9' => 0, 'zone_10' => 0, ]); // 4. اجرای سرویس $service = app(PriceCalculatorService::class); $data = [ 'direction' => 'Outbound', // ← توجه: در سرویس به 'export' تبدیل می‌شود 'type' => 'DOC_NORMAL', 'country_iso' => 'US', 'weight' => 2.5, 'volumetric_weight' => 3.0, 'extra_service' => 10.00, 'packing_cost' => 0, // ← اضافه کردن هزینه بسته‌بندی صفر 'domestic_pickup' => 0, 'domestic_delivery' => 0, 'warehousing_cost' => 0, ]; $result = $service->calculate($data); // 5. بررسی ساختار خروجی $this->assertIsArray($result); $this->assertArrayHasKey('total_fee', $result); // ✅ تغییر به total_fee $this->assertArrayHasKey('base_price', $result); // 6. بررسی مقادیر $this->assertEquals(1, $result['zone']); $this->assertEquals(3.0, $result['chargeable_weight']); $this->assertEquals(40.00, $result['base_price']); // محاسبه دستی: // base_price = 40 // net_rial = 40 × 1.0 (profit) × 1.0 (currency) = 40 // extra = 10 // subtotal = 50 // vat = 0 // total_fee = 50 $this->assertEquals(50.00, $result['total_fee']); } }