mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 20:34:03 +00:00
wip
This commit is contained in:
parent
3e514461ca
commit
f02aa1a6f2
3 changed files with 9 additions and 9 deletions
|
|
@ -121,12 +121,12 @@ class UpdateSyncedResource extends QueueableListener
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getResourceCreationAttributes(Syncable $model): array
|
protected function getResourceCreationAttributes(Syncable $model): array
|
||||||
{
|
{
|
||||||
$attributes = $model->getAttributes();
|
$attributes = $model->getAttributes();
|
||||||
|
|
||||||
if ($model->getResourceCreationAttributes()) {
|
if ($model->getResourceCreationAttributes()) {
|
||||||
// If array is key-value, We assume default values are provided
|
// If function returned array is key-value, We assume default values are provided
|
||||||
// if array is plain values, fetch attributes from model
|
// if array is plain values, fetch attributes from model
|
||||||
$attributes = Arr::isAssoc($model->getResourceCreationAttributes()) ? $model->getResourceCreationAttributes() : $model->only($model->getResourceCreationAttributes());
|
$attributes = Arr::isAssoc($model->getResourceCreationAttributes()) ? $model->getResourceCreationAttributes() : $model->only($model->getResourceCreationAttributes());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
class AddExtraColumnToUsersTable extends Migration
|
class AddExtraColumnToCentralUsersTable extends Migration
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
|
|
@ -127,7 +127,7 @@ test('only the synced columns are updated in the central db', function () {
|
||||||
], ResourceUser::first()->getAttributes());
|
], ResourceUser::first()->getAttributes());
|
||||||
});
|
});
|
||||||
|
|
||||||
test('creating the resource in tenant database creates it in central database ad 1:1 copy when create attributes are null', function () {
|
test('creating the resource in tenant database creates it in central database as 1:1 copy when creation attributes are not specified', function () {
|
||||||
// Assert no user exists in central DB
|
// Assert no user exists in central DB
|
||||||
expect(ResourceUser::all())->toHaveCount(0);
|
expect(ResourceUser::all())->toHaveCount(0);
|
||||||
|
|
||||||
|
|
@ -151,7 +151,7 @@ test('creating the resource in tenant database creates it in central database ad
|
||||||
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 provided 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 values
|
||||||
class ResourceUserWithDefaultValues extends ResourceUser {
|
class ResourceUserWithDefaultValues extends ResourceUser {
|
||||||
public function getResourceCreationAttributes(): array
|
public function getResourceCreationAttributes(): array
|
||||||
|
|
@ -194,7 +194,7 @@ test('creating the resource in tenant database creates it in central database wi
|
||||||
expect(CentralUser::first()->role)->toBe('admin');
|
expect(CentralUser::first()->role)->toBe('admin');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('creating the resource in tenant database creates it in central database with provided attributes names', function () {
|
test('creating the resource in tenant database creates it in central database with attributes names', function () {
|
||||||
// override method in ResourceUser class to return attribute names
|
// override method in ResourceUser class to return attribute names
|
||||||
class ResourceUserWithAttributeNames extends ResourceUser {
|
class ResourceUserWithAttributeNames extends ResourceUser {
|
||||||
public function getResourceCreationAttributes(): array
|
public function getResourceCreationAttributes(): array
|
||||||
|
|
@ -242,7 +242,7 @@ test('creating the resource in tenant database creates it in central database wi
|
||||||
expect(CentralUser::first()->code)->toBeNull();
|
expect(CentralUser::first()->code)->toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('creating the resource in central database creates it in tenant database with 1:1 copy when create attributes are null', function () {
|
test('creating the resource in central database creates it in tenant database as 1:1 copy when creation attributes are not specified', function () {
|
||||||
$centralUser = CentralUser::create([
|
$centralUser = CentralUser::create([
|
||||||
'global_id' => 'acme',
|
'global_id' => 'acme',
|
||||||
'name' => 'John Doe',
|
'name' => 'John Doe',
|
||||||
|
|
@ -268,7 +268,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 provided 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 ResourceUser class to return attribute values
|
||||||
class CentralUserWithDefaultValues extends CentralUser {
|
class CentralUserWithDefaultValues extends CentralUser {
|
||||||
public function getResourceCreationAttributes(): array
|
public function getResourceCreationAttributes(): array
|
||||||
|
|
@ -314,7 +314,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 provided 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 ResourceUser class to return attribute values
|
||||||
class CentralUserWithAttributeNames extends CentralUser {
|
class CentralUserWithAttributeNames extends CentralUser {
|
||||||
public function getResourceCreationAttributes(): array
|
public function getResourceCreationAttributes(): array
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue