mirror of
https://github.com/archtechx/tenancy.git
synced 2026-08-06 05:54:03 +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:
parent
3156c87ee3
commit
5e3eb4322c
1 changed files with 26 additions and 0 deletions
|
|
@ -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',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue