feat(admin): improve payments and server settings
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?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_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']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user