Ensure when merging, we purge empty contacts
(cherry picked from commit 75335ba8e4)
This commit is contained in:
parent
528f8c7b40
commit
79b014c752
2 changed files with 57 additions and 1 deletions
|
|
@ -59,7 +59,7 @@ class Merge extends AbstractService
|
|||
/* Loop through contacts an only merge distinct contacts by email */
|
||||
$this->mergable_client->contacts->each(function ($contact) {
|
||||
$exist = $this->client->contacts->contains(function ($client_contact) use ($contact) {
|
||||
return $client_contact->email == $contact->email;
|
||||
return $client_contact->email == $contact->email || empty($contact->email) || $contact->email == ' ';
|
||||
});
|
||||
|
||||
if ($exist) {
|
||||
|
|
|
|||
|
|
@ -63,6 +63,62 @@ class ClientTest extends TestCase
|
|||
$this->makeTestData();
|
||||
}
|
||||
|
||||
|
||||
public function testClientMergeContactDrop()
|
||||
{
|
||||
|
||||
$c = Client::factory()->create(['user_id' => $this->user->id, 'company_id' => $this->company->id]);
|
||||
|
||||
ClientContact::factory()->create([
|
||||
'user_id' => $this->user->id,
|
||||
'client_id' => $c->id,
|
||||
'company_id' => $this->company->id,
|
||||
'is_primary' => 1,
|
||||
]);
|
||||
|
||||
ClientContact::factory()->create([
|
||||
'user_id' => $this->user->id,
|
||||
'client_id' => $c->id,
|
||||
'company_id' => $this->company->id,
|
||||
]);
|
||||
|
||||
|
||||
$c1 = Client::factory()->create(['user_id' => $this->user->id, 'company_id' => $this->company->id]);
|
||||
|
||||
ClientContact::factory()->create([
|
||||
'user_id' => $this->user->id,
|
||||
'client_id' => $c1->id,
|
||||
'company_id' => $this->company->id,
|
||||
'is_primary' => 1,
|
||||
]);
|
||||
|
||||
ClientContact::factory()->create([
|
||||
'user_id' => $this->user->id,
|
||||
'client_id' => $c1->id,
|
||||
'company_id' => $this->company->id,
|
||||
]);
|
||||
|
||||
ClientContact::factory()->create([
|
||||
'user_id' => $this->user->id,
|
||||
'client_id' => $c1->id,
|
||||
'company_id' => $this->company->id,
|
||||
'email' => ''
|
||||
]);
|
||||
|
||||
|
||||
$this->assertEquals(2, $c->contacts->count());
|
||||
$this->assertEquals(3, $c1->contacts->count());
|
||||
|
||||
$c->service()->merge($c1);
|
||||
|
||||
$c = $c->fresh();
|
||||
|
||||
nlog($c->contacts->pluck('email'));
|
||||
|
||||
$this->assertEquals(4, $c->contacts->count());
|
||||
|
||||
}
|
||||
|
||||
private function buildLineItems($number = 2)
|
||||
{
|
||||
$line_items = [];
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue