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); } }