refactor(integration): resolver credenciales mediante instancias
Resuelve primero la instancia del cliente y luego la del tipo de sitio cuando existe contexto de tenant. Adapta SMTP y Telepagos, con tokens identificados por instancia y version de credenciales. Separa la edicion de instancias de sus asociaciones y conserva el guardado por cliente creando una instancia nueva. Impide eliminar instancias en uso y adapta las pruebas existentes, incluida la herencia SMTP.
This commit is contained in:
@@ -4,17 +4,18 @@ namespace Tests\Feature\MailTest;
|
||||
|
||||
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\MailTest\Mailables\TestMail;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Tests\Concerns\CreatesIntegrationInstances;
|
||||
use Tests\TestCase;
|
||||
|
||||
class MailTestControllerTest extends TestCase
|
||||
{
|
||||
use CreatesIntegrationInstances;
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_it_sends_a_test_email(): void
|
||||
@@ -22,7 +23,7 @@ class MailTestControllerTest extends TestCase
|
||||
Mail::fake();
|
||||
$tenant = $this->createTenant();
|
||||
|
||||
$response = $this->postJson('/api/acme/mail-test/send', [
|
||||
$response = $this->withHeader('Accept-Language', 'es')->postJson('/api/acme/mail-test/send', [
|
||||
'to' => 'recipient@example.com',
|
||||
'subject' => 'SMTP test',
|
||||
'message' => 'Test message',
|
||||
@@ -32,7 +33,7 @@ class MailTestControllerTest extends TestCase
|
||||
->assertJsonPath('message', 'Correo de prueba enviado correctamente.')
|
||||
->assertJsonPath('recipient', 'recipient@example.com')
|
||||
->assertJsonPath('tenant_code', 'acme')
|
||||
->assertJsonPath('mailer', 'tenant-smtp')
|
||||
->assertJsonPath('mailer', 'integration-smtp')
|
||||
->assertJsonStructure(['sent_at']);
|
||||
|
||||
Mail::assertSent(Mailable::class, function (Mailable $mail) use ($tenant): bool {
|
||||
@@ -48,7 +49,7 @@ class MailTestControllerTest extends TestCase
|
||||
Mail::fake();
|
||||
$this->createTenant();
|
||||
|
||||
$this->postJson('/api/acme/mail-test/send', [
|
||||
$this->withHeader('Accept-Language', 'es')->postJson('/api/acme/mail-test/send', [
|
||||
'to' => 'recipient@example.com',
|
||||
])->assertOk();
|
||||
|
||||
@@ -63,7 +64,7 @@ class MailTestControllerTest extends TestCase
|
||||
Mail::fake();
|
||||
$this->createTenant();
|
||||
|
||||
$this->postJson('/api/acme/mail-test/send', [
|
||||
$this->withHeader('Accept-Language', 'es')->postJson('/api/acme/mail-test/send', [
|
||||
'to' => 'invalid-email',
|
||||
])->assertUnprocessable()
|
||||
->assertJsonValidationErrors(['to']);
|
||||
@@ -117,7 +118,7 @@ class MailTestControllerTest extends TestCase
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$this->postJson('/api/unknown/mail-test/send', [
|
||||
$this->withHeader('Accept-Language', 'es')->postJson('/api/unknown/mail-test/send', [
|
||||
'to' => 'recipient@example.com',
|
||||
])->assertNotFound();
|
||||
|
||||
@@ -129,7 +130,7 @@ class MailTestControllerTest extends TestCase
|
||||
Mail::fake();
|
||||
$tenant = $this->createTenant();
|
||||
|
||||
$this->postJson("/api/{$tenant->id}/mail-test/send", [
|
||||
$this->withHeader('Accept-Language', 'es')->postJson("/api/{$tenant->id}/mail-test/send", [
|
||||
'to' => 'recipient@example.com',
|
||||
])->assertNotFound();
|
||||
|
||||
@@ -171,7 +172,7 @@ class MailTestControllerTest extends TestCase
|
||||
'integration_code' => 'email',
|
||||
'name' => 'Email',
|
||||
]);
|
||||
ClientIntegration::create([
|
||||
$this->createClientIntegration([
|
||||
'client_id' => $tenant->client_id,
|
||||
'integration_code' => 'email',
|
||||
'integration_data' => [
|
||||
|
||||
Reference in New Issue
Block a user