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>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
10af41c5cf
commit
c5115b52dd
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Api\Client;
|
||||
|
||||
use App\Models\Customer;
|
||||
use App\Models\DnsDomain;
|
||||
use App\Models\DnsManagerNS;
|
||||
use App\Models\Service;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ClientServiceListTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_customer_can_only_list_their_own_services_across_all_types(): void
|
||||
{
|
||||
$customer = Customer::factory()->create();
|
||||
$otherCustomer = Customer::factory()->create();
|
||||
|
||||
$vps = Service::create([
|
||||
'customer_id' => $customer->id,
|
||||
'type' => 'vps',
|
||||
'server_name' => 'vps.example.vn',
|
||||
'status' => 'active',
|
||||
]);
|
||||
$hosting = Service::create([
|
||||
'customer_id' => $customer->id,
|
||||
'type' => 'hosting',
|
||||
'server_name' => 'hosting.example.vn',
|
||||
'status' => 'cancelled',
|
||||
]);
|
||||
$domain = Service::create([
|
||||
'customer_id' => $customer->id,
|
||||
'type' => 'domain',
|
||||
'server_name' => 'example.vn',
|
||||
'status' => 'active',
|
||||
]);
|
||||
$dnsServerId = DB::table('dns_manager_servers')->insertGetId([
|
||||
'ip_address' => '10.0.0.1',
|
||||
'password' => 'x',
|
||||
]);
|
||||
$dnsDomain = DnsDomain::create([
|
||||
'domain_name' => 'example.vn',
|
||||
'dns_manager_server_id' => $dnsServerId,
|
||||
'is_created' => DnsDomain::STATUS_CREATED,
|
||||
]);
|
||||
$dnsDomain->customer()->attach($customer->id);
|
||||
DnsManagerNS::create([
|
||||
'dns_manager_domain_id' => $dnsDomain->id,
|
||||
'type' => 'A',
|
||||
'type_valid' => 'A',
|
||||
'name' => 'example.vn',
|
||||
'value' => '10.0.0.2',
|
||||
'ttl' => 300,
|
||||
]);
|
||||
Service::create([
|
||||
'customer_id' => $otherCustomer->id,
|
||||
'type' => 'vps',
|
||||
'server_name' => 'private.example.vn',
|
||||
'status' => 'active',
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($customer, 'client')
|
||||
->withHeaders(['x-access-token' => $this->buildClientAccessToken()])
|
||||
->getJson('/v1/client/client-service')
|
||||
->assertOk()
|
||||
->assertJsonPath('error', false)
|
||||
->assertJsonCount(3, 'data.items');
|
||||
|
||||
$items = collect($response->json('data.items'))->keyBy('uuid');
|
||||
|
||||
$this->assertSame('vps', $items[$vps->uuid]['type']);
|
||||
$this->assertSame('hosting', $items[$hosting->uuid]['type']);
|
||||
$this->assertSame(1, $items[$domain->uuid]['dns_records_count']);
|
||||
$this->assertFalse($items->contains('server_name', 'private.example.vn'));
|
||||
|
||||
$this->assertSame(['os', 'specs'], array_values(array_intersect(
|
||||
array_keys($items[$vps->uuid]),
|
||||
['os', 'specs', 'service_plan', 'dns_records_count'],
|
||||
)));
|
||||
$this->assertSame(['service_plan'], array_values(array_intersect(
|
||||
array_keys($items[$hosting->uuid]),
|
||||
['os', 'specs', 'service_plan', 'dns_records_count'],
|
||||
)));
|
||||
$this->assertSame(['dns_records_count'], array_values(array_intersect(
|
||||
array_keys($items[$domain->uuid]),
|
||||
['os', 'specs', 'service_plan', 'dns_records_count'],
|
||||
)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user