From 4bc82b535af29eb9a96469bba9bc53534d0a82df Mon Sep 17 00:00:00 2001 From: Ion Caliman Date: Wed, 21 Jun 2023 18:56:20 +0300 Subject: [PATCH] Added a failing test: Duplicate entry --- tests/ResourceSyncingTest.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/ResourceSyncingTest.php b/tests/ResourceSyncingTest.php index 570448d1..835bc1f2 100644 --- a/tests/ResourceSyncingTest.php +++ b/tests/ResourceSyncingTest.php @@ -180,6 +180,38 @@ class ResourceSyncingTest extends TestCase $this->assertSame('commenter', ResourceUser::first()->role); } + /** @test */ + public function creating_the_resource_in_tenant_database_creates_it_in_central_database_when_id_already_exists() + { + CentralUser::create([ + 'name' => 'John Central', + 'email' => 'john@central', + 'password' => 'secret', + 'role' => 'employee', + ]); + + // Assert no user in central DB + $this->assertCount(1, CentralUser::all()); + + $tenant = ResourceTenant::create(); + $this->migrateTenants(); + + tenancy()->initialize($tenant); + + // Create the same user in tenant DB + ResourceUser::create([ + 'global_id' => 'acme', + 'name' => 'John Doe', + 'email' => 'john@localhost', + 'password' => 'secret', + 'role' => 'commenter', // unsynced + ]); + + tenancy()->end(); + + $this->assertCount(2, CentralUser::all()); + } + /** @test */ public function trying_to_update_synced_resources_from_central_context_using_tenant_models_results_in_an_exception() {