Skip to content

Commit 5e3eb43

Browse files
committed
Test that updating pivot columns does not re-create the synced tenant resource
Regression test for #1467
1 parent 3156c87 commit 5e3eb43

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

tests/ResourceSyncingTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,32 @@
274274
});
275275
});
276276

277+
test('updating pivot column does not re-create the synced tenant resource', function () {
278+
// Add an extra pivot column so we can update it
279+
Schema::table('tenant_users', fn (Blueprint $table) => $table->string('note')->nullable());
280+
281+
$centralUser = CentralUser::create([
282+
'global_id' => 'acme',
283+
'name' => 'John Doe',
284+
'email' => 'john@localhost',
285+
'password' => 'secret',
286+
'role' => 'commenter',
287+
]);
288+
289+
$tenant = Tenant::create();
290+
migrateUsersTableForTenants();
291+
292+
// Attaching creates the tenant resource
293+
$centralUser->tenants()->attach($tenant);
294+
$tenant->run(fn () => expect(TenantUser::count())->toBe(1));
295+
296+
// Updating a pivot column does not re-attach and create the resource again
297+
// (which would throw a duplicate entry error -- regression test for #1467)
298+
$centralUser->tenants()->updateExistingPivot($tenant->getTenantKey(), ['note' => 'foo']);
299+
300+
$tenant->run(fn () => expect(TenantUser::count())->toBe(1));
301+
});
302+
277303
test('detaching central users from tenants or vice versa force deletes the synced tenant resource', function (bool $attachUserToTenant) {
278304
$centralUser = CentralUser::create([
279305
'global_id' => 'acme',

0 commit comments

Comments
 (0)