diff --git a/app/Domains/Settings/ManageAddressTypes/Services/CreateAddressType.php b/app/Domains/Settings/ManageAddressTypes/Services/CreateAddressType.php index 288958f6628..1a9d490733c 100644 --- a/app/Domains/Settings/ManageAddressTypes/Services/CreateAddressType.php +++ b/app/Domains/Settings/ManageAddressTypes/Services/CreateAddressType.php @@ -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; diff --git a/tests/Unit/Domains/Contact/ManageContact/Dav/ImportAddressTest.php b/tests/Unit/Domains/Contact/ManageContact/Dav/ImportAddressTest.php index 6c8c9af396e..f7c61f5a6ea 100644 --- a/tests/Unit/Domains/Contact/ManageContact/Dav/ImportAddressTest.php +++ b/tests/Unit/Domains/Contact/ManageContact/Dav/ImportAddressTest.php @@ -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()