mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 18:34:04 +00:00
Add feature that allow to determine when model is syncable
This commit is contained in:
parent
51228defc6
commit
9155e32ba8
4 changed files with 80 additions and 7 deletions
|
|
@ -89,6 +89,61 @@ class ResourceSyncingTest extends TestCase
|
|||
});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function resources_are_synced_only_sync_is_enabled()
|
||||
{
|
||||
CentralUser::create([
|
||||
'global_id' => 'acme',
|
||||
'name' => 'John Doe',
|
||||
'email' => 'john@localhost',
|
||||
'password' => 'secret',
|
||||
'role' => 'commenter', // synced
|
||||
]);
|
||||
|
||||
$tenant = ResourceTenant::create();
|
||||
$this->migrateTenants();
|
||||
|
||||
$tenant->run(function() {
|
||||
ResourceUser::create([
|
||||
'name' => 'Foo',
|
||||
'email' => 'foo@email.com',
|
||||
'password' => 'secret',
|
||||
'global_id' => 'acme',
|
||||
'role' => 'not_sync',
|
||||
]);
|
||||
});
|
||||
|
||||
$centralUser = CentralUser::first();
|
||||
$this->assertSame('John Doe', $centralUser->name); // not sync
|
||||
$this->assertSame('john@localhost', $centralUser->email); // not sync
|
||||
$this->assertSame('secret', $centralUser->password); // not sync
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function central_users_are_synced_only_sync_is_enabled()
|
||||
{
|
||||
$centralUser = CentralUser::create([
|
||||
'global_id' => 'acme',
|
||||
'name' => 'John Doe',
|
||||
'email' => 'john@localhost',
|
||||
'password' => 'secret',
|
||||
'role' => 'not_sync', // unsynced
|
||||
]);
|
||||
|
||||
$t1 = ResourceTenant::create([
|
||||
'id' => 't1',
|
||||
]);
|
||||
$this->migrateTenants();
|
||||
|
||||
$centralUser->tenants()->attach('t1');
|
||||
|
||||
$t1->run(function () {
|
||||
// assert user not exsits
|
||||
$this->assertCount(0, ResourceUser::all());
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function only_the_synced_columns_are_updated_in_the_central_db()
|
||||
{
|
||||
|
|
@ -626,6 +681,11 @@ class CentralUser extends Model implements SyncMaster
|
|||
'email',
|
||||
];
|
||||
}
|
||||
|
||||
public function isSyncEnabled()
|
||||
{
|
||||
return $this->role !== 'not_sync';
|
||||
}
|
||||
}
|
||||
|
||||
class ResourceUser extends Model implements Syncable
|
||||
|
|
@ -659,4 +719,9 @@ class ResourceUser extends Model implements Syncable
|
|||
'email',
|
||||
];
|
||||
}
|
||||
|
||||
public function isSyncEnabled()
|
||||
{
|
||||
return $this->role !== 'not_sync';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue