- Lịch sử thanh toán hoá đơn trả thêm `method` (tự động gia hạn / số dư / admin / chuyển khoản / hoàn tiền), bỏ đuôi `(method)` khỏi ghi chú - `DnsServer::panelUrl()` = https://<domain>/ dùng cho email cấp hosting và nút Plesk của khách - Order item trả thêm `uuid`/`type` của dịch vụ để FE dẫn tới trang quản lý - Yêu cầu huỷ dịch vụ, chứng chỉ SSL, lịch sử gia hạn, đổi mật khẩu hosting cho khách Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
59 lines
2.0 KiB
PHP
59 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\Api\Admin\DnsManager;
|
|
|
|
use App\Models\DnsServer;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Spatie\Permission\Models\Role;
|
|
use Tests\TestCase;
|
|
|
|
class DnsServerDomainTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private function admin(): User
|
|
{
|
|
Role::firstOrCreate(['name' => 'Full Administrator', 'guard_name' => 'admin']);
|
|
$admin = User::factory()->create();
|
|
$admin->assignRole('Full Administrator');
|
|
|
|
return $admin;
|
|
}
|
|
|
|
public function test_public_host_prefers_domain_over_ip(): void
|
|
{
|
|
$server = new DnsServer(['ip_address' => '103.42.58.99', 'domain' => 'host99.tgs.com.vn']);
|
|
$this->assertSame('host99.tgs.com.vn', $server->publicHost());
|
|
|
|
$server->domain = null;
|
|
$this->assertSame('103.42.58.99', $server->publicHost());
|
|
}
|
|
|
|
public function test_panel_url_is_https_on_public_host_without_port_or_script(): void
|
|
{
|
|
$server = new DnsServer(['ip_address' => '103.42.58.99', 'domain' => 'login.tgs.com.vn', 'panel_port' => 8880]);
|
|
|
|
$this->assertSame('https://login.tgs.com.vn/', $server->panelUrl());
|
|
}
|
|
|
|
public function test_store_saves_domain_and_rejects_invalid_hostname(): void
|
|
{
|
|
$admin = $this->admin();
|
|
$payload = ['name' => 'Host 99', 'ip_address' => '103.42.58.99', 'username' => 'root', 'password' => 'secret'];
|
|
|
|
$this->actingAs($admin, 'admin')
|
|
->postJson('/api/v1/administrator/dns-servers', $payload + ['domain' => 'not a domain'])
|
|
->assertStatus(422);
|
|
|
|
$this->actingAs($admin, 'admin')
|
|
->postJson('/api/v1/administrator/dns-servers', $payload + ['domain' => 'host99.tgs.com.vn'])
|
|
->assertStatus(201)
|
|
->assertJsonPath('data.domain', 'host99.tgs.com.vn');
|
|
|
|
$this->assertDatabaseHas('dns_manager_servers', ['ip_address' => '103.42.58.99', 'domain' => 'host99.tgs.com.vn']);
|
|
}
|
|
}
|