Extract Ladill Servers as standalone app at servers.ladill.com.
VPS and dedicated server ordering, managed panels, SSO, billing, and launcher integration — forked from hosting infrastructure with server-focused routes and dashboard. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Jobs\ProvisionHostingOrderJob;
|
||||
use App\Models\CustomerHostingOrder;
|
||||
use App\Models\HostedSite;
|
||||
use App\Models\HostingAccount;
|
||||
use App\Models\HostingNode;
|
||||
use App\Models\HostingProduct;
|
||||
use App\Models\ProvisioningQueueItem;
|
||||
use App\Models\User;
|
||||
use App\Services\Hosting\HostingResourcePolicyService;
|
||||
use App\Services\Hosting\NodeCapacityService;
|
||||
use App\Services\Hosting\Providers\ContaboProvider;
|
||||
use App\Services\Hosting\Providers\SharedNodeProvider;
|
||||
use App\Services\Hosting\ServerAgentBootstrapService;
|
||||
use App\Services\Hosting\ServerAgentInstallerService;
|
||||
use App\Services\Hosting\ServerOrderService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ProvisionHostingOrderJobSharedTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_shared_order_provisioning_creates_account_on_a_compatible_node(): void
|
||||
{
|
||||
$user = User::factory()->create([
|
||||
'email' => 'customer@example.com',
|
||||
]);
|
||||
|
||||
$product = HostingProduct::create([
|
||||
'name' => 'Starter Shared',
|
||||
'slug' => 'starter-shared-job-test',
|
||||
'category' => HostingProduct::CATEGORY_SHARED,
|
||||
'type' => HostingProduct::TYPE_SINGLE_DOMAIN,
|
||||
'price_monthly' => 1,
|
||||
'currency' => 'GHS',
|
||||
'disk_gb' => 5,
|
||||
'max_domains' => 1,
|
||||
'is_active' => true,
|
||||
'is_visible' => true,
|
||||
]);
|
||||
|
||||
$starterNode = HostingNode::create($this->nodeAttributes([
|
||||
'name' => 'Starter Node',
|
||||
'hostname' => 'starter-node.local',
|
||||
'ip_address' => '192.0.2.20',
|
||||
'segment' => HostingNode::SEGMENT_STARTER,
|
||||
]));
|
||||
|
||||
HostingNode::create($this->nodeAttributes([
|
||||
'name' => 'High Resource Node',
|
||||
'hostname' => 'pro-node.local',
|
||||
'ip_address' => '192.0.2.21',
|
||||
'segment' => HostingNode::SEGMENT_HIGH_RESOURCE,
|
||||
]));
|
||||
|
||||
$order = CustomerHostingOrder::create([
|
||||
'user_id' => $user->id,
|
||||
'hosting_product_id' => $product->id,
|
||||
'domain_name' => 'starter-example.test',
|
||||
'billing_cycle' => CustomerHostingOrder::CYCLE_MONTHLY,
|
||||
'amount_paid' => 1,
|
||||
'currency' => 'GHS',
|
||||
'status' => CustomerHostingOrder::STATUS_APPROVED,
|
||||
]);
|
||||
|
||||
$sharedProvider = \Mockery::mock(SharedNodeProvider::class);
|
||||
$sharedProvider->shouldReceive('createAccountOnNode')
|
||||
->once()
|
||||
->withArgs(function (HostingNode $node, array $config) use ($starterNode): bool {
|
||||
$this->assertSame($starterNode->id, $node->id);
|
||||
$this->assertSame(5 * 1024, $config['disk_quota_mb']);
|
||||
$this->assertSame('starter-example.test', $config['domain']);
|
||||
|
||||
return true;
|
||||
})
|
||||
->andReturn([
|
||||
'home_directory' => '/home/startacct',
|
||||
'document_root' => '/home/startacct/public_html',
|
||||
]);
|
||||
$sharedProvider->shouldReceive('applyAccountResourceProfile')->once()->andReturn(true);
|
||||
$sharedProvider->shouldReceive('installWordPress')->never();
|
||||
|
||||
(new ProvisionHostingOrderJob($order))->handle(
|
||||
app(NodeCapacityService::class),
|
||||
app(HostingResourcePolicyService::class),
|
||||
$sharedProvider,
|
||||
\Mockery::mock(ContaboProvider::class),
|
||||
\Mockery::mock(ServerOrderService::class),
|
||||
\Mockery::mock(ServerAgentBootstrapService::class),
|
||||
\Mockery::mock(ServerAgentInstallerService::class),
|
||||
);
|
||||
|
||||
$order->refresh();
|
||||
$account = HostingAccount::query()->firstOrFail();
|
||||
$site = HostedSite::query()->firstOrFail();
|
||||
|
||||
$this->assertSame(CustomerHostingOrder::STATUS_ACTIVE, $order->status);
|
||||
$this->assertSame($starterNode->id, $order->hosting_node_id);
|
||||
$this->assertSame($account->id, $order->hosting_account_id);
|
||||
$this->assertSame($product->id, $account->hosting_product_id);
|
||||
$this->assertSame(5, $account->allocated_disk_gb);
|
||||
$this->assertSame('starter-example.test', $account->primary_domain);
|
||||
$this->assertSame('starter-example.test', $site->domain);
|
||||
$this->assertSame('primary', $site->type);
|
||||
$this->assertDatabaseHas('provisioning_queue', [
|
||||
'customer_hosting_order_id' => $order->id,
|
||||
'status' => ProvisioningQueueItem::STATUS_COMPLETED,
|
||||
]);
|
||||
$this->assertSame('starter', data_get($order->meta, 'node_segment'));
|
||||
}
|
||||
|
||||
private function nodeAttributes(array $overrides = []): array
|
||||
{
|
||||
return array_merge([
|
||||
'name' => 'Shared Node',
|
||||
'hostname' => 'shared-node.local',
|
||||
'ip_address' => '192.0.2.15',
|
||||
'type' => HostingNode::TYPE_SHARED,
|
||||
'segment' => HostingNode::SEGMENT_GENERAL,
|
||||
'provider' => HostingNode::PROVIDER_MANUAL,
|
||||
'disk_gb' => 100,
|
||||
'oversell_ratio' => 3,
|
||||
'max_accounts' => 100,
|
||||
'status' => HostingNode::STATUS_ACTIVE,
|
||||
'ssh_port' => '22',
|
||||
], $overrides);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user