mock(PriceCalculatorService::class, function ($mock) { $mock->shouldReceive('calculate') ->once() ->andReturn([ 'total_cost' => 150.00, 'currency' => 'USD', ]); }); // ارسال درخواست معتبر $response = $this->postJson('/api/v1/calculate', [ 'direction' => 'Outbound', 'type' => 'DOC_NORMAL', 'country_iso' => 'US', 'weight' => 2.5, 'volumetric_weight' => 3.0, 'extra_service' => 10.00, ]); // بررسی وضعیت پاسخ و ساختار داده‌ها $response->assertStatus(200) ->assertJson([ 'total_cost' => 150.00, 'currency' => 'USD', ]); } #[Test] public function it_returns_validation_errors_for_invalid_data() { // ارسال درخواست نامعتبر $response = $this->postJson('/api/v1/calculate', [ 'direction' => 'InvalidDirection', 'type' => 'PARCEL', ]); // بررسی دریافت خطای اعتبارسنجی $response->assertStatus(422) ->assertJsonValidationErrors(['country_iso', 'weight', 'volumetric_weight', 'direction']); } }