Deploy Ladill Events / deploy (push) Successful in 43s
Co-authored-by: Cursor <cursoragent@cursor.com>
156 lines
5.0 KiB
PHP
156 lines
5.0 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Http\Middleware\EnsurePlatformSession;
|
|
use App\Models\MessagingCredential;
|
|
use App\Models\QrSetting;
|
|
use App\Models\User;
|
|
use App\Services\Events\EventEmailService;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Support\Facades\Crypt;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Str;
|
|
use Tests\TestCase;
|
|
|
|
class EventEmailBrandingTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->withoutMiddleware(EnsurePlatformSession::class);
|
|
Http::preventStrayRequests();
|
|
Storage::fake('public');
|
|
}
|
|
|
|
public function test_can_upload_logo_on_settings_update(): void
|
|
{
|
|
$user = User::create([
|
|
'public_id' => (string) Str::uuid(),
|
|
'name' => 'Branded Events Co',
|
|
'email' => 'brand+'.uniqid().'@example.com',
|
|
]);
|
|
|
|
$this->actingAs($user)
|
|
->put(route('account.settings.update'), [
|
|
'notify_registrations' => '1',
|
|
'notify_payouts' => '1',
|
|
'product_updates' => '1',
|
|
'low_balance_alerts' => '1',
|
|
'event_defaults' => [
|
|
'registration_open' => '1',
|
|
],
|
|
'logo' => UploadedFile::fake()->image('company-logo.png', 200, 80),
|
|
])
|
|
->assertRedirect(route('account.settings'));
|
|
|
|
$settings = QrSetting::where('user_id', $user->id)->first();
|
|
|
|
$this->assertNotNull($settings);
|
|
$this->assertNotNull($settings->logo_path);
|
|
Storage::disk('public')->assertExists($settings->logo_path);
|
|
}
|
|
|
|
public function test_registration_email_contains_logo_url_when_set(): void
|
|
{
|
|
$user = User::create([
|
|
'public_id' => 'usr-brand-logo-001',
|
|
'name' => 'Branded Events Co',
|
|
'email' => 'brand-logo@example.com',
|
|
]);
|
|
|
|
$logoPath = 'events/accounts/'.$user->id.'/company-logo.png';
|
|
Storage::disk('public')->put($logoPath, 'fake-logo');
|
|
|
|
QrSetting::create([
|
|
'user_id' => $user->id,
|
|
'logo_path' => $logoPath,
|
|
]);
|
|
|
|
$this->seedBirdCredentials($user);
|
|
|
|
$capturedHtml = null;
|
|
Http::fake([
|
|
'*/api/smtp/send' => function ($request) use (&$capturedHtml) {
|
|
$capturedHtml = $request['html'];
|
|
|
|
return Http::response(['success' => true, 'message_id' => 'x']);
|
|
},
|
|
]);
|
|
|
|
$sent = app(EventEmailService::class)->sendRegistrationConfirmation(
|
|
$user->public_id,
|
|
'ada@example.com',
|
|
'Demo event',
|
|
'BADGE123',
|
|
'https://meet.test/join',
|
|
'Ada Lovelace',
|
|
$user->email,
|
|
$user->name,
|
|
);
|
|
|
|
$this->assertTrue($sent);
|
|
$this->assertNotNull($capturedHtml);
|
|
$this->assertStringContainsString('/storage/'.$logoPath, $capturedHtml);
|
|
$this->assertStringNotContainsString('ladillevents-logo-email.png', $capturedHtml);
|
|
$this->assertStringContainsString('Sent via Ladill Events', $capturedHtml);
|
|
}
|
|
|
|
public function test_registration_email_uses_company_name_without_logo(): void
|
|
{
|
|
$user = User::create([
|
|
'public_id' => 'usr-brand-text-001',
|
|
'name' => 'CAPBuSS Events',
|
|
'email' => 'brand-text@example.com',
|
|
]);
|
|
|
|
$this->seedBirdCredentials($user);
|
|
|
|
$capturedHtml = null;
|
|
Http::fake([
|
|
'*/api/smtp/send' => function ($request) use (&$capturedHtml) {
|
|
$capturedHtml = $request['html'];
|
|
|
|
return Http::response(['success' => true, 'message_id' => 'x']);
|
|
},
|
|
]);
|
|
|
|
$sent = app(EventEmailService::class)->sendRegistrationConfirmation(
|
|
$user->public_id,
|
|
'ada@example.com',
|
|
'Demo event',
|
|
'BADGE123',
|
|
null,
|
|
'Ada Lovelace',
|
|
$user->email,
|
|
$user->name,
|
|
);
|
|
|
|
$this->assertTrue($sent);
|
|
$this->assertNotNull($capturedHtml);
|
|
$this->assertStringContainsString('CAPBuSS Events', $capturedHtml);
|
|
$this->assertStringNotContainsString('ladillevents-logo-email.png', $capturedHtml);
|
|
$this->assertStringContainsString('Sent via Ladill Events', $capturedHtml);
|
|
$this->assertStringNotContainsString('Ladill Technologies', $capturedHtml);
|
|
}
|
|
|
|
private function seedBirdCredentials(User $user): void
|
|
{
|
|
$plain = 'lsk_live_'.str_repeat('f', 32);
|
|
|
|
MessagingCredential::create([
|
|
'owner_ref' => $user->public_id,
|
|
'bird_api_key_encrypted' => Crypt::encryptString($plain),
|
|
'bird_api_key_prefix' => substr($plain, 0, 16),
|
|
'bird_from_email' => 'events@example.test',
|
|
'bird_from_name' => 'Events',
|
|
'bird_status' => MessagingCredential::STATUS_VALID,
|
|
'bird_validated_at' => now(),
|
|
]);
|
|
}
|
|
}
|