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, ]); // ایجاد نرخ‌های حمل‌ونقل مورد نیاز برای تست ShippingRate::factory()->create([ 'direction' => 'export', // اصلاح شد: تطبیق با مقادیر مجاز دیتابیس 'type' => 'DOC_NORMAL', 'weight' => 1.0, 'zone_1' => 20.00, ]); ShippingRate::factory()->create([ 'direction' => 'export', // اصلاح شد: تطبیق با مقادیر مجاز دیتابیس 'type' => 'DOC_NORMAL', 'weight' => 3.0, 'zone_1' => 40.00, ]); $service = app(PriceCalculatorService::class); $data = [ 'direction' => 'export', 'type' => 'DOC_NORMAL', // اصلاح شد: تطبیق با مقادیر مجاز ShipmentType Enum 'country_iso' => 'US', 'weight' => 2.5, 'volumetric_weight' => 3.0, 'extra_service' => 10.00, ]; $result = $service->calculate($data); $this->assertIsArray($result); $this->assertArrayHasKey('total_cost', $result); $this->assertArrayHasKey('currency', $result); // بررسی مقدار محاسبه شده // وزن حجمی (3.0) بیشتر از وزن واقعی (2.5) است، بنابراین باید از وزن حجمی استفاده شود // نزدیک‌ترین نرخ برای وزن 3.0، نرخ 40.00 است // هزینه کل = نرخ حمل (40.00) + خدمات اضافی (10.00) = 50.00 $this->assertEquals(50.00, $result['total_cost']); } }