- ProvisionDnsDomainJob/SuspendDnsDomainJob: tạo domain admin lên Plesk, huỷ = suspend (is_created=3) - Khách xem zone DNS được gán ở /dich-vu/domain, quản lý bản ghi A/AAAA/CNAME/TXT/MX/SRV - send-mail hoá đơn đẩy SendInvoiceMailJob, preview + sửa nội dung, ghi mail.order_id - invoice_attachments.type (payment_proof/deployment) - CacheService xoá theo SCAN pattern, Redis không persistent mặc định - Backfill transactions.public_code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
64 lines
2.6 KiB
PHP
64 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\Api\Admin\Customer;
|
|
|
|
use App\Models\Customer;
|
|
use App\Models\Transaction;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Spatie\Permission\Models\Role;
|
|
use Tests\TestCase;
|
|
|
|
class ManualTransactionTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_admin_records_and_deletes_a_manual_transaction_without_touching_balance(): void
|
|
{
|
|
Role::firstOrCreate(['name' => 'Full Administrator', 'guard_name' => 'admin']);
|
|
$admin = User::factory()->create();
|
|
$admin->assignRole('Full Administrator');
|
|
$customer = Customer::factory()->create(['total' => 500000]);
|
|
$url = "/api/v1/administrator/customers/{$customer->uuid}/transactions";
|
|
|
|
$created = $this->actingAs($admin, 'admin')
|
|
->postJson($url, ['trans' => 'CK VCB 123', 'amount' => 800000, 'note' => 'Thu tiền mặt'])
|
|
->assertCreated()
|
|
->json('data');
|
|
|
|
$this->assertMatchesRegularExpression('/^ADM-\d{8}-[A-Z0-9]{6}$/', $created['public_code']);
|
|
$this->assertSame('neutral', $created['direction']);
|
|
$this->assertSame(500000, (int) $customer->fresh()->total);
|
|
$this->actingAs($admin, 'admin')->getJson($url)->assertJsonCount(1, 'data');
|
|
|
|
$this->actingAs($admin, 'admin')->deleteJson("{$url}/{$created['id']}")->assertOk();
|
|
$this->assertSoftDeleted('transactions', ['id' => $created['id']]);
|
|
}
|
|
|
|
public function test_transaction_created_without_code_gets_one(): void
|
|
{
|
|
$customer = Customer::factory()->create();
|
|
|
|
$transaction = Transaction::create(['amount' => 1, 'customer_id' => $customer->id, 'type' => 'transfer', 'status' => 1]);
|
|
|
|
$this->assertMatchesRegularExpression('/^TXN-\d{8}-[A-Z0-9]{6}$/', $transaction->public_code);
|
|
}
|
|
|
|
public function test_cannot_delete_another_customers_transaction(): void
|
|
{
|
|
Role::firstOrCreate(['name' => 'Full Administrator', 'guard_name' => 'admin']);
|
|
$admin = User::factory()->create();
|
|
$admin->assignRole('Full Administrator');
|
|
$owner = Customer::factory()->create();
|
|
$other = Customer::factory()->create();
|
|
$transaction = Transaction::create(['amount' => 1, 'customer_id' => $owner->id, 'type' => 'transfer', 'status' => 1]);
|
|
|
|
$this->actingAs($admin, 'admin')
|
|
->deleteJson("/api/v1/administrator/customers/{$other->uuid}/transactions/{$transaction->id}")
|
|
->assertNotFound();
|
|
$this->assertNotSoftDeleted('transactions', ['id' => $transaction->id]);
|
|
}
|
|
}
|