Files
portal-api/tests/Feature/Api/Admin/Customer/CustomerMassAssignmentTest.php
baodev0 c377c7e195 feat: add domain registration form and email notifications
- Create a new Blade view for domain registration (`registrant-tochuc.blade.php`) to capture organization and manager details.
- Implement email templates for new domain orders for both admin (`domain-order-new.blade.php`) and customers (`domain-order-received.blade.php`).
- Add CSV exports for client and domain data.
- Introduce tests for customer mass assignment, password reset, login throttling, and permission gating.
- Ensure service renewals use current pricing and validate ownership for virtual machines.
- Validate mass assignment behavior in service model.
2026-08-22 17:30:55 +07:00

75 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\Api\Admin\Customer;
use App\Models\Customer;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Spatie\Permission\Models\Role;
use Tests\TestCase;
class CustomerMassAssignmentTest extends TestCase
{
use RefreshDatabase;
private User $admin;
protected function setUp(): void
{
parent::setUp();
Role::firstOrCreate(['name' => 'Full Administrator', 'guard_name' => 'admin']);
$this->admin = User::factory()->create();
$this->admin->assignRole('Full Administrator');
}
public function test_store_ignores_fields_not_declared_in_validation_rules(): void
{
$response = $this->actingAs($this->admin, 'admin')->postJson('/api/v1/administrator/customers', [
'fullname' => 'Nguyen Van A',
'email' => 'nva@example.com',
'password' => 'secret123',
// Các field này nằm trong $fillable của Customer nhưng KHÔNG có trong
// CreateCustomerRequest::rules() — không được phép set qua endpoint tạo mới.
'credit' => 999_999_999,
'total' => 999_999_999,
'status' => 1,
'email_verified_at' => now()->toDateTimeString(),
]);
$response->assertCreated();
$customer = Customer::where('email', 'nva@example.com')->firstOrFail();
$this->assertSame(0, (int) $customer->credit);
$this->assertSame(0, (int) $customer->total);
$this->assertNull($customer->email_verified_at);
}
public function test_update_ignores_fields_not_declared_in_validation_rules(): void
{
$customer = Customer::factory()->create([
'credit' => 0,
'total' => 0,
]);
$response = $this->actingAs($this->admin, 'admin')->putJson(
"/api/v1/administrator/customers/{$customer->uuid}",
[
'fullname' => 'Updated Name',
'email' => $customer->email,
'credit' => 999_999_999,
'total' => 999_999_999,
],
);
$response->assertOk();
$customer->refresh();
$this->assertSame(0, (int) $customer->credit);
$this->assertSame(0, (int) $customer->total);
$this->assertSame('Updated Name', $customer->fullname);
}
}