withoutMiddleware(EnsurePlatformSession::class); config(['billing.api_url' => 'https://billing.test']); $this->user = User::create([ 'public_id' => 'fd-brand-001', 'name' => 'Test User', 'email' => 'frontdesk@example.com', ]); $this->organization = Organization::create([ 'owner_ref' => $this->user->public_id, 'name' => 'Frontdesk HQ', 'slug' => 'frontdesk-hq', 'timezone' => 'UTC', 'settings' => [ 'onboarded' => true, 'plan' => 'pro', 'plan_expires_at' => now()->addMonth()->toIso8601String(), 'badge_expiry_hours' => 8, 'kiosk_reset_seconds' => 120, 'notification_channels' => ['email'], ], ]); Member::create([ 'owner_ref' => $this->user->public_id, 'organization_id' => $this->organization->id, 'user_ref' => $this->user->public_id, 'role' => 'org_admin', ]); Branch::create([ 'owner_ref' => $this->user->public_id, 'organization_id' => $this->organization->id, 'name' => 'Main Office', 'is_active' => true, ]); } public function test_host_alert_email_contains_organization_branding(): void { Storage::fake('public'); $path = UploadedFile::fake()->image('hq-logo.png', 400, 120) ->store('frontdesk/organizations/'.$this->organization->id, 'public'); $this->organization->update(['logo_path' => $path, 'name' => 'Frontdesk HQ']); $plain = 'lsk_live_'.str_repeat('d', 32); MessagingCredential::create([ 'owner_ref' => $this->user->public_id, 'organization_id' => $this->organization->id, 'bird_api_key_encrypted' => Crypt::encryptString($plain), 'bird_api_key_prefix' => substr($plain, 0, 16), 'bird_from_email' => 'frontdesk@example.test', 'bird_from_name' => 'Frontdesk', 'bird_status' => MessagingCredential::STATUS_VALID, 'bird_validated_at' => now(), ]); Http::fake([ 'billing.test/*' => Http::response(['affordable' => true, 'ok' => true]), '*/api/smtp/send' => Http::response(['success' => true, 'message_id' => 'x']), ]); $host = Host::create([ 'owner_ref' => $this->user->public_id, 'organization_id' => $this->organization->id, 'name' => 'Jane Host', 'email' => 'jane@example.com', 'is_available' => true, ]); $this->actingAs($this->user) ->post(route('frontdesk.visits.store'), [ 'full_name' => 'John Visitor', 'host_id' => $host->id, 'visitor_type' => 'visitor', 'policies_accepted' => '1', ]) ->assertRedirect(); $logoUrl = OrganizationBranding::emailLogoUrl($this->organization->fresh()); Http::assertSent(function ($request) use ($logoUrl) { $html = $request['html'] ?? ''; return str_contains($request->url(), '/api/smtp/send') && str_contains($html, 'Frontdesk HQ') && str_contains($html, $logoUrl) && ! str_contains($html, 'ladillfrontdesk-logo') && str_contains($html, 'Sent via Ladill Frontdesk'); }); } public function test_laravel_mail_uses_organization_branding(): void { Storage::fake('public'); \Illuminate\Support\Facades\Mail::fake(); $path = UploadedFile::fake()->image('hq-logo.png', 400, 120) ->store('frontdesk/organizations/'.$this->organization->id, 'public'); $this->organization->update(['logo_path' => $path]); $logoUrl = OrganizationBranding::emailLogoUrl($this->organization->fresh()); $sent = app(\App\Services\Comms\EmailService::class)->send( 'admin@example.com', 'Daily summary', "Visitors checked in: 3\nDeliveries: 1", $this->organization->name, null, $this->organization->fresh(), ); $this->assertTrue($sent); \Illuminate\Support\Facades\Mail::assertSent(\App\Mail\ContactMessageMail::class, function (\App\Mail\ContactMessageMail $mail) use ($logoUrl) { $html = $mail->render(); return $mail->logoUrl === $logoUrl && $mail->companyName === 'Frontdesk HQ' && str_contains($html, 'Frontdesk HQ') && str_contains($html, $logoUrl) && str_contains($html, 'Sent via Ladill Frontdesk'); }); } }