Add per-customer SMS and Bird credentials to Frontdesk Integrations.
Deploy Ladill Frontdesk / deploy (push) Successful in 45s
Deploy Ladill Frontdesk / deploy (push) Successful in 45s
NotificationDispatcher sends via customer relay and skips Frontdesk wallet debit when tenant keys are configured. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -6,14 +6,14 @@ use App\Http\Middleware\EnsurePlatformSession;
|
||||
use App\Models\Branch;
|
||||
use App\Models\Host;
|
||||
use App\Models\Member;
|
||||
use App\Models\MessagingCredential;
|
||||
use App\Models\NotificationUsage;
|
||||
use App\Models\Organization;
|
||||
use App\Models\User;
|
||||
use App\Models\Visit;
|
||||
use App\Notifications\FrontdeskAlertNotification;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -25,6 +25,8 @@ class FrontdeskNotificationBillingTest extends TestCase
|
||||
|
||||
protected Organization $organization;
|
||||
|
||||
protected string $birdKey;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
@@ -63,14 +65,26 @@ class FrontdeskNotificationBillingTest extends TestCase
|
||||
'name' => 'HQ',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$this->birdKey = 'lsk_live_'.str_repeat('a', 32);
|
||||
MessagingCredential::create([
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'bird_api_key_encrypted' => Crypt::encryptString($this->birdKey),
|
||||
'bird_api_key_prefix' => substr($this->birdKey, 0, 16),
|
||||
'bird_from_email' => 'notify@example.test',
|
||||
'bird_from_name' => 'Notify Org',
|
||||
'bird_status' => MessagingCredential::STATUS_VALID,
|
||||
'bird_validated_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_host_email_notification_without_ladill_user_link(): void
|
||||
{
|
||||
Mail::fake();
|
||||
Http::fake([
|
||||
'billing.test/can-afford*' => Http::response(['affordable' => true]),
|
||||
'billing.test/debit' => Http::response(['ok' => true]),
|
||||
'*/api/smtp/send' => Http::response(['success' => true]),
|
||||
]);
|
||||
|
||||
$host = Host::create([
|
||||
@@ -90,7 +104,8 @@ class FrontdeskNotificationBillingTest extends TestCase
|
||||
])
|
||||
->assertRedirect();
|
||||
|
||||
Mail::assertSent(\App\Mail\ContactMessageMail::class);
|
||||
Http::assertSent(fn ($request) => str_contains($request->url(), '/api/smtp/send'));
|
||||
Http::assertNotSent(fn ($request) => str_contains($request->url(), '/debit'));
|
||||
|
||||
$usage = NotificationUsage::where('organization_id', $this->organization->id)->first();
|
||||
$this->assertNotNull($usage);
|
||||
@@ -98,12 +113,12 @@ class FrontdeskNotificationBillingTest extends TestCase
|
||||
$this->assertSame(0, $usage->email_charged_minor);
|
||||
}
|
||||
|
||||
public function test_paid_email_charges_wallet_after_free_allowance(): void
|
||||
public function test_customer_email_skips_wallet_debit_after_free_allowance(): void
|
||||
{
|
||||
Mail::fake();
|
||||
Http::fake([
|
||||
'billing.test/can-afford*' => Http::response(['affordable' => true]),
|
||||
'billing.test/debit' => Http::response(['ok' => true]),
|
||||
'*/api/smtp/send' => Http::response(['success' => true]),
|
||||
]);
|
||||
|
||||
NotificationUsage::create([
|
||||
@@ -132,16 +147,17 @@ class FrontdeskNotificationBillingTest extends TestCase
|
||||
])
|
||||
->assertRedirect();
|
||||
|
||||
Http::assertSent(fn ($request) => str_contains($request->url(), '/debit'));
|
||||
Http::assertNotSent(fn ($request) => str_contains($request->url(), '/debit'));
|
||||
|
||||
$usage = NotificationUsage::where('organization_id', $this->organization->id)->first();
|
||||
$this->assertSame(101, $usage->email_count);
|
||||
$this->assertGreaterThan(0, $usage->email_charged_minor);
|
||||
$this->assertSame(0, $usage->email_charged_minor);
|
||||
}
|
||||
|
||||
public function test_insufficient_balance_skips_host_email(): void
|
||||
public function test_missing_bird_credentials_skips_host_email(): void
|
||||
{
|
||||
Mail::fake();
|
||||
MessagingCredential::query()->where('organization_id', $this->organization->id)->delete();
|
||||
|
||||
Http::fake([
|
||||
'billing.test/can-afford*' => Http::response(['affordable' => false]),
|
||||
]);
|
||||
@@ -169,15 +185,15 @@ class FrontdeskNotificationBillingTest extends TestCase
|
||||
])
|
||||
->assertRedirect();
|
||||
|
||||
Mail::assertNothingSent();
|
||||
Http::assertNotSent(fn ($request) => str_contains($request->url(), '/api/smtp/send'));
|
||||
}
|
||||
|
||||
public function test_kiosk_returns_host_notified_flag(): void
|
||||
{
|
||||
Mail::fake();
|
||||
Http::fake([
|
||||
'billing.test/can-afford*' => Http::response(['affordable' => true]),
|
||||
'billing.test/debit' => Http::response(['ok' => true]),
|
||||
'*/api/smtp/send' => Http::response(['success' => true]),
|
||||
]);
|
||||
|
||||
$host = Host::create([
|
||||
@@ -226,12 +242,12 @@ class FrontdeskNotificationBillingTest extends TestCase
|
||||
->assertSee('Upgrade to Pro');
|
||||
}
|
||||
|
||||
public function test_pro_plan_emails_are_unlimited(): void
|
||||
public function test_pro_plan_emails_record_usage_without_wallet_debit(): void
|
||||
{
|
||||
Mail::fake();
|
||||
Http::fake([
|
||||
'billing.test/can-afford*' => Http::response(['affordable' => true]),
|
||||
'billing.test/debit' => Http::response(['ok' => true]),
|
||||
'*/api/smtp/send' => Http::response(['success' => true]),
|
||||
]);
|
||||
|
||||
$this->organization->update([
|
||||
@@ -264,7 +280,7 @@ class FrontdeskNotificationBillingTest extends TestCase
|
||||
])
|
||||
->assertRedirect();
|
||||
|
||||
Mail::assertSent(\App\Mail\ContactMessageMail::class);
|
||||
Http::assertSent(fn ($request) => str_contains($request->url(), '/api/smtp/send'));
|
||||
Http::assertNotSent(fn ($request) => str_contains($request->url(), '/debit'));
|
||||
|
||||
$usage = NotificationUsage::where('organization_id', $this->organization->id)->first();
|
||||
@@ -275,10 +291,10 @@ class FrontdeskNotificationBillingTest extends TestCase
|
||||
public function test_linked_user_still_gets_in_app_notification(): void
|
||||
{
|
||||
Notification::fake();
|
||||
Mail::fake();
|
||||
Http::fake([
|
||||
'billing.test/can-afford*' => Http::response(['affordable' => true]),
|
||||
'billing.test/debit' => Http::response(['ok' => true]),
|
||||
'*/api/smtp/send' => Http::response(['success' => true]),
|
||||
]);
|
||||
|
||||
$linkedUser = User::create([
|
||||
|
||||
Reference in New Issue
Block a user