Deploy Ladill Queue / deploy (push) Successful in 55s
Let orgs manage logos in settings and render customer-facing mail with company branding. Co-authored-by: Cursor <cursoragent@cursor.com>
159 lines
5.4 KiB
PHP
159 lines
5.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Http\Middleware\EnsurePlatformSession;
|
|
use App\Mail\ContactMessageMail;
|
|
use App\Models\Branch;
|
|
use App\Models\ServiceQueue;
|
|
use App\Models\Ticket;
|
|
use App\Models\User;
|
|
use App\Services\Qms\OrganizationResolver;
|
|
use App\Services\Qms\QueueNotificationService;
|
|
use App\Support\OrganizationBranding;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Tests\TestCase;
|
|
|
|
class QueueEmailBrandingTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected User $owner;
|
|
|
|
protected \App\Models\Organization $organization;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->withoutMiddleware(EnsurePlatformSession::class);
|
|
|
|
$this->owner = User::create([
|
|
'public_id' => 'queue-brand-001',
|
|
'name' => 'Owner',
|
|
'email' => 'owner@example.com',
|
|
'password' => bcrypt('password'),
|
|
]);
|
|
|
|
$this->organization = app(OrganizationResolver::class)->completeOnboarding($this->owner, [
|
|
'organization_name' => 'Acme Queue Co',
|
|
'industry' => 'retail',
|
|
'appointment_mode' => 'hybrid',
|
|
'branch_name' => 'Main',
|
|
'timezone' => 'UTC',
|
|
]);
|
|
}
|
|
|
|
public function test_org_admin_can_upload_organization_logo(): void
|
|
{
|
|
Storage::fake('public');
|
|
|
|
$this->actingAs($this->owner)
|
|
->put(route('qms.settings.update'), [
|
|
'name' => 'Acme Queue Co',
|
|
'timezone' => 'UTC',
|
|
'appointment_mode' => 'hybrid',
|
|
'industry' => 'retail',
|
|
'notifications_enabled' => '1',
|
|
'logo' => UploadedFile::fake()->image('company-logo.png', 400, 120),
|
|
])
|
|
->assertRedirect();
|
|
|
|
$this->organization->refresh();
|
|
$this->assertNotNull($this->organization->logo_path);
|
|
Storage::disk('public')->assertExists($this->organization->logo_path);
|
|
}
|
|
|
|
public function test_queue_notification_email_contains_company_branding_without_product_logo(): void
|
|
{
|
|
Storage::fake('public');
|
|
Mail::fake();
|
|
|
|
$path = UploadedFile::fake()->image('company-logo.png', 400, 120)
|
|
->store('queue/organizations/'.$this->organization->id, 'public');
|
|
$this->organization->update(['logo_path' => $path, 'name' => 'Acme Queue Co']);
|
|
|
|
$branch = Branch::first();
|
|
$queue = ServiceQueue::create([
|
|
'owner_ref' => $this->owner->public_id,
|
|
'organization_id' => $this->organization->id,
|
|
'branch_id' => $branch->id,
|
|
'name' => 'Reception',
|
|
'prefix' => 'A',
|
|
'strategy' => 'fifo',
|
|
'is_active' => true,
|
|
'settings' => ['notifications_enabled' => true],
|
|
]);
|
|
|
|
$ticket = Ticket::create([
|
|
'owner_ref' => $this->owner->public_id,
|
|
'organization_id' => $this->organization->id,
|
|
'branch_id' => $branch->id,
|
|
'service_queue_id' => $queue->id,
|
|
'ticket_number' => 'A001',
|
|
'status' => 'waiting',
|
|
'customer_email' => 'customer@example.com',
|
|
'issued_at' => now(),
|
|
]);
|
|
|
|
app(QueueNotificationService::class)->ticketIssued($ticket);
|
|
|
|
$logoUrl = OrganizationBranding::emailLogoUrl($this->organization->fresh());
|
|
|
|
Mail::assertSent(ContactMessageMail::class, function (ContactMessageMail $mail) use ($logoUrl) {
|
|
$html = $mail->render();
|
|
|
|
return $mail->companyName === 'Acme Queue Co'
|
|
&& $mail->logoUrl === $logoUrl
|
|
&& str_contains($html, 'Acme Queue Co')
|
|
&& str_contains($html, $logoUrl)
|
|
&& ! str_contains($html, 'ladillqueue-logo')
|
|
&& ! str_contains($html, 'Sent via Ladill');
|
|
});
|
|
}
|
|
|
|
public function test_queue_notification_email_shows_company_name_when_no_logo(): void
|
|
{
|
|
Mail::fake();
|
|
|
|
$this->organization->update(['name' => 'Plain Name Org', 'logo_path' => null]);
|
|
|
|
$branch = Branch::first();
|
|
$queue = ServiceQueue::create([
|
|
'owner_ref' => $this->owner->public_id,
|
|
'organization_id' => $this->organization->id,
|
|
'branch_id' => $branch->id,
|
|
'name' => 'Reception',
|
|
'prefix' => 'B',
|
|
'strategy' => 'fifo',
|
|
'is_active' => true,
|
|
'settings' => ['notifications_enabled' => true],
|
|
]);
|
|
|
|
$ticket = Ticket::create([
|
|
'owner_ref' => $this->owner->public_id,
|
|
'organization_id' => $this->organization->id,
|
|
'branch_id' => $branch->id,
|
|
'service_queue_id' => $queue->id,
|
|
'ticket_number' => 'B001',
|
|
'status' => 'waiting',
|
|
'customer_email' => 'customer@example.com',
|
|
'issued_at' => now(),
|
|
]);
|
|
|
|
app(QueueNotificationService::class)->ticketIssued($ticket);
|
|
|
|
Mail::assertSent(ContactMessageMail::class, function (ContactMessageMail $mail) {
|
|
$html = $mail->render();
|
|
|
|
return $mail->companyName === 'Plain Name Org'
|
|
&& $mail->logoUrl === null
|
|
&& str_contains($html, 'Plain Name Org')
|
|
&& ! str_contains($html, 'ladillqueue-logo')
|
|
&& ! str_contains($html, 'Sent via Ladill');
|
|
});
|
|
}
|
|
}
|