feat: Introduce client management and integration updates

- Added client_id field to StoreTenantRequest and UpdateTenantRequest for tenant management.
- Updated TenantResource to include client_id in the response.
- Created migration to establish clients table and link tenants to clients.
- Migrated existing tenant integrations to client_integrations table.
- Grouped specific tenants under a shared client (OnTicket) in a new migration.
- Updated seeders to reflect new client structure and relationships.
- Adjusted integration configurations to require client instead of tenant.
- Added tests for client integration functionality and ensured existing tests reflect the new client structure.
This commit is contained in:
2026-08-18 16:18:34 -03:00
parent e6785eb5af
commit d73b4d1daf
42 changed files with 931 additions and 392 deletions

View File

@@ -4,10 +4,10 @@ namespace Tests\Feature\Integration;
use App\Domains\Attachable\Enums\AttachmentType;
use App\Domains\Attachable\Models\Attachment;
use App\Domains\Integration\Models\ClientIntegration;
use App\Domains\Integration\Models\Integration;
use App\Domains\Integration\Models\TenantIntegration;
use App\Domains\Integration\Services\ClientIntegrationService;
use App\Domains\Integration\Services\MailService;
use App\Domains\Integration\Services\TenantIntegrationService;
use App\Domains\Tenant\Models\Tenant;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Mail\Mailable;
@@ -21,12 +21,12 @@ class MailServiceTest extends TestCase
{
use RefreshDatabase;
public function test_it_builds_an_isolated_smtp_mailer_from_the_tenant_integration(): void
public function test_it_builds_an_isolated_smtp_mailer_from_the_client_integration(): void
{
$tenant = $this->createTenant();
$this->createEmailIntegration();
TenantIntegration::create([
'tenant_code' => $tenant->codigo,
ClientIntegration::create([
'client_id' => $tenant->client_id,
'integration_code' => 'email',
'integration_data' => $this->emailData(),
]);
@@ -40,7 +40,7 @@ class MailServiceTest extends TestCase
$manager->shouldReceive('build')
->once()
->with(Mockery::on(fn (array $config): bool => $config === [
'name' => 'tenant-smtp-acme',
'name' => 'client-smtp-'.$tenant->client_id,
'transport' => 'smtp',
'scheme' => 'smtp',
'host' => 'smtp.example.com',
@@ -54,10 +54,10 @@ class MailServiceTest extends TestCase
$service = (new MailService($manager))->forTenant($tenant->codigo);
$this->assertSame('tenant-smtp', $service->mailerName());
$this->assertSame('client-smtp', $service->mailerName());
}
public function test_it_uses_the_default_mailer_when_tenant_configuration_is_not_required(): void
public function test_it_uses_the_default_mailer_when_client_configuration_is_not_required(): void
{
Mail::fake();
config(['mail.default' => 'array']);
@@ -65,7 +65,7 @@ class MailServiceTest extends TestCase
Integration::create([
'integration_code' => 'email',
'name' => 'Email',
'requires_tenant_configuration' => false,
'requires_client_configuration' => false,
]);
$service = (new MailService)->forTenant($tenant->codigo);
@@ -84,8 +84,8 @@ class MailServiceTest extends TestCase
Mail::fake();
$tenant = $this->createTenant();
$this->createEmailIntegration();
TenantIntegration::create([
'tenant_code' => $tenant->codigo,
ClientIntegration::create([
'client_id' => $tenant->client_id,
'integration_code' => 'email',
'integration_data' => $this->emailData(),
]);
@@ -109,8 +109,8 @@ class MailServiceTest extends TestCase
$tenant = $this->createTenant();
$integration = $this->createEmailIntegration();
app(TenantIntegrationService::class)->updateOrCreateIntegration(
$tenant->codigo,
app(ClientIntegrationService::class)->updateOrCreateIntegration(
$tenant->client,
$integration,
$this->emailData(),
);