ifnex/04_Laravel/tests/Feature/Api/PricingControllerTest.php
Kazem Alghasi e1c4385a9c feat(finance): implement Filament admin panel and expand wallet/discount features
Implement a comprehensive financial management suite within the Filament
admin panel, including new resources for payments and discount codes,
along with a financial dashboard.

- feat(ui): add Filament Dashboard with finance overview and transaction
  widgets
- feat(ui): implement PaymentResource for monitoring gateway transactions
- feat(ui): complete DiscountCodeResource with full CRUD and filtering
- feat(wallet): add automatic wallet creation on balance retrieval
- fix(wallet): resolve null handling in isFrozen() and balance viewing
- fix(db): correct enum type from 'percent' to 'percentage' in
  discount_codes migration
- fix(api): update pricing calculation endpoint to /api/v1/calculate
- test: add 21 new feature and service tests covering wallet, payment,
  and discount logic
- chore: remove obsolete PaymentGatewayService and update project status
2026-08-08 03:15:51 +03:30

58 lines
1.8 KiB
PHP

<?php
namespace Tests\Feature\Api;
use App\Services\PriceCalculatorService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class PricingControllerTest extends TestCase
{
#[Test]
public function it_can_calculate_pricing_with_valid_data()
{
// Mock کردن سرویس محاسبه قیمت
$this->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']);
}
}