From e81e6ac6518e7fc8753d6be4c913b9417fbcdec2 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Tue, 28 Apr 2026 12:47:42 +0200 Subject: [PATCH] Add regression test for jobs recognizing pending tenants Reverting the HasPending changes (in createPending(), create tenant without pending_since, and only after that, update the tenant to give it pending_since) makes the test fail. --- tests/PendingTenantsTest.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/PendingTenantsTest.php b/tests/PendingTenantsTest.php index 36c9203c..c2886008 100644 --- a/tests/PendingTenantsTest.php +++ b/tests/PendingTenantsTest.php @@ -336,3 +336,34 @@ test('pending tenant databases can be seeded using a job unless configured other 'seed with pending' => [true], 'seed without pending' => [false], ]); + +test('jobs that run before tenants get fully created recognize pending tenants', function () { + config([ + 'tenancy.bootstrappers' => [DatabaseTenancyBootstrapper::class], + ]); + + Event::listen(TenancyInitialized::class, BootstrapTenancy::class); + Event::listen(TenancyEnded::class, RevertToCentralContext::class); + Event::listen(TenantCreated::class, JobPipeline::make([ + CreateDatabase::class, + PendingTenantJob::class, + ])->send(function (TenantCreated $event) { + return $event->tenant; + })->toListener()); + + Tenant::createPending(); + + expect(app('tenant_is_pending'))->toBeTrue(); +}); + +class PendingTenantJob +{ + public function __construct( + public Tenant $tenant, + ) {} + + public function handle() + { + app()->instance('tenant_is_pending', $this->tenant->pending()); + } +}