Files
portal-api/tests/Feature/Jobs/ProvisionHostingAccountJobTest.php
baodev0andClaude Sonnet 5.5 55a834a2f8 feat: nhắc gia hạn QR theo dịch vụ, failover server hosting, CCCD admin, log cấp phát dịch vụ
- Mail campaign: mẫu nhắc gia hạn thanh toán QR, chọn dịch vụ + chu kỳ từng dòng (renewal_services)
- Hosting: nhiều server Plesk cho một gói (service_plan_servers), chuyển server khi server chết
- Admin xem/sửa giấy tờ định danh khách, tuỳ chọn gia hạn cho khách, nhật ký cấp phát dịch vụ
- Đánh dấu mẫu email dịch vụ là non-marketing

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 18:36:41 +07:00

83 lines
2.8 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\Jobs;
use App\Enums\Invoice\InvoiceStatus;
use App\Enums\Order\OrderStatus;
use App\Jobs\Hosting\ProvisionHostingAccountJob;
use App\Jobs\Mail\Customer\VMCreationFailedJob;
use App\Models\Customer;
use App\Models\Invoice;
use App\Models\Order;
use App\Models\OrderItem;
use App\Models\Product;
use App\Models\Service;
use App\Services\InvoicePaymentService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;
class ProvisionHostingAccountJobTest extends TestCase
{
use RefreshDatabase;
public function test_failed_provisioning_marks_service_failed_and_refunds_the_customer(): void
{
Bus::fake([VMCreationFailedJob::class]);
Http::fake();
$customer = Customer::factory()->create(['total' => 500_000]);
$product = Product::factory()->create(['product_type' => 'hosting', 'service_plan_id' => null]);
$order = Order::create([
'order_num' => 'ORD-' . uniqid(),
'customer_id' => $customer->id,
'sub_total' => 200_000,
'total' => 200_000,
'status' => OrderStatus::PENDING->value,
]);
$item = OrderItem::create([
'order_id' => $order->id,
'product_id' => $product->id,
'billing_cycle' => 'monthly',
'months' => 1,
'server_name' => 'khach-hang.test',
'quantity' => 1,
'price' => 200_000,
]);
$invoice = Invoice::create([
'invoice_number' => 'INV-' . uniqid(),
'customer_id' => $customer->id,
'order_id' => $order->id,
'invoice_type' => 1,
'sub_total' => 200_000,
'tax' => 0,
'total' => 200_000,
'status' => InvoiceStatus::UNPAID->value,
]);
$service = Service::create([
'customer_id' => $customer->id,
'product_id' => $product->id,
'order_item_id' => $item->id,
'invoice_id' => $invoice->id,
'server_name' => 'khach-hang.test',
'status' => 'pending',
'started_at' => now(),
'expires_at' => now()->addMonth(),
]);
app(InvoicePaymentService::class)->payWithBalance($invoice, $customer, 'balance');
$this->assertSame(300_000, (int) $customer->fresh()->total);
dispatch_sync(new ProvisionHostingAccountJob($item->fresh()));
$this->assertSame('failed', $service->fresh()->status);
$this->assertSame(500_000, (int) $customer->fresh()->total);
$this->assertSame(InvoiceStatus::REFUNDED->value, (int) $invoice->fresh()->status);
$this->assertSame(OrderStatus::CANCELLED->value, $order->fresh()->status);
Bus::assertDispatched(VMCreationFailedJob::class);
}
}