feat(mail-test): implement email testing functionality
- Created MailTestController to handle email sending requests. - Added SendTestMailRequest for validating email input. - Developed MailTestService to manage email sending logic. - Introduced TestMail Mailable for formatting test emails. - Defined API route for sending test emails. - Created EmailIntegrationSeeder to seed email integration settings. - Updated DatabaseSeeder to include EmailIntegrationSeeder. - Added MailTestControllerTest to ensure email sending functionality works as expected.
This commit is contained in:
59
tests/Feature/MailTest/MailTestControllerTest.php
Normal file
59
tests/Feature/MailTest/MailTestControllerTest.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\MailTest;
|
||||
|
||||
use App\Domains\MailTest\Mailables\TestMail;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Tests\TestCase;
|
||||
|
||||
class MailTestControllerTest extends TestCase
|
||||
{
|
||||
public function test_it_sends_a_test_email(): void
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$response = $this->postJson('/api/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('mailer', 'array')
|
||||
->assertJsonStructure(['sent_at']);
|
||||
|
||||
Mail::assertSent(TestMail::class, function (TestMail $mail): bool {
|
||||
return $mail->hasTo('recipient@example.com')
|
||||
&& $mail->mailSubject === 'SMTP test'
|
||||
&& $mail->mailMessage === 'Test message';
|
||||
});
|
||||
}
|
||||
|
||||
public function test_it_uses_default_content_when_optional_fields_are_omitted(): void
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$this->postJson('/api/mail-test/send', [
|
||||
'to' => 'recipient@example.com',
|
||||
])->assertOk();
|
||||
|
||||
Mail::assertSent(TestMail::class, function (TestMail $mail): bool {
|
||||
return $mail->mailSubject === 'Prueba de correo de Shopit'
|
||||
&& $mail->mailMessage === 'Este es un correo de prueba enviado desde Shopit.';
|
||||
});
|
||||
}
|
||||
|
||||
public function test_it_validates_the_recipient(): void
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$this->postJson('/api/mail-test/send', [
|
||||
'to' => 'invalid-email',
|
||||
])->assertUnprocessable()
|
||||
->assertJsonValidationErrors(['to']);
|
||||
|
||||
Mail::assertNothingSent();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user