mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-06 05:04:03 +00:00
DisabledSync -> ConditionalSync; test both cases with dataset
This commit is contained in:
parent
15fa0b6157
commit
5d7eb9c50a
2 changed files with 18 additions and 17 deletions
3
t
Executable file
3
t
Executable file
|
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
docker-compose exec -T test vendor/bin/pest --no-coverage --filter "$@"
|
||||||
|
|
@ -763,15 +763,15 @@ function creatingResourceInTenantDatabaseCreatesAndMapInCentralDatabase()
|
||||||
expect(ResourceUser::first()->role)->toBe('commenter');
|
expect(ResourceUser::first()->role)->toBe('commenter');
|
||||||
}
|
}
|
||||||
|
|
||||||
test('resources are synced only when sync is enabled', function () {
|
test('resources are synced only when sync is enabled', function (bool $enabled) {
|
||||||
|
app()->instance('_tenancy_test_shouldSync', $enabled);
|
||||||
|
|
||||||
[$tenant1, $tenant2] = createTenantsAndRunMigrations();
|
[$tenant1, $tenant2] = createTenantsAndRunMigrations();
|
||||||
migrateUsersTableForTenants();
|
migrateUsersTableForTenants();
|
||||||
|
|
||||||
tenancy()->initialize($tenant1);
|
tenancy()->initialize($tenant1);
|
||||||
|
|
||||||
// Tenant model returns false from `shouldSync`
|
TenantUserWithConditionalSync::create([
|
||||||
// central model will not be created
|
|
||||||
TenantUserWithDisabledSync::create([
|
|
||||||
'global_id' => 'absd',
|
'global_id' => 'absd',
|
||||||
'name' => 'John Doe',
|
'name' => 'John Doe',
|
||||||
'email' => 'john@localhost',
|
'email' => 'john@localhost',
|
||||||
|
|
@ -781,10 +781,10 @@ test('resources are synced only when sync is enabled', function () {
|
||||||
|
|
||||||
tenancy()->end();
|
tenancy()->end();
|
||||||
|
|
||||||
expect(CentralUser::all())->toHaveCount(0);
|
expect(CentralUserWithConditionalSync::all())->toHaveCount($enabled ? 1 : 0);
|
||||||
expect(CentralUser::whereGlobalId('absd')->first())->toBeNull();
|
expect(CentralUserWithConditionalSync::whereGlobalId('absd')->exists())->toBe($enabled);
|
||||||
|
|
||||||
$centralUser = CentralUserWithDisabledSync::create([
|
$centralUser = CentralUserWithConditionalSync::create([
|
||||||
'global_id' => 'acme',
|
'global_id' => 'acme',
|
||||||
'name' => 'John Doe',
|
'name' => 'John Doe',
|
||||||
'email' => 'john@localhost',
|
'email' => 'john@localhost',
|
||||||
|
|
@ -792,15 +792,13 @@ test('resources are synced only when sync is enabled', function () {
|
||||||
'role' => 'commenter',
|
'role' => 'commenter',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// central model returns false from `shouldSync`
|
|
||||||
// resource model will not be created
|
|
||||||
$centralUser->tenants()->attach('t2');
|
$centralUser->tenants()->attach('t2');
|
||||||
|
|
||||||
$tenant2->run(function () {
|
$tenant2->run(function () use ($enabled) {
|
||||||
expect(ResourceUser::all())->toHaveCount(0);
|
expect(TenantUserWithConditionalSync::all())->toHaveCount($enabled ? 1 : 0);
|
||||||
expect(ResourceUser::whereGlobalId('acme')->first())->toBeNull();
|
expect(TenantUserWithConditionalSync::whereGlobalId('acme')->exists())->toBe($enabled);
|
||||||
});
|
});
|
||||||
});
|
})->with([[true], [false]]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create two tenants and run migrations for those tenants.
|
* Create two tenants and run migrations for those tenants.
|
||||||
|
|
@ -1019,18 +1017,18 @@ class ResourceUserProvidingMixture extends ResourceUser
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CentralUserWithDisabledSync extends CentralUser
|
class CentralUserWithConditionalSync extends CentralUser
|
||||||
{
|
{
|
||||||
public function shouldSync(): bool
|
public function shouldSync(): bool
|
||||||
{
|
{
|
||||||
return false;
|
return app('_tenancy_test_shouldSync');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TenantUserWithDisabledSync extends ResourceUser
|
class TenantUserWithConditionalSync extends ResourceUser
|
||||||
{
|
{
|
||||||
public function shouldSync(): bool
|
public function shouldSync(): bool
|
||||||
{
|
{
|
||||||
return false;
|
return app('_tenancy_test_shouldSync');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue