39 lines
1.2 KiB
PHP
39 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Services\Discounts;
|
|
|
|
use App\Services\Discounts\DiscountApplyService;
|
|
use App\Services\Discounts\DiscountContextService;
|
|
use App\Services\Discounts\DiscountInvoiceService;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Tests\TestCase;
|
|
|
|
class DiscountApplyServiceTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_apply_voucher_returns_error_when_no_remaining_uses(): void
|
|
{
|
|
DB::table('configuration')->insert([
|
|
['id' => 1, 'config_key' => 'school_year', 'config_value' => '2025-2026'],
|
|
['id' => 2, 'config_key' => 'semester', 'config_value' => 'Fall'],
|
|
]);
|
|
|
|
DB::table('discount_vouchers')->insert([
|
|
'id' => 1,
|
|
'code' => 'USED-OUT',
|
|
'discount_type' => 'fixed',
|
|
'discount_value' => 10,
|
|
'max_uses' => 1,
|
|
'times_used' => 1,
|
|
'is_active' => 1,
|
|
]);
|
|
|
|
$service = new DiscountApplyService(new DiscountContextService, new DiscountInvoiceService);
|
|
$result = $service->applyVoucher(1, [10], true, 1);
|
|
|
|
$this->assertFalse($result['ok']);
|
|
}
|
|
}
|