From f02aa1a6f2a5cfe1b593e2d155f15f872e3a2ef1 Mon Sep 17 00:00:00 2001 From: Abrar Ahmad Date: Tue, 16 Aug 2022 15:50:22 +0500 Subject: [PATCH] wip --- src/Listeners/UpdateSyncedResource.php | 4 ++-- ...0009_add_extra_column_to_central_users_table.php} | 2 +- tests/ResourceSyncingTest.php | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) rename tests/Etc/synced_resource_migrations/users_extra/{2019_08_08_000009_add_extra_column_to_users_table.php => 2019_08_08_000009_add_extra_column_to_central_users_table.php} (87%) diff --git a/src/Listeners/UpdateSyncedResource.php b/src/Listeners/UpdateSyncedResource.php index 123298f8..b11cad57 100644 --- a/src/Listeners/UpdateSyncedResource.php +++ b/src/Listeners/UpdateSyncedResource.php @@ -121,12 +121,12 @@ class UpdateSyncedResource extends QueueableListener }); } - function getResourceCreationAttributes(Syncable $model): array + protected function getResourceCreationAttributes(Syncable $model): array { $attributes = $model->getAttributes(); 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 $attributes = Arr::isAssoc($model->getResourceCreationAttributes()) ? $model->getResourceCreationAttributes() : $model->only($model->getResourceCreationAttributes()); } diff --git a/tests/Etc/synced_resource_migrations/users_extra/2019_08_08_000009_add_extra_column_to_users_table.php b/tests/Etc/synced_resource_migrations/users_extra/2019_08_08_000009_add_extra_column_to_central_users_table.php similarity index 87% rename from tests/Etc/synced_resource_migrations/users_extra/2019_08_08_000009_add_extra_column_to_users_table.php rename to tests/Etc/synced_resource_migrations/users_extra/2019_08_08_000009_add_extra_column_to_central_users_table.php index 54977000..bfa13cc1 100644 --- a/tests/Etc/synced_resource_migrations/users_extra/2019_08_08_000009_add_extra_column_to_users_table.php +++ b/tests/Etc/synced_resource_migrations/users_extra/2019_08_08_000009_add_extra_column_to_central_users_table.php @@ -6,7 +6,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class AddExtraColumnToUsersTable extends Migration +class AddExtraColumnToCentralUsersTable extends Migration { /** * Run the migrations. diff --git a/tests/ResourceSyncingTest.php b/tests/ResourceSyncingTest.php index 6326985b..d1e20556 100644 --- a/tests/ResourceSyncingTest.php +++ b/tests/ResourceSyncingTest.php @@ -127,7 +127,7 @@ test('only the synced columns are updated in the central db', function () { ], 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 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()); }); -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 class ResourceUserWithDefaultValues extends ResourceUser { 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'); }); -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 class ResourceUserWithAttributeNames extends ResourceUser { 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(); }); -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([ 'global_id' => 'acme', '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 class CentralUserWithDefaultValues extends CentralUser { 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 class CentralUserWithAttributeNames extends CentralUser { public function getResourceCreationAttributes(): array