87 lines
2.9 KiB
PHP
87 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Mail;
|
|
|
|
use App\Domains\Attachable\Enums\AttachmentType;
|
|
use App\Domains\Attachable\Models\Attachment;
|
|
use App\Domains\Integration\Models\Integration;
|
|
use App\Domains\Integration\Models\TenantIntegration;
|
|
use App\Domains\Mail\Services\MailService;
|
|
use App\Domains\Tenant\Models\Tenant;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Mail\Mailer;
|
|
use Illuminate\Mail\MailManager;
|
|
use Mockery;
|
|
use Tests\TestCase;
|
|
|
|
class MailServiceTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_it_builds_an_isolated_smtp_mailer_from_the_tenant_integration(): void
|
|
{
|
|
$logo = Attachment::create([
|
|
'path' => 'tenants/logo.png',
|
|
'filename' => 'logo.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' => $logo->id,
|
|
'footer_logo_id' => $logo->id,
|
|
]);
|
|
Integration::create([
|
|
'integration_code' => 'email',
|
|
'name' => 'Email',
|
|
]);
|
|
TenantIntegration::create([
|
|
'tenant_code' => $tenant->codigo,
|
|
'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',
|
|
'MAIL_FROM_NAME' => 'Acme Mail',
|
|
],
|
|
]);
|
|
|
|
$mailer = Mockery::mock(Mailer::class);
|
|
$mailer->shouldReceive('alwaysFrom')
|
|
->once()
|
|
->with('store@example.com', 'Acme Mail');
|
|
|
|
$manager = Mockery::mock(MailManager::class);
|
|
$manager->shouldReceive('build')
|
|
->once()
|
|
->with(Mockery::on(fn (array $config): bool => $config === [
|
|
'name' => 'tenant-smtp-acme',
|
|
'transport' => 'smtp',
|
|
'scheme' => 'smtp',
|
|
'host' => 'smtp.example.com',
|
|
'port' => 587,
|
|
'username' => 'mailer@example.com',
|
|
'password' => 'secret',
|
|
'timeout' => null,
|
|
'local_domain' => null,
|
|
]))
|
|
->andReturn($mailer);
|
|
|
|
$service = new MailService($tenant, $manager);
|
|
|
|
$this->assertSame('tenant-smtp', $service->mailerName());
|
|
}
|
|
}
|