test(user): soft-delete cascade + cross-tenant parent-child (Phase 5)
- UserSoftDeleteCascadeTest: verifies soft-delete cleans role_user, parent_child, license_assignments while keeping soft-deleted users row - cross-tenant parent-child attach test confirms withoutGlobalScope works Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>main
parent
6de4131389
commit
2fb1700075
|
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\License;
|
||||||
|
use App\Models\Tenant;
|
||||||
|
use App\Models\User;
|
||||||
|
use function Pest\Laravel\actingAs;
|
||||||
|
|
||||||
|
uses(\Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||||
|
|
||||||
|
it('soft-delete User bereinigt role_user, parent_child, license_assignments', function () {
|
||||||
|
$license = License::factory()->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);
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue