|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
|
|
|
|
|
|
|
|
|
use App\Services\Cloud\CloudInvoicePageService;
|
|
|
|
|
use App\Services\Cloud\CloudInvoiceService;
|
|
|
|
|
use App\Services\Config;
|
|
|
|
|
use App\Models\CloudInvoice;
|
|
|
|
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
|
|
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
|
|
|
|
|
|
|
|
$assert = static function (bool $condition, string $message): void {
|
|
|
|
|
if (!$condition) {
|
|
|
|
|
throw new RuntimeException($message);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$capsule = new Capsule();
|
|
|
|
|
$capsule->addConnection(['driver' => 'sqlite', 'database' => ':memory:'], 'default');
|
|
|
|
|
$capsule->setAsGlobal();
|
|
|
|
|
$capsule->bootEloquent();
|
|
|
|
|
$schema = $capsule->schema('default');
|
|
|
|
|
$schema->create('cloud_instances', static function (Blueprint $table): void {
|
|
|
|
|
$table->increments('id');
|
|
|
|
|
$table->integer('user_id');
|
|
|
|
|
$table->string('name');
|
|
|
|
|
$table->string('status');
|
|
|
|
|
$table->string('service_status')->default('active');
|
|
|
|
|
$table->text('spec_json')->default('{}');
|
|
|
|
|
});
|
|
|
|
|
$schema->create('cloud_jobs', static function (Blueprint $table): void {
|
|
|
|
|
$table->increments('id');
|
|
|
|
|
$table->string('operation_id')->nullable();
|
|
|
|
|
$table->string('request_idempotency_key')->nullable();
|
|
|
|
|
$table->string('request_fingerprint')->nullable();
|
|
|
|
|
$table->integer('order_id')->nullable();
|
|
|
|
|
$table->integer('invoice_id')->nullable();
|
|
|
|
|
$table->integer('instance_id')->nullable();
|
|
|
|
|
$table->integer('user_id');
|
|
|
|
|
$table->integer('host_id')->nullable();
|
|
|
|
|
$table->string('kind');
|
|
|
|
|
$table->string('execution_mode')->default('agent');
|
|
|
|
|
$table->string('phase');
|
|
|
|
|
$table->string('outcome')->nullable();
|
|
|
|
|
$table->string('status')->default('queued');
|
|
|
|
|
$table->integer('attempts')->default(0);
|
|
|
|
|
$table->integer('dispatch_deadline_at')->default(0);
|
|
|
|
|
$table->integer('dispatch_started_at')->nullable();
|
|
|
|
|
$table->integer('agent_accepted_at')->nullable();
|
|
|
|
|
$table->integer('receipt_deadline_at')->nullable();
|
|
|
|
|
$table->integer('terminal_at')->nullable();
|
|
|
|
|
$table->integer('dispatched_at')->nullable();
|
|
|
|
|
$table->integer('updated_at')->default(0);
|
|
|
|
|
$table->string('error_code')->nullable();
|
|
|
|
|
$table->boolean('effect_may_have_applied')->nullable();
|
|
|
|
|
$table->boolean('safe_to_resubmit')->nullable();
|
|
|
|
|
$table->text('result_json')->nullable();
|
|
|
|
|
$table->string('effect_resolution')->default('not_applicable');
|
|
|
|
|
$table->integer('dispatch_attempts')->default(0);
|
|
|
|
|
$table->boolean('finalization_incident')->default(false);
|
|
|
|
|
$table->string('finalization_error_code')->nullable();
|
|
|
|
|
$table->string('completion_event_id')->nullable();
|
|
|
|
|
$table->text('sealed_payload')->nullable();
|
|
|
|
|
});
|
|
|
|
|
$schema->create('cloud_invoices', static function (Blueprint $table): void {
|
|
|
|
|
$table->increments('id');
|
|
|
|
|
$table->string('purpose');
|
|
|
|
|
$table->integer('instance_id')->nullable();
|
|
|
|
|
$table->integer('order_id')->nullable();
|
|
|
|
|
$table->integer('user_id');
|
|
|
|
|
$table->integer('renews_expires_at')->nullable();
|
|
|
|
|
$table->integer('due_at');
|
|
|
|
|
$table->string('amount');
|
|
|
|
|
$table->string('currency')->default('USD');
|
|
|
|
|
$table->string('status');
|
|
|
|
|
$table->integer('validity_days')->default(30);
|
|
|
|
|
$table->integer('traffic_quota_bytes')->default(0);
|
|
|
|
|
$table->string('paid_via')->nullable();
|
|
|
|
|
$table->integer('paid_at')->nullable();
|
|
|
|
|
$table->integer('created_at');
|
|
|
|
|
});
|
|
|
|
|
$schema->create('cloud_invoice_items', static function (Blueprint $table): void {
|
|
|
|
|
$table->increments('id');
|
|
|
|
|
$table->integer('invoice_id');
|
|
|
|
|
$table->integer('order_item_id')->nullable();
|
|
|
|
|
$table->string('code');
|
|
|
|
|
$table->string('label');
|
|
|
|
|
$table->string('amount');
|
|
|
|
|
$table->string('currency')->default('USD');
|
|
|
|
|
$table->text('snapshot_json');
|
|
|
|
|
$table->integer('created_at');
|
|
|
|
|
});
|
|
|
|
|
Config::set('timeZone', 'Asia/Shanghai');
|
|
|
|
|
|
|
|
|
|
$now = time();
|
|
|
|
|
$expiry = $now + 3600;
|
|
|
|
|
Capsule::table('cloud_instances')->insert([
|
|
|
|
|
['id' => 1, 'user_id' => 1, 'name' => 'customer-api', 'status' => 'active'],
|
|
|
|
|
['id' => 2, 'user_id' => 2, 'name' => 'foreign-vm', 'status' => 'active'],
|
|
|
|
|
['id' => 3, 'user_id' => 1, 'name' => 'edge-search-vm', 'status' => 'active'],
|
|
|
|
|
['id' => 4, 'user_id' => 2, 'name' => 'edge-search-vm', 'status' => 'active'],
|
|
|
|
|
]);
|
|
|
|
|
Capsule::table('cloud_invoices')->insert([
|
|
|
|
|
'id' => 1,
|
|
|
|
|
'purpose' => 'renewal',
|
|
|
|
|
'instance_id' => 1,
|
|
|
|
|
'order_id' => null,
|
|
|
|
|
'user_id' => 1,
|
|
|
|
|
'renews_expires_at' => $expiry,
|
|
|
|
|
'due_at' => $expiry,
|
|
|
|
|
'amount' => '10.00',
|
|
|
|
|
'status' => 'paid',
|
|
|
|
|
'created_at' => $now - 100,
|
|
|
|
|
]);
|
|
|
|
|
Capsule::table('cloud_invoices')->insert([
|
|
|
|
|
'id' => 2,
|
|
|
|
|
'purpose' => 'renewal',
|
|
|
|
|
'instance_id' => 2,
|
|
|
|
|
'order_id' => null,
|
|
|
|
|
'user_id' => 2,
|
|
|
|
|
'renews_expires_at' => $expiry,
|
|
|
|
|
'due_at' => $expiry,
|
|
|
|
|
'amount' => '20.00',
|
|
|
|
|
'status' => 'open',
|
|
|
|
|
'created_at' => $now - 99,
|
|
|
|
|
]);
|
|
|
|
|
Capsule::table('cloud_invoices')->insert([
|
|
|
|
|
'id' => 3,
|
|
|
|
|
'purpose' => 'upgrade',
|
|
|
|
|
'instance_id' => 1,
|
|
|
|
|
'order_id' => null,
|
|
|
|
|
'user_id' => 1,
|
|
|
|
|
'renews_expires_at' => null,
|
|
|
|
|
'due_at' => $now,
|
|
|
|
|
'amount' => '5.00',
|
|
|
|
|
'status' => 'paid',
|
|
|
|
|
'created_at' => $now + 100,
|
|
|
|
|
]);
|
|
|
|
|
Capsule::table('cloud_jobs')->insert([
|
|
|
|
|
'id' => 3,
|
|
|
|
|
'order_id' => null,
|
|
|
|
|
'invoice_id' => 3,
|
|
|
|
|
'instance_id' => 1,
|
|
|
|
|
'user_id' => 1,
|
|
|
|
|
'kind' => 'instance_upgrade',
|
|
|
|
|
'phase' => 'accepted',
|
|
|
|
|
'outcome' => null,
|
|
|
|
|
'effect_resolution' => 'not_applicable',
|
|
|
|
|
]);
|
|
|
|
|
Capsule::table('cloud_invoices')->insert([
|
|
|
|
|
'id' => 50,
|
|
|
|
|
'purpose' => 'backup_addon',
|
|
|
|
|
'instance_id' => 1,
|
|
|
|
|
'order_id' => null,
|
|
|
|
|
'user_id' => 1,
|
|
|
|
|
'renews_expires_at' => null,
|
|
|
|
|
'due_at' => $now,
|
|
|
|
|
'amount' => '2.50',
|
|
|
|
|
'status' => 'paid',
|
|
|
|
|
'paid_via' => 'balance',
|
|
|
|
|
'paid_at' => $now,
|
|
|
|
|
'created_at' => $now + 200,
|
|
|
|
|
]);
|
|
|
|
|
for ($number = 0; $number < 12; $number++) {
|
|
|
|
|
Capsule::table('cloud_invoices')->insert([
|
|
|
|
|
'purpose' => 'ip_change',
|
|
|
|
|
'instance_id' => null,
|
|
|
|
|
'order_id' => null,
|
|
|
|
|
'user_id' => 1,
|
|
|
|
|
'renews_expires_at' => null,
|
|
|
|
|
'due_at' => $now + $number,
|
|
|
|
|
'amount' => '1.00',
|
|
|
|
|
'status' => 'paid',
|
|
|
|
|
'created_at' => $now + $number,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$all = CloudInvoicePageService::forUser(1);
|
|
|
|
|
$assert($all['purpose'] === 'all'
|
|
|
|
|
&& $all['pagination']['total'] === 15
|
|
|
|
|
&& $all['pagination']['per_page'] === 25
|
|
|
|
|
&& count($all['invoices']) === 15
|
|
|
|
|
&& in_array('1', array_column($all['invoices'], 'id'), true),
|
|
|
|
|
'The default all-invoice view did not include every owner bill within the bounded page.');
|
|
|
|
|
|
|
|
|
|
$renewals = CloudInvoicePageService::forUser(1, 1, 10, 'renewal');
|
|
|
|
|
$invoice = $renewals['invoices'][0] ?? [];
|
|
|
|
|
$assert($renewals['purpose'] === 'renewal'
|
|
|
|
|
&& $renewals['pagination']['total'] === 1
|
|
|
|
|
&& count($renewals['invoices']) === 1
|
|
|
|
|
&& ($invoice['id'] ?? null) === '1'
|
|
|
|
|
&& ($invoice['purpose'] ?? null) === 'renewal'
|
|
|
|
|
&& ($invoice['renews_expires_at'] ?? null) === $expiry
|
|
|
|
|
&& ($invoice['payment_deadline_at'] ?? null)
|
|
|
|
|
=== $expiry + CloudInvoiceService::PAYMENT_GRACE_SECONDS,
|
|
|
|
|
'The user renewal filter hid the owner invoice or returned the wrong fixed deadline.');
|
|
|
|
|
$upgrades = CloudInvoicePageService::forUser(1, 1, 10, 'upgrade');
|
|
|
|
|
$upgrade = $upgrades['invoices'][0] ?? [];
|
|
|
|
|
$assert($upgrades['purpose'] === 'upgrade'
|
|
|
|
|
&& $upgrades['pagination']['total'] === 1
|
|
|
|
|
&& ($upgrade['title'] ?? null) === '实例升级'
|
|
|
|
|
&& ($upgrade['instance_id'] ?? null) === '1'
|
|
|
|
|
&& ($upgrade['instance_name'] ?? null) === 'customer-api'
|
|
|
|
|
&& ($upgrade['task_id'] ?? null) === '3'
|
|
|
|
|
&& ($upgrade['job_status'] ?? null) === 'active'
|
|
|
|
|
&& ($upgrade['fulfillment_status'] ?? null) === 'active',
|
|
|
|
|
'Upgrade invoices did not expose their target instance and invoice-linked task state.');
|
|
|
|
|
$upgradeInvoice = CloudInvoice::find(3);
|
|
|
|
|
$upgradeStatus = CloudInvoiceService::status($upgradeInvoice);
|
|
|
|
|
$upgradeDetail = CloudInvoiceService::display($upgradeInvoice);
|
|
|
|
|
$assert(($upgradeStatus['payable'] ?? null) === false
|
|
|
|
|
&& ($upgradeStatus['instance_id'] ?? null) === '1'
|
|
|
|
|
&& ($upgradeStatus['task_id'] ?? null) === '3'
|
|
|
|
|
&& ($upgradeStatus['job_status'] ?? null) === 'active'
|
|
|
|
|
&& ($upgradeDetail['title'] ?? null) === '实例升级'
|
|
|
|
|
&& ($upgradeDetail['instance_name'] ?? null) === 'customer-api'
|
|
|
|
|
&& ($upgradeDetail['task_id'] ?? null) === '3'
|
|
|
|
|
&& ($upgradeDetail['payable'] ?? null) === false
|
|
|
|
|
&& array_key_exists('payment_deadline_at', $upgradeDetail)
|
|
|
|
|
&& $upgradeDetail['payment_deadline_at'] === null,
|
|
|
|
|
'Upgrade invoice detail or polling lost its target, task link, or non-payable state.');
|
|
|
|
|
|
|
|
|
|
$backupAddons = CloudInvoicePageService::forUser(
|
|
|
|
|
1,
|
|
|
|
|
1,
|
|
|
|
|
10,
|
|
|
|
|
'backup_addon'
|
|
|
|
|
);
|
|
|
|
|
$backupAddon = $backupAddons['invoices'][0] ?? [];
|
|
|
|
|
$backupInvoice = CloudInvoice::find(50);
|
|
|
|
|
$backupStatus = CloudInvoiceService::status($backupInvoice);
|
|
|
|
|
$backupDetail = CloudInvoiceService::display($backupInvoice);
|
|
|
|
|
$assert($backupAddons['purpose'] === 'backup_addon'
|
|
|
|
|
&& $backupAddons['pagination']['total'] === 1
|
|
|
|
|
&& ($backupAddon['title'] ?? null) === '自动备份开通'
|
|
|
|
|
&& ($backupAddon['instance_id'] ?? null) === '1'
|
|
|
|
|
&& ($backupAddon['instance_name'] ?? null) === 'customer-api'
|
|
|
|
|
&& ($backupStatus['payable'] ?? null) === false
|
|
|
|
|
&& ($backupStatus['instance_id'] ?? null) === '1'
|
|
|
|
|
&& ($backupDetail['title'] ?? null) === '自动备份开通'
|
|
|
|
|
&& ($backupDetail['instance_id'] ?? null) === '1'
|
|
|
|
|
&& ($backupDetail['instance_name'] ?? null) === 'customer-api'
|
|
|
|
|
&& ($backupDetail['payable'] ?? null) === false,
|
|
|
|
|
'Automatic-backup add-on bills were hidden, payable, or detached from their instance.');
|
|
|
|
|
|
|
|
|
|
Capsule::table('cloud_jobs')->where('id', 3)->update([
|
|
|
|
|
'phase' => 'terminal',
|
|
|
|
|
'outcome' => 'failed',
|
|
|
|
|
'effect_resolution' => 'unknown',
|
|
|
|
|
]);
|
|
|
|
|
$unknownStatus = CloudInvoiceService::status($upgradeInvoice);
|
|
|
|
|
$assert($unknownStatus['job_status'] === 'active'
|
|
|
|
|
&& $unknownStatus['job_completed'] === false,
|
|
|
|
|
'Unknown upgrade effect was presented as a completed failure.');
|
|
|
|
|
Capsule::table('cloud_jobs')->where('id', 3)->update([
|
|
|
|
|
'effect_resolution' => 'applied',
|
|
|
|
|
]);
|
|
|
|
|
$appliedStatus = CloudInvoiceService::status($upgradeInvoice);
|
|
|
|
|
$assert($appliedStatus['job_status'] === 'succeeded'
|
|
|
|
|
&& $appliedStatus['job_completed'] === true,
|
|
|
|
|
'Recovered applied upgrade was not presented as fulfilled.');
|
|
|
|
|
|
|
|
|
|
$filterCreatedAt = gmmktime(12, 0, 0, 10, 20, 2026);
|
|
|
|
|
for ($number = 0; $number < 32; $number++) {
|
|
|
|
|
Capsule::table('cloud_invoices')->insert([
|
|
|
|
|
'id' => 100 + $number,
|
|
|
|
|
'purpose' => 'ip_change',
|
|
|
|
|
'instance_id' => 3,
|
|
|
|
|
'order_id' => null,
|
|
|
|
|
'user_id' => 1,
|
|
|
|
|
'renews_expires_at' => null,
|
|
|
|
|
'due_at' => $filterCreatedAt,
|
|
|
|
|
'amount' => '1.00',
|
|
|
|
|
'status' => $number < 16 ? 'open' : 'paid',
|
|
|
|
|
'created_at' => $filterCreatedAt,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
Capsule::table('cloud_invoices')->insert([
|
|
|
|
|
'id' => 200,
|
|
|
|
|
'purpose' => 'ip_change',
|
|
|
|
|
'instance_id' => 4,
|
|
|
|
|
'order_id' => null,
|
|
|
|
|
'user_id' => 2,
|
|
|
|
|
'renews_expires_at' => null,
|
|
|
|
|
'due_at' => $filterCreatedAt,
|
|
|
|
|
'amount' => '9.00',
|
|
|
|
|
'status' => 'open',
|
|
|
|
|
'created_at' => $filterCreatedAt,
|
|
|
|
|
]);
|
|
|
|
|
Capsule::table('cloud_invoices')->insert([
|
|
|
|
|
[
|
|
|
|
|
'id' => 201,
|
|
|
|
|
'purpose' => 'ip_change',
|
|
|
|
|
'instance_id' => 3,
|
|
|
|
|
'order_id' => null,
|
|
|
|
|
'user_id' => 1,
|
|
|
|
|
'renews_expires_at' => null,
|
|
|
|
|
'due_at' => $filterCreatedAt,
|
|
|
|
|
'amount' => '1.00',
|
|
|
|
|
'status' => 'paid',
|
|
|
|
|
'created_at' => gmmktime(16, 30, 0, 10, 19, 2026),
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'id' => 202,
|
|
|
|
|
'purpose' => 'ip_change',
|
|
|
|
|
'instance_id' => 3,
|
|
|
|
|
'order_id' => null,
|
|
|
|
|
'user_id' => 1,
|
|
|
|
|
'renews_expires_at' => null,
|
|
|
|
|
'due_at' => $filterCreatedAt,
|
|
|
|
|
'amount' => '1.00',
|
|
|
|
|
'status' => 'paid',
|
|
|
|
|
'created_at' => gmmktime(16, 30, 0, 10, 20, 2026),
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'id' => 203,
|
|
|
|
|
'purpose' => 'renewal',
|
|
|
|
|
'instance_id' => 3,
|
|
|
|
|
'order_id' => null,
|
|
|
|
|
'user_id' => 1,
|
|
|
|
|
'renews_expires_at' => $now - 4 * 86400,
|
|
|
|
|
'due_at' => $now - 4 * 86400,
|
|
|
|
|
'amount' => '10.00',
|
|
|
|
|
'status' => 'overdue',
|
|
|
|
|
'created_at' => $filterCreatedAt,
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'id' => 204,
|
|
|
|
|
'purpose' => 'renewal',
|
|
|
|
|
'instance_id' => 4,
|
|
|
|
|
'order_id' => null,
|
|
|
|
|
'user_id' => 1,
|
|
|
|
|
'renews_expires_at' => $now + 3600,
|
|
|
|
|
'due_at' => $now + 3600,
|
|
|
|
|
'amount' => '10.00',
|
|
|
|
|
'status' => 'open',
|
|
|
|
|
'created_at' => $filterCreatedAt,
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'id' => 205,
|
|
|
|
|
'purpose' => 'renewal',
|
|
|
|
|
'instance_id' => 3,
|
|
|
|
|
'order_id' => null,
|
|
|
|
|
'user_id' => 1,
|
|
|
|
|
'renews_expires_at' => $now + 3600,
|
|
|
|
|
'due_at' => $now + 3600,
|
|
|
|
|
'amount' => '10.00',
|
|
|
|
|
'status' => 'open',
|
|
|
|
|
'created_at' => $filterCreatedAt,
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
$combined = CloudInvoicePageService::queryForUser(1, [
|
|
|
|
|
'purpose' => 'ip_change',
|
|
|
|
|
'status' => 'pending',
|
|
|
|
|
'keyword' => 'edge-search-vm',
|
|
|
|
|
'date_from' => '2026-10-20',
|
|
|
|
|
'date_to' => '2026-10-20',
|
|
|
|
|
]);
|
|
|
|
|
$assert($combined['pagination']['total'] === 16
|
|
|
|
|
&& count($combined['invoices']) === 16
|
|
|
|
|
&& !in_array('200', array_column($combined['invoices'], 'id'), true)
|
|
|
|
|
&& ($combined['filters']['status'] ?? null) === 'pending'
|
|
|
|
|
&& ($combined['filters']['keyword'] ?? null) === 'edge-search-vm',
|
|
|
|
|
'Combined invoice filters escaped owner scope or changed normalized input.');
|
|
|
|
|
$localDate = CloudInvoicePageService::queryForUser(1, [
|
|
|
|
|
'purpose' => 'ip_change',
|
|
|
|
|
'status' => 'paid',
|
|
|
|
|
'date_from' => '2026-10-20',
|
|
|
|
|
'date_to' => '2026-10-20',
|
|
|
|
|
]);
|
|
|
|
|
$localDateIds = array_column($localDate['invoices'], 'id');
|
|
|
|
|
$assert(in_array('201', $localDateIds, true)
|
|
|
|
|
&& !in_array('202', $localDateIds, true),
|
|
|
|
|
'Invoice date filtering ignored the configured site timezone boundary.');
|
|
|
|
|
$pendingRenewals = CloudInvoicePageService::queryForUser(1, [
|
|
|
|
|
'purpose' => 'renewal',
|
|
|
|
|
'status' => 'pending',
|
|
|
|
|
]);
|
|
|
|
|
$closedRenewals = CloudInvoicePageService::queryForUser(1, [
|
|
|
|
|
'purpose' => 'renewal',
|
|
|
|
|
'status' => 'closed',
|
|
|
|
|
]);
|
|
|
|
|
$pendingRenewalIds = array_column($pendingRenewals['invoices'], 'id');
|
|
|
|
|
$closedRenewalIds = array_column($closedRenewals['invoices'], 'id');
|
|
|
|
|
$assert(in_array('205', $pendingRenewalIds, true)
|
|
|
|
|
&& !in_array('203', $pendingRenewalIds, true)
|
|
|
|
|
&& !in_array('204', $pendingRenewalIds, true)
|
|
|
|
|
&& in_array('203', $closedRenewalIds, true)
|
|
|
|
|
&& in_array('204', $closedRenewalIds, true),
|
|
|
|
|
'Invoice status filtering drifted from renewal expiry or target visibility.');
|
|
|
|
|
$idMatch = CloudInvoicePageService::queryForUser(1, [
|
|
|
|
|
'keyword' => '105',
|
|
|
|
|
]);
|
|
|
|
|
$assert($idMatch['pagination']['total'] === 1
|
|
|
|
|
&& ($idMatch['invoices'][0]['id'] ?? null) === '105',
|
|
|
|
|
'A numeric invoice search did not resolve the exact owner invoice ID.');
|
|
|
|
|
$firstPage = CloudInvoicePageService::queryForUser(1, [
|
|
|
|
|
'purpose' => 'ip_change',
|
|
|
|
|
'page' => '1',
|
|
|
|
|
]);
|
|
|
|
|
$secondPage = CloudInvoicePageService::queryForUser(1, [
|
|
|
|
|
'purpose' => 'ip_change',
|
|
|
|
|
'page' => '2',
|
|
|
|
|
]);
|
|
|
|
|
$firstIds = array_column($firstPage['invoices'], 'id');
|
|
|
|
|
$secondIds = array_column($secondPage['invoices'], 'id');
|
|
|
|
|
$assert($firstPage['pagination']['per_page'] === 25
|
|
|
|
|
&& count($firstIds) === 25
|
|
|
|
|
&& $secondIds !== []
|
|
|
|
|
&& array_intersect($firstIds, $secondIds) === [],
|
|
|
|
|
'Stable invoice pagination repeated or dropped records at one timestamp.');
|
|
|
|
|
$invalidFilters = CloudInvoicePageService::normalizeQuery([
|
|
|
|
|
'page' => ['2'],
|
|
|
|
|
'purpose' => ['renewal'],
|
|
|
|
|
'status' => ['paid'],
|
|
|
|
|
'keyword' => str_repeat('x', 300),
|
|
|
|
|
'date_from' => ['2026-10-20'],
|
|
|
|
|
'date_to' => new stdClass(),
|
|
|
|
|
]);
|
|
|
|
|
$assert($invalidFilters === [
|
|
|
|
|
'page' => 1,
|
|
|
|
|
'purpose' => 'all',
|
|
|
|
|
'status' => 'all',
|
|
|
|
|
'keyword' => '',
|
|
|
|
|
'date_from' => '',
|
|
|
|
|
'date_to' => '',
|
|
|
|
|
], 'Structured or oversized invoice filters were not rejected safely.');
|
|
|
|
|
|
|
|
|
|
Capsule::table('cloud_instances')->where('id', 1)->delete();
|
|
|
|
|
$deletedList = CloudInvoicePageService::forUser(1, 1, 10, 'upgrade');
|
|
|
|
|
$deletedStatus = CloudInvoiceService::status($upgradeInvoice);
|
|
|
|
|
$deletedDetail = CloudInvoiceService::display($upgradeInvoice);
|
|
|
|
|
$assert(($deletedList['invoices'][0]['instance_id'] ?? null) === '1'
|
|
|
|
|
&& ($deletedStatus['instance_id'] ?? null) === '1'
|
|
|
|
|
&& ($deletedDetail['instance_id'] ?? null) === '1'
|
|
|
|
|
&& ($deletedDetail['instance_name'] ?? null) === '已删除实例',
|
|
|
|
|
'Upgrade audit lost its referenced instance ID after the instance row disappeared.');
|
|
|
|
|
$assert(CloudInvoicePageService::normalizePurpose('upgrade') === 'upgrade'
|
|
|
|
|
&& CloudInvoicePageService::normalizePurpose('backup_addon') === 'backup_addon'
|
|
|
|
|
&& CloudInvoicePageService::normalizePurpose('invalid') === 'all'
|
|
|
|
|
&& CloudInvoicePageService::normalizePurpose(['renewal']) === 'all',
|
|
|
|
|
'Invoice purpose filtering accepted an unsupported or structured value.');
|
|
|
|
|
|
|
|
|
|
echo "User invoice filtering, ownership, deadlines and upgrade task checks passed.\n";
|