1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 04:34:03 +00:00

Make test clearer

This commit is contained in:
lukinovec 2025-06-09 10:33:42 +02:00
parent b326ebb718
commit f3f583b027

View file

@ -110,12 +110,12 @@ afterEach(function () {
UpdateOrCreateSyncedResource::$scopeGetModelQuery = null; UpdateOrCreateSyncedResource::$scopeGetModelQuery = null;
}); });
test('resources created with the same global id in different tenant dbs will be synced to a single central resource', function () { test('creating multiple tenant resources with the same global_id only creates corresponding central resource if it does not exist yet', function () {
$tenants = [Tenant::create(), Tenant::create(), Tenant::create()]; $tenants = [Tenant::create(), Tenant::create(), Tenant::create()];
migrateUsersTableForTenants(); migrateUsersTableForTenants();
// Only a single central user is created since the same global_id is used for each tenant user // While creating a tenant resource with global_id 'acme',
// Therefore all of these tenant users are synced to a single global user // a corresponding central resource is attempted to be created ONLY ONCE.
tenancy()->runForMultiple($tenants, function () { tenancy()->runForMultiple($tenants, function () {
// Create a user with the same global_id in each tenant DB // Create a user with the same global_id in each tenant DB
TenantUser::create([ TenantUser::create([
@ -127,7 +127,8 @@ test('resources created with the same global id in different tenant dbs will be
]); ]);
}); });
// Only a single central user is created // Only a single central user is created.
// No duplicate global_id exception is thrown.
expect(CentralUser::all())->toHaveCount(1); expect(CentralUser::all())->toHaveCount(1);
expect(CentralUser::first()->global_id)->toBe('acme'); expect(CentralUser::first()->global_id)->toBe('acme');
}); });