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.
This commit is contained in:
baodev0
2026-08-22 17:30:55 +07:00
parent eec2c5906e
commit c377c7e195
58 changed files with 3063 additions and 418 deletions
@@ -0,0 +1,74 @@
<?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);
}
}
@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
namespace Tests\Feature\Api\Admin\Customer;
use App\Mail\Customer\PasswordResetByAdmin;
use App\Models\Customer;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Mail;
use Spatie\Permission\Models\Role;
use Tests\TestCase;
class ResetPasswordTest extends TestCase
{
use RefreshDatabase;
private User $admin;
private Customer $customer;
protected function setUp(): void
{
parent::setUp();
Role::firstOrCreate(['name' => 'Full Administrator', 'guard_name' => 'admin']);
$this->admin = User::factory()->create();
$this->admin->assignRole('Full Administrator');
$this->customer = Customer::factory()->create([
'password' => Hash::make('old-password'),
]);
}
public function test_reset_password_sends_email_and_does_not_leak_password_in_response(): void
{
Mail::fake();
$oldHash = $this->customer->password;
$response = $this->actingAs($this->admin, 'admin')
->postJson("/api/v1/administrator/customers/{$this->customer->uuid}/reset-password");
$response->assertOk();
$response->assertJsonMissingPath('data.new_password');
$response->assertJsonMissing(['new_password']);
Mail::assertSent(PasswordResetByAdmin::class, function (PasswordResetByAdmin $mail) {
return $mail->hasTo($this->customer->email);
});
$this->assertNotSame($oldHash, $this->customer->fresh()->password);
}
}