From daa1b907b026fcf26e1c3b9a600c0c13ed7485fe Mon Sep 17 00:00:00 2001 From: lukinovec Date: Mon, 24 Nov 2025 15:33:19 +0100 Subject: [PATCH] Test that `DeleteResourceMapping` works with `forceDelete()` --- tests/ResourceSyncingTest.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/ResourceSyncingTest.php b/tests/ResourceSyncingTest.php index ebd6ccfd..2f7417b0 100644 --- a/tests/ResourceSyncingTest.php +++ b/tests/ResourceSyncingTest.php @@ -966,6 +966,28 @@ test('pivot record is automatically deleted with the tenant resource', function( // Deleting tenant resource deletes its pivot record expect(DB::select("SELECT * FROM tenant_users WHERE tenant_id = ?", [$tenant->id]))->toHaveCount(0); + + // The same works with forceDelete + addExtraColumns(true); + + $syncMaster = CentralUserWithSoftDeletes::create([ + 'global_id' => 'force_cascade_user', + 'name' => 'Central user', + 'email' => 'central2@localhost', + 'password' => 'password', + 'role' => 'force_cascade_user', + 'foo' => 'bar', + ]); + + $syncMaster->tenants()->attach($tenant); + + expect(DB::select("SELECT * FROM tenant_users WHERE tenant_id = ?", [$tenant->id]))->toHaveCount(1); + + $tenant->run(function () { + TenantUserWithSoftDeletes::firstWhere('global_id', 'force_cascade_user')->forceDelete(); + }); + + expect(DB::select("SELECT * FROM tenant_users WHERE tenant_id = ?", [$tenant->id]))->toHaveCount(0); }); test('DeleteAllTenantMappings handles incorrect configuration correctly', function() {