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