Files
portal-api/tests/Feature/Api/Admin/CustomerDomainServiceSyncTest.php
T
baodev0andClaude Opus 5.5 c5115b52dd feat: nạp tiền thủ công mã 30 phút, gia hạn trừ số dư, đồng bộ domain từ Plesk
- Nạp tiền: mã thanh toán sống 30 phút (ManualDepositDraft), khôi phục/huỷ mã, lệnh dọn mã hết hạn; total_pending chỉ tính giao dịch đã nộp chứng từ, admin duyệt/từ chối/xoá giao dịch
- Gia hạn dịch vụ: phát hành invoice gia hạn trên order gốc và trừ số dư ngay
- Đồng bộ domain từ Plesk theo server, ServiceOrderRecorder tạo order/invoice cho dịch vụ admin dựng
- Danh sách dịch vụ trả field theo loại (service_plan, dns_records_count), đếm dịch vụ theo loại

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 23:07:51 +07:00

73 lines
2.8 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\Api\Admin;
use App\Models\Customer;
use App\Models\DnsDomain;
use App\Models\DomainPricing;
use App\Models\Product;
use App\Models\Service;
use App\Services\Domain\CustomerDomainServiceSync;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class CustomerDomainServiceSyncTest extends TestCase
{
use RefreshDatabase;
public function test_assign_update_and_detach_keep_domain_service_in_sync(): void
{
$customer = Customer::factory()->create();
$serverId = DB::table('dns_manager_servers')->insertGetId([
'ip_address' => '10.0.0.1',
'password' => 'x',
]);
$domain = DnsDomain::create([
'domain_name' => 'devro-tech.com',
'dns_manager_server_id' => $serverId,
'is_created' => DnsDomain::STATUS_CREATED,
]);
DomainPricing::query()->delete();
DomainPricing::create(['type' => 'domain', 'tld' => '.com', 'setup_fee' => '0', 'first_year' => 320_000, 'recurring_fee' => '340000', 'is_active' => true]);
$product = Product::factory()->create(['product_type' => 'domain', 'is_active' => true]);
$sync = app(CustomerDomainServiceSync::class);
$sync->syncCustomers($domain, [$customer->id]);
$service = Service::query()
->where('customer_id', $customer->id)
->where('type', 'domain')
->where('server_name', 'devro-tech.com')
->firstOrFail();
$this->assertSame('active', $service->status);
$this->assertSame(CustomerDomainServiceSync::AUTO_CREATED_NOTE, $service->note);
$this->assertSame($product->id, $service->product_id);
$this->assertSame('devro-tech.com', $service->orderItem->domain_name);
$this->assertSame(320_000, (int) $service->orderItem->price);
$this->assertSame('annually', $service->orderItem->billing_cycle);
$this->assertSame(1, (int) $service->invoice->status);
$this->assertSame(320_000, (int) $service->invoice->total);
$sync->syncCustomers($domain, [$customer->id]);
$this->assertSame(1, Service::query()->where('customer_id', $customer->id)->count());
$this->assertSame(1, $service->orderItem->order()->count());
$this->assertDatabaseCount('invoices', 1);
$sync->updateCustomerDomain($domain, $customer->id, '2027-07-21');
$this->assertSame('2027-07-21', $service->fresh()->expires_at?->toDateString());
$sync->syncCustomers($domain, []);
$this->assertSoftDeleted('services', ['id' => $service->id]);
$this->assertSame(3, (int) $service->invoice->fresh()->status);
$this->assertDatabaseMissing('dns_domain_user', [
'domain_id' => $domain->id,
'user_id' => $customer->id,
]);
}
}