Files
ladill-events/tests/Feature/EventsSuiteMessagingTest.php
T
isaacclad a7231ab16f
Deploy Ladill Events / deploy (push) Successful in 45s
fix(email): use client/org name as From display, not Ladill product
Customer-facing outbound mail should appear from the business (organizer,
clinic, company, location), not the Ladill product brand.
2026-07-16 12:01:06 +00:00

169 lines
5.4 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\User;
use App\Services\Billing\PlatformEmailClient;
use App\Services\Billing\PlatformSmsClient;
use App\Services\Events\EventMailer;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;
class EventsSuiteMessagingTest extends TestCase
{
use RefreshDatabase;
public function test_platform_email_client_sends_channel_suite(): void
{
config([
'smtp.platform_api_key' => 'events-key',
'smtp.platform_api_url' => 'https://platform.test/api/smtp',
'smtp.from_name' => 'Ladill Events',
]);
Http::fake([
'platform.test/api/smtp/messages/send' => Http::response(['success' => true, 'path' => 'suite']),
]);
$ok = app(PlatformEmailClient::class)->send(
'usr_events_1',
'guest@example.com',
'Ticket',
'<p>Hi</p>',
'Hi',
);
$this->assertTrue($ok);
Http::assertSent(function ($request) {
$data = $request->data();
return str_contains($request->url(), '/messages/send')
&& ($data['channel'] ?? null) === 'suite'
&& $request->hasHeader('Idempotency-Key');
});
}
public function test_platform_sms_client_sends_channel_suite_without_service_id(): void
{
config([
'sms.platform_api_key' => 'events-sms-key',
'sms.platform_api_url' => 'https://platform.test/api',
]);
Http::fake([
'platform.test/api/sms/messages/send' => Http::response(['success' => true, 'path' => 'suite']),
]);
$ok = app(PlatformSmsClient::class)->send('usr_events_1', '0241234567', 'Hello');
$this->assertTrue($ok);
Http::assertSent(function ($request) {
$data = $request->data();
return str_contains($request->url(), '/sms/messages/send')
&& ($data['channel'] ?? null) === 'suite'
&& ! array_key_exists('sms_service_id', $data);
});
}
public function test_event_mailer_uses_suite_when_platform_configured(): void
{
config([
'smtp.platform_api_key' => 'events-key',
'smtp.platform_api_url' => 'https://platform.test/api/smtp',
]);
Http::fake([
'platform.test/api/smtp/messages/send' => Http::response(['success' => true]),
]);
$user = User::factory()->create([
'public_id' => 'usr_mailer_suite',
'name' => 'Acme Events Ltd',
]);
$ok = app(EventMailer::class)->send(
$user->public_id,
'speaker@example.com',
'Invite',
'<p>Join us</p>',
'Join us',
);
$this->assertTrue($ok);
$this->assertTrue(app(EventMailer::class)->isConfiguredForOwner($user->public_id));
Http::assertSent(function ($request) {
$data = $request->data();
return str_contains($request->url(), '/messages/send')
&& ($data['channel'] ?? null) === 'suite'
&& ($data['from_name'] ?? null) === 'Acme Events Ltd';
});
}
public function test_sms_service_uses_suite_when_platform_configured(): void
{
config([
'sms.platform_api_key' => 'events-sms-key',
'sms.platform_api_url' => 'https://platform.test/api',
]);
Http::fake([
'platform.test/api/sms/messages/send' => Http::response(['success' => true, 'path' => 'suite']),
]);
$user = User::factory()->create(['public_id' => 'usr_sms_suite']);
$ok = app(\App\Services\Billing\SmsService::class)->send(
$user->public_id,
'0241234567',
'Programme link',
);
$this->assertTrue($ok);
$this->assertTrue(app(\App\Services\Billing\SmsService::class)->isConfiguredForOwner($user->public_id));
Http::assertSent(function ($request) {
$data = $request->data();
return str_contains($request->url(), '/sms/messages/send')
&& ($data['channel'] ?? null) === 'suite';
});
}
public function test_billing_client_syncs_suite_entitlement(): void
{
config([
'billing.api_url' => 'https://platform.test/api/billing',
'billing.api_key' => 'events-billing',
'billing.service' => 'events',
]);
Http::fake([
'platform.test/api/billing/suite-entitlements' => Http::response([
'data' => ['app' => 'events', 'plan' => 'pro'],
'idempotent_replay' => false,
], 201),
]);
$ok = app(\App\Services\Billing\BillingClient::class)->syncSuiteEntitlement(
'usr_events_1',
'pro',
'active',
'events-pro-ref-1',
[
'period_starts_at' => now()->toIso8601String(),
'period_ends_at' => now()->addMonth()->toIso8601String(),
'source' => 'wallet_debit',
],
);
$this->assertTrue($ok);
Http::assertSent(function ($request) {
$data = $request->data();
return str_contains($request->url(), '/suite-entitlements')
&& ($data['app'] ?? null) === 'events'
&& ($data['plan'] ?? null) === 'pro';
});
}
}