Skip to content

Commit

Permalink
feat: add notes when importing vcard (#5216)
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveitaly authored May 22, 2021
1 parent 8f0bbb1 commit 36912bc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/Services/VCard/ImportVCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use App\Helpers\VCardHelper;
use App\Models\Contact\Note;
use App\Helpers\LocaleHelper;
use App\Services\BaseService;
use function Safe\preg_split;
Expand Down Expand Up @@ -509,6 +510,7 @@ private function importEntry($contact, VCard $entry): Contact
$this->importTel($contact, $entry);
$this->importSocialProfile($contact, $entry);
$this->importCategories($contact, $entry);
$this->importNote($contact, $entry);

// Save vcard content
if ($contact->address_book_id) {
Expand Down Expand Up @@ -884,6 +886,24 @@ private function importEmail(Contact $contact, VCard $entry): void
}
}

/**
* @param Contact $contact
* @param VCard $entry
* @return void
*/
private function importNote(Contact $contact, VCard $entry): void
{
if (is_null($entry->NOTE)) {
return;
}

$note = Note::create([
'contact_id' => $contact->id,
'account_id' => $contact->account_id,
'body' => $entry->NOTE,
]);
}

/**
* @param Contact $contact
* @param VCard $entry
Expand Down
24 changes: 24 additions & 0 deletions tests/Unit/Services/VCard/ImportVCardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,30 @@ public function it_imports_categories()
]);
}

/** @test */
public function it_imports_notes()
{
$account = factory(Account::class)->create([]);
$contact = factory(Contact::class)->create([
'account_id' => $account->id,
]);

$importVCard = new ImportVCard;
$importVCard->accountId = $account->id;

$vcard = new VCard([
'NOTE' => 'a great note about this contact',
]);

$this->invokePrivateMethod($importVCard, 'importNote', [$contact, $vcard]);

$this->assertDatabaseHas('notes', [
'account_id' => $account->id,
'contact_id' => $contact->id,
'body' => 'a great note about this contact',
]);
}

/** @test */
public function it_imports_new_categories()
{
Expand Down

0 comments on commit 36912bc

Please sign in to comment.