1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-08-06 12:04:04 +00:00

Test that updating pivot columns does not re-create the synced tenant resource

Regression test for https://github.com/archtechx/tenancy/issues/1467
This commit is contained in:
lukinovec 2026-07-07 12:35:03 +02:00
parent 3156c87ee3
commit 5e3eb4322c

View file

@ -274,6 +274,32 @@ test('attaching central resources to tenants or vice versa creates synced tenant
});
});
test('updating pivot column does not re-create the synced tenant resource', function () {
// Add an extra pivot column so we can update it
Schema::table('tenant_users', fn (Blueprint $table) => $table->string('note')->nullable());
$centralUser = CentralUser::create([
'global_id' => 'acme',
'name' => 'John Doe',
'email' => 'john@localhost',
'password' => 'secret',
'role' => 'commenter',
]);
$tenant = Tenant::create();
migrateUsersTableForTenants();
// Attaching creates the tenant resource
$centralUser->tenants()->attach($tenant);
$tenant->run(fn () => expect(TenantUser::count())->toBe(1));
// Updating a pivot column does not re-attach and create the resource again
// (which would throw a duplicate entry error -- regression test for #1467)
$centralUser->tenants()->updateExistingPivot($tenant->getTenantKey(), ['note' => 'foo']);
$tenant->run(fn () => expect(TenantUser::count())->toBe(1));
});
test('detaching central users from tenants or vice versa force deletes the synced tenant resource', function (bool $attachUserToTenant) {
$centralUser = CentralUser::create([
'global_id' => 'acme',