refactor(mail-test): remove unused developer endpoint

This commit is contained in:
2026-08-27 12:10:41 -03:00
parent 4a166e3cbf
commit 889e188deb
7 changed files with 0 additions and 362 deletions

View File

@@ -1,32 +0,0 @@
<?php
namespace App\Domains\MailTest\Controllers;
use App\Domains\MailTest\Requests\SendTestMailRequest;
use App\Domains\MailTest\Services\MailTestService;
use App\Domains\Tenant\Models\Tenant;
use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;
class MailTestController extends Controller
{
public function __construct(
protected MailTestService $mailTestService,
) {}
public function __invoke(SendTestMailRequest $request, string $tenantCode): JsonResponse
{
$tenant = Tenant::query()
->where('codigo', $tenantCode)
->firstOrFail();
return response()->json(
$this->mailTestService->send(
$tenant,
$request->validated('to'),
$request->validated('subject'),
$request->validated('message'),
)
);
}
}

View File

@@ -1,51 +0,0 @@
<?php
namespace App\Domains\MailTest\Mailables;
use App\Domains\Tenant\Models\Tenant;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class TestMail extends Mailable
{
use Queueable, SerializesModels;
public function __construct(
public readonly string $mailSubject,
public readonly string $mailMessage,
public readonly Tenant $tenant,
) {}
public function envelope(): Envelope
{
return new Envelope(subject: $this->mailSubject);
}
public function content(): Content
{
$this->tenant->loadMissing(['headerLogo', 'footerLogo']);
$branding = [
'name' => $this->tenant->nombre,
'primary_color' => $this->tenant->primary_color ?? '#6376f3',
'body_color' => '#334155',
'background_color' => '#f1f5f9',
'surface_color' => '#ffffff',
'header_bg_color' => $this->tenant->header_bg_color ?? '#ffffff',
'footer_bg_color' => $this->tenant->footer_bg_color ?? '#334155',
];
return new Content(
view: 'mail.test',
with: [
'tenant' => $this->tenant,
'branding' => $branding,
'headerLogoUrl' => $this->tenant->headerLogo?->getTemporaryUrl(1440),
'footerLogoUrl' => $this->tenant->footerLogo?->getTemporaryUrl(1440),
],
);
}
}

View File

@@ -1,25 +0,0 @@
<?php
namespace App\Domains\MailTest\Requests;
use Illuminate\Foundation\Http\FormRequest;
class SendTestMailRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
/**
* @return array<string, array<int, string>>
*/
public function rules(): array
{
return [
'to' => ['required', 'string', 'email', 'max:255'],
'subject' => ['nullable', 'string', 'max:255'],
'message' => ['nullable', 'string', 'max:5000'],
];
}
}

View File

@@ -1,35 +0,0 @@
<?php
namespace App\Domains\MailTest\Services;
use App\Domains\Integration\Services\MailService;
use App\Domains\Tenant\Models\Tenant;
class MailTestService
{
/**
* @return array<string, string>
*/
public function send(Tenant $tenant, string $recipient, ?string $subject = null, ?string $message = null): array
{
$subject ??= 'Prueba de correo de Shopit';
$message ??= 'Este es un correo de prueba enviado desde Shopit.';
$mailService = (new MailService)->forTenant($tenant->codigo);
$mailService->send(
$recipient,
$subject,
'<h1 style="margin: 0 0 20px;">'.e($subject).'</h1>'
.'<p>'.nl2br(e($message)).'</p>',
);
return [
'code' => 'mail.test_sent',
'message' => __('api.mail.test_sent'),
'recipient' => $recipient,
'tenant_code' => $tenant->codigo,
'mailer' => $mailService->mailerName(),
'sent_at' => now()->toIso8601String(),
];
}
}

View File

@@ -1,24 +0,0 @@
# Dominio MailTest
## Propósito
Ofrece una operación técnica para verificar la configuración de correo de un tenant sin ejecutar un flujo funcional real.
## Componentes
- `MailTestController`: endpoint invocable de envío.
- `SendTestMailRequest`: valida destinatario y contenido requerido.
- `MailTestService`: coordina el envío de prueba.
- `TestMail`: mailable utilizado para construir el mensaje.
## Endpoint
- `POST /{tenant_code}/mail-test/send`.
## Dependencias
Usa la configuración de correo del dominio `Integration` y resuelve el tenant indicado.
## Consideraciones
Es una herramienta de diagnóstico. Debe restringirse o deshabilitarse en entornos donde no corresponda exponer envíos de prueba, y nunca debe registrar credenciales.

View File

@@ -1,6 +0,0 @@
<?php
use App\Domains\MailTest\Controllers\MailTestController;
use Illuminate\Support\Facades\Route;
Route::post('{tenant_code}/mail-test/send', MailTestController::class);

View File

@@ -1,189 +0,0 @@
<?php
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\TestCase;
class MailTestControllerTest extends TestCase
{
use RefreshDatabase;
public function test_it_sends_a_test_email(): void
{
Mail::fake();
$tenant = $this->createTenant();
$response = $this->postJson('/api/acme/mail-test/send', [
'to' => 'recipient@example.com',
'subject' => 'SMTP test',
'message' => 'Test message',
]);
$response->assertOk()
->assertJsonPath('message', 'Correo de prueba enviado correctamente.')
->assertJsonPath('recipient', 'recipient@example.com')
->assertJsonPath('tenant_code', 'acme')
->assertJsonPath('mailer', 'tenant-smtp')
->assertJsonStructure(['sent_at']);
Mail::assertSent(Mailable::class, function (Mailable $mail) use ($tenant): bool {
return $mail->hasTo('recipient@example.com')
&& $mail->subject === 'SMTP test'
&& str_contains($mail->render(), 'Test message')
&& str_contains($mail->render(), $tenant->nombre);
});
}
public function test_it_uses_default_content_when_optional_fields_are_omitted(): void
{
Mail::fake();
$this->createTenant();
$this->postJson('/api/acme/mail-test/send', [
'to' => 'recipient@example.com',
])->assertOk();
Mail::assertSent(Mailable::class, function (Mailable $mail): bool {
return $mail->subject === 'Prueba de correo de Shopit'
&& str_contains($mail->render(), 'Este es un correo de prueba enviado desde Shopit.');
});
}
public function test_it_validates_the_recipient(): void
{
Mail::fake();
$this->createTenant();
$this->postJson('/api/acme/mail-test/send', [
'to' => 'invalid-email',
])->assertUnprocessable()
->assertJsonValidationErrors(['to']);
Mail::assertNothingSent();
}
public function test_the_mail_template_uses_the_tenant_branding(): void
{
$tenant = new Tenant([
'codigo' => 'tenant-store',
'nombre' => 'Tenant Store',
'primary_color' => '#778899',
'header_bg_color' => '#112233',
'footer_bg_color' => '#445566',
]);
$tenant->setRelation('headerLogo', new class extends Attachment
{
public function getTemporaryUrl(int $expiresInMinutes = 10): string
{
return 'https://example.com/header-logo.png';
}
});
$tenant->setRelation('footerLogo', new class extends Attachment
{
public function getTemporaryUrl(int $expiresInMinutes = 10): string
{
return 'https://example.com/footer-logo.png';
}
});
$mail = new TestMail(
'Branded email',
'Tenant message',
$tenant,
);
$html = $mail->render();
$this->assertStringContainsString('https://example.com/header-logo.png', $html);
$this->assertStringContainsString('https://example.com/footer-logo.png', $html);
$this->assertStringContainsString('background-color: #112233', $html);
$this->assertStringContainsString('background-color: #445566', $html);
$this->assertStringContainsString('color: #778899', $html);
$this->assertStringContainsString('Tenant Store', $html);
$this->assertStringContainsString('Tenant message', $html);
}
public function test_it_returns_not_found_for_an_unknown_tenant(): void
{
Mail::fake();
$this->postJson('/api/unknown/mail-test/send', [
'to' => 'recipient@example.com',
])->assertNotFound();
Mail::assertNothingSent();
}
public function test_it_does_not_resolve_the_tenant_by_id(): void
{
Mail::fake();
$tenant = $this->createTenant();
$this->postJson("/api/{$tenant->id}/mail-test/send", [
'to' => 'recipient@example.com',
])->assertNotFound();
Mail::assertNothingSent();
}
private function createTenant(): Tenant
{
$headerLogo = Attachment::create([
'path' => 'tenants/header.png',
'filename' => 'header.png',
'type' => AttachmentType::Image,
'mime_type' => 'image/png',
'extension' => 'png',
]);
$footerLogo = Attachment::create([
'path' => 'tenants/footer.png',
'filename' => 'footer.png',
'type' => AttachmentType::Image,
'mime_type' => 'image/png',
'extension' => 'png',
]);
$tenant = Tenant::create([
'codigo' => 'acme',
'nombre' => 'Acme Store',
'dominio' => 'acme.example.com',
'primary_color' => '#778899',
'secondary_color' => '#64748b',
'danger_color' => '#dc2626',
'success_color' => '#16a34a',
'header_bg_color' => '#112233',
'footer_bg_color' => '#445566',
'header_logo_id' => $headerLogo->id,
'footer_logo_id' => $footerLogo->id,
]);
Integration::create([
'integration_code' => 'email',
'name' => 'Email',
]);
ClientIntegration::create([
'client_id' => $tenant->client_id,
'integration_code' => 'email',
'integration_data' => [
'MAIL_SCHEME' => 'smtp',
'MAIL_HOST' => 'smtp.example.com',
'MAIL_PORT' => 587,
'MAIL_USERNAME' => 'mailer@example.com',
'MAIL_PASSWORD' => 'secret',
'MAIL_FROM_ADDRESS' => 'store@example.com',
],
]);
return $tenant;
}
}