1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 13:34:04 +00:00
This commit is contained in:
Abrar Ahmad 2022-08-16 15:59:52 +05:00
parent f02aa1a6f2
commit 6ffa3d2b55

View file

@ -147,12 +147,12 @@ test('creating the resource in tenant database creates it in central database as
tenancy()->end(); tenancy()->end();
// Assert central user was created without `code` property // Assert central user and Resource user has exact same attributes and values
expect(CentralUser::first()->toArray())->toEqual(ResourceUser::first()->toArray()); expect(CentralUser::first()->toArray())->toEqual(ResourceUser::first()->toArray());
}); });
test('creating the resource in tenant database creates it in central database with default attributes values', function () { test('creating the resource in tenant database creates it in central database with default attributes values', function () {
// override method in ResourceUser class to return attribute values // override method in ResourceUser class to return attribute default values
class ResourceUserWithDefaultValues extends ResourceUser { class ResourceUserWithDefaultValues extends ResourceUser {
public function getResourceCreationAttributes(): array public function getResourceCreationAttributes(): array
{ {
@ -200,8 +200,8 @@ test('creating the resource in tenant database creates it in central database wi
public function getResourceCreationAttributes(): array public function getResourceCreationAttributes(): array
{ {
// Attributes used when creating resources from tenant to central DB // Attributes used when creating resources from tenant to central DB
// Notice here we are not adding "code" filed because it does // Notice here we are not adding "code" filed because it doesn't
// not exist in central model // exist in central model
return return
[ [
'global_id', 'global_id',
@ -262,14 +262,15 @@ test('creating the resource in central database creates it in tenant database as
$centralUser->tenants()->attach('t1'); $centralUser->tenants()->attach('t1');
$tenant->run(function () { $centralUser = CentralUser::first();
$tenant->run(function () use ($centralUser) {
expect(ResourceUser::all())->toHaveCount(1); expect(ResourceUser::all())->toHaveCount(1);
expect(ResourceUser::first()->global_id)->toBe('acme'); expect(ResourceUser::first()->toArray())->toEqual($centralUser->toArray());
}); });
}); });
test('creating the resource in central database creates it in tenant database with default attributes values', function () { test('creating the resource in central database creates it in tenant database with default attributes values', function () {
// override method in ResourceUser class to return attribute values // override method in CentralUser class to return attribute default values
class CentralUserWithDefaultValues extends CentralUser { class CentralUserWithDefaultValues extends CentralUser {
public function getResourceCreationAttributes(): array public function getResourceCreationAttributes(): array
{ {
@ -315,7 +316,7 @@ test('creating the resource in central database creates it in tenant database wi
}); });
test('creating the resource in central database creates it in tenant database with attributes names', function () { test('creating the resource in central database creates it in tenant database with attributes names', function () {
// override method in ResourceUser class to return attribute values // override method in CentralUser class to return attribute names
class CentralUserWithAttributeNames extends CentralUser { class CentralUserWithAttributeNames extends CentralUser {
public function getResourceCreationAttributes(): array public function getResourceCreationAttributes(): array
{ {
@ -331,7 +332,7 @@ test('creating the resource in central database creates it in tenant database wi
} }
} }
// migrate extra column in central DB // migrate extra column "foo" in central DB
pest()->artisan('migrate', [ pest()->artisan('migrate', [
'--path' => __DIR__ . '/Etc/synced_resource_migrations/users_extra', '--path' => __DIR__ . '/Etc/synced_resource_migrations/users_extra',
'--realpath' => true, '--realpath' => true,
@ -343,7 +344,7 @@ test('creating the resource in central database creates it in tenant database wi
'email' => 'john@localhost', 'email' => 'john@localhost',
'password' => 'secret', 'password' => 'secret',
'role' => 'commenter', 'role' => 'commenter',
'foo' => 'bar', // foo does not exist in resource 'foo' => 'bar', // foo does not exist in resource model
]); ]);
$tenant = ResourceTenant::create([ $tenant = ResourceTenant::create([