Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin committed Nov 4, 2023
1 parent a50625c commit 1878197
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public function execute(array $data): AddressType

$type = AddressType::create([
'account_id' => $data['account_id'],
'name' => $data['name'] ?? null,
'name_translation_key' => $data['name_translation_key'] ?? null,
'name' => $this->valueOrNull($data, 'name'),
'name_translation_key' => $this->valueOrNull($data, 'name_translation_key'),
]);

return $type;
Expand Down
43 changes: 43 additions & 0 deletions tests/Unit/Domains/Contact/ManageContact/Dav/ImportAddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,49 @@ public function it_imports_address_type()
$this->assertEquals('home', $address->addressType->name);
}

#[Group('dav')]
#[Test]
public function it_imports_new_address_type()
{
$user = $this->createAdministrator();
$vault = $this->createVaultUser($user, Vault::PERMISSION_MANAGE);
$importVCard = new ImportVCard();
$importVCard->author = $user;
$importVCard->vault = $vault;
$importer = new ImportAddress();
$importer->setContext($importVCard);

$contact = Contact::factory()->create([
'vault_id' => $vault->id,
]);

$vcard = new VCard();
$vcard->add('ADR', [
'',
'line 1',
'line 2',
'city',
'province',
'postal code',
'country',
], [
'TYPE' => 'home',
]);

$contact = $importer->import($vcard, $contact);

$this->assertCount(1, $contact->addresses);
$address = $contact->addresses->first();

$this->assertDatabaseHas('address_types', [
'account_id' => $user->account_id,
'name' => 'home',
]);

$this->assertNotNull($address->addressType);
$this->assertEquals('home', $address->addressType->name);
}

#[Group('dav')]
#[Test]
public function it_imports_new_address_and_remove_old()
Expand Down

0 comments on commit 1878197

Please sign in to comment.