diff --git a/tests/Feature/User/UserSoftDeleteCascadeTest.php b/tests/Feature/User/UserSoftDeleteCascadeTest.php new file mode 100644 index 0000000..fc7695d --- /dev/null +++ b/tests/Feature/User/UserSoftDeleteCascadeTest.php @@ -0,0 +1,40 @@ +active()->create(); + $child = User::factory()->withRole('child')->withLicense($license)->create(); + $parent = User::factory()->withRole('parent')->create(); + + // Attach parent-child cross-tenant relation + $parent->children()->attach($child->id); + + $userId = $child->id; + $child->delete(); // soft-delete + + expect(\DB::table('role_user')->where('user_id', $userId)->count())->toBe(0); + expect(\DB::table('parent_child')->where('child_id', $userId)->count())->toBe(0); + expect(\DB::table('license_assignments')->where('user_id', $userId)->count())->toBe(0); + // Row still exists as soft-deleted + expect(\DB::table('users')->where('id', $userId)->whereNotNull('deleted_at')->count())->toBe(1); +}); + +it('cross-tenant parent-child attach möglich (Option B)', function () { + $tenant1 = Tenant::factory()->create(); + $tenant2 = Tenant::factory()->create(); + + $parent = User::factory()->for($tenant1)->withRole('parent')->create(); + $child = User::factory()->for($tenant2)->withRole('child')->create(); + + // Must work across tenants (parent_child has no tenant_id) + $parent->children()->attach($child->id); + + // Query children without TenantScope to verify + expect($parent->children()->count())->toBe(1); +});