From 457081c1ca013292652cd068a0913249e5ac80a4 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Sat, 16 Sep 2023 15:29:04 +0200 Subject: [PATCH] feat: add more vcard exports (#6878) --- .../Contact/ManageContact/Dav/ExportAdr.php | 45 ++++++++++ .../Dav/ExportContactInformation.php | 85 +++++++++++++++++++ .../ManageContact}/Dav/ExportGender.php | 4 +- .../Dav/ExportImportantDates.php | 46 ++++++++++ .../Contact/ManageContact/Dav/ExportNames.php | 3 + .../ManageContact/Dav/ExportTimestamp.php | 1 + .../Dav/ExportWorkInformation.php | 40 +++++++++ .../Web/ViewHelpers/ContactShowViewHelper.php | 4 + .../ManageGroups/Dav/ExportMembers.php | 1 + .../Services/CreateAddress.php | 8 +- .../Services/UpdateAddress.php | 8 +- database/factories/ContactFactory.php | 13 ++- .../ContactImportantDateTypeFactory.php | 2 +- .../ContactInformationTypeFactory.php | 2 +- server.php | 2 - .../ManageContact/Dav/ExportAdrTest.php | 48 +++++++++++ .../Dav/ExportContactInformationTest.php | 83 ++++++++++++++++++ .../ManageContact}/Dav/ExportGenderTest.php | 48 ++++------- .../Dav/ExportImportantDatesTest.php | 48 +++++++++++ .../ManageContact/Dav/ExportNamesTest.php | 16 ++-- .../Dav/ExportWorkInformationTest.php | 51 +++++++++++ .../ManageContact/Dav/ImportContactTest.php | 29 +++++-- .../ContactImportantDatesViewHelperTest.php | 2 +- .../ModuleImportantDatesViewHelperTest.php | 2 +- .../ModuleCompanyViewHelperTest.php | 2 +- .../Services/CreateAddressTest.php | 2 + .../Services/UpdateAddressTest.php | 2 + tests/Unit/Models/ContactTest.php | 5 +- 28 files changed, 532 insertions(+), 70 deletions(-) create mode 100644 app/Domains/Contact/ManageContact/Dav/ExportAdr.php create mode 100644 app/Domains/Contact/ManageContact/Dav/ExportContactInformation.php rename app/Domains/{Settings/ManageGenders => Contact/ManageContact}/Dav/ExportGender.php (90%) create mode 100644 app/Domains/Contact/ManageContact/Dav/ExportImportantDates.php create mode 100644 app/Domains/Contact/ManageContact/Dav/ExportWorkInformation.php create mode 100644 tests/Unit/Domains/Contact/ManageContact/Dav/ExportAdrTest.php create mode 100644 tests/Unit/Domains/Contact/ManageContact/Dav/ExportContactInformationTest.php rename tests/Unit/Domains/{Settings/ManageGenders => Contact/ManageContact}/Dav/ExportGenderTest.php (91%) create mode 100644 tests/Unit/Domains/Contact/ManageContact/Dav/ExportImportantDatesTest.php create mode 100644 tests/Unit/Domains/Contact/ManageContact/Dav/ExportWorkInformationTest.php diff --git a/app/Domains/Contact/ManageContact/Dav/ExportAdr.php b/app/Domains/Contact/ManageContact/Dav/ExportAdr.php new file mode 100644 index 00000000000..d7a3a0793a4 --- /dev/null +++ b/app/Domains/Contact/ManageContact/Dav/ExportAdr.php @@ -0,0 +1,45 @@ + + */ +#[Order(20)] +class ExportAdr implements ExportVCardResource +{ + public function getType(): string + { + return Contact::class; + } + + /** + * @param Contact $resource + */ + public function export(mixed $resource, VCard $vcard): void + { + $vcard->remove('ADR'); + + if (($addresses = $resource->addresses) !== null) { + foreach ($addresses as $address) { + // https://datatracker.ietf.org/doc/html/rfc6350#section-6.3.1 + $vcard->add('ADR', [ + '', + $address->line_1, + $address->line_2, + $address->city, + $address->province, + $address->postal_code, + $address->country, + ], $address->addressType ? [ + 'TYPE' => $address->addressType->name, + ] : []); + } + } + } +} diff --git a/app/Domains/Contact/ManageContact/Dav/ExportContactInformation.php b/app/Domains/Contact/ManageContact/Dav/ExportContactInformation.php new file mode 100644 index 00000000000..8cfe653da3d --- /dev/null +++ b/app/Domains/Contact/ManageContact/Dav/ExportContactInformation.php @@ -0,0 +1,85 @@ + + */ +#[Order(30)] +class ExportContactInformation extends Exporter implements ExportVCardResource +{ + public function getType(): string + { + return Contact::class; + } + + /** + * @param Contact $resource + */ + public function export(mixed $resource, VCard $vcard): void + { + $vcard->remove('TEL'); + $vcard->remove('EMAIL'); + $vcard->remove('socialProfile'); + $vcard->remove('URL'); + + $resource->contactInformations + ->each(fn ($contactInformation) => $this->addContactInformationToVCard($vcard, $contactInformation)); + } + + private function addContactInformationToVCard(VCard $vcard, ContactInformation $contactInformation) + { + switch ($contactInformation->contactInformationType->name) { + case trans('Email address'): + // https://datatracker.ietf.org/doc/html/rfc6350#section-6.4.2 + $vcard->add('EMAIL', $contactInformation->data, [ + // 'TYPE' => $contactInformation->contactInformationType->type, + ]); + break; + case trans('Phone'): + // https://datatracker.ietf.org/doc/html/rfc6350#section-6.4.1 + $vcard->add('TEL', $contactInformation->data, [ + //'TYPE' => $contactInformation->contactInformationType->type, + ]); + break; + case trans('Facebook'): + $vcard->add('socialProfile', $this->escape('https://www.facebook.com/'.$contactInformation->data), [ + 'TYPE' => 'facebook', + ]); + break; + case trans('Mastodon'): + $vcard->add('socialProfile', $this->escape($contactInformation->data), [ + 'TYPE' => 'Mastodon', + ]); + break; + case trans('Whatsapp'): + $vcard->add('socialProfile', $this->escape('https://wa.me/'.$contactInformation->data), [ + 'TYPE' => 'whatsapp', + ]); + break; + case trans('Telegram'): + $vcard->add('socialProfile', $this->escape('https://t.me/'.$contactInformation->data), [ + 'TYPE' => 'telegram', + ]); + break; + case trans('LinkedIn'): + $vcard->add('socialProfile', $this->escape('https://www.linkedin.com/in/'.$contactInformation->data), [ + 'TYPE' => 'linkedin', + ]); + break; + default: + // If field isn't a supported social profile, but still has a protocol, then export it as a url. + if (! empty($type = $contactInformation->contactInformationType->type)) { + $vcard->add('URL', $this->escape($type.$contactInformation->data)); + } + break; + } + } +} diff --git a/app/Domains/Settings/ManageGenders/Dav/ExportGender.php b/app/Domains/Contact/ManageContact/Dav/ExportGender.php similarity index 90% rename from app/Domains/Settings/ManageGenders/Dav/ExportGender.php rename to app/Domains/Contact/ManageContact/Dav/ExportGender.php index 48e4a658483..b1e6979d327 100644 --- a/app/Domains/Settings/ManageGenders/Dav/ExportGender.php +++ b/app/Domains/Contact/ManageContact/Dav/ExportGender.php @@ -1,6 +1,6 @@ add('GENDER', $gender); } } diff --git a/app/Domains/Contact/ManageContact/Dav/ExportImportantDates.php b/app/Domains/Contact/ManageContact/Dav/ExportImportantDates.php new file mode 100644 index 00000000000..bb84aa4493b --- /dev/null +++ b/app/Domains/Contact/ManageContact/Dav/ExportImportantDates.php @@ -0,0 +1,46 @@ + + */ +#[Order(40)] +class ExportImportantDates extends Exporter implements ExportVCardResource +{ + public function getType(): string + { + return Contact::class; + } + + /** + * @param Contact $resource + */ + public function export(mixed $resource, VCard $vcard): void + { + $vcard->remove('BDAY'); + + $resource->importantDates + ->each(fn ($importantDate) => $this->addImportantDateToVCard($vcard, $importantDate)); + } + + public function addImportantDateToVCard(VCard $vcard, ContactImportantDate $importantDate) + { + if (($type = $importantDate->contactImportantDateType) !== null && mb_strtolower($type->label) === ContactImportantDate::TYPE_BIRTHDATE) { + $date = $importantDate->year ? Str::padLeft((string) $importantDate->year, 2, '0') : '--'; + $date .= $importantDate->month ? Str::padLeft((string) $importantDate->month, 2, '0') : '--'; + $date .= $importantDate->day ? Str::padLeft((string) $importantDate->day, 2, '0') : '--'; + + // https://datatracker.ietf.org/doc/html/rfc6350#section-6.2.5 + $vcard->add('BDAY', $date); + } + } +} diff --git a/app/Domains/Contact/ManageContact/Dav/ExportNames.php b/app/Domains/Contact/ManageContact/Dav/ExportNames.php index d6a2b118f55..8cbe9a0a945 100644 --- a/app/Domains/Contact/ManageContact/Dav/ExportNames.php +++ b/app/Domains/Contact/ManageContact/Dav/ExportNames.php @@ -28,8 +28,10 @@ public function export(mixed $resource, VCard $vcard): void $vcard->remove('N'); $vcard->remove('NICKNAME'); + // https://datatracker.ietf.org/doc/html/rfc6350#section-6.2.1 $vcard->add('FN', $this->escape($resource->name)); + // https://datatracker.ietf.org/doc/html/rfc6350#section-6.2.2 $vcard->add('N', [ $this->escape($resource->last_name), $this->escape($resource->first_name), @@ -37,6 +39,7 @@ public function export(mixed $resource, VCard $vcard): void ]); if (! empty($resource->nickname)) { + // https://datatracker.ietf.org/doc/html/rfc6350#section-6.2.3 $vcard->add('NICKNAME', $this->escape($resource->nickname)); } } diff --git a/app/Domains/Contact/ManageContact/Dav/ExportTimestamp.php b/app/Domains/Contact/ManageContact/Dav/ExportTimestamp.php index 9f7ce5adf42..f5c5a5c013b 100644 --- a/app/Domains/Contact/ManageContact/Dav/ExportTimestamp.php +++ b/app/Domains/Contact/ManageContact/Dav/ExportTimestamp.php @@ -25,6 +25,7 @@ public function export(mixed $resource, VCard $vcard): void { $vcard->remove('REV'); + // https://datatracker.ietf.org/doc/html/rfc6350#section-6.7.4 $vcard->REV = $resource->updated_at->format('Ymd\\THis\\Z'); } } diff --git a/app/Domains/Contact/ManageContact/Dav/ExportWorkInformation.php b/app/Domains/Contact/ManageContact/Dav/ExportWorkInformation.php new file mode 100644 index 00000000000..19b0e256a22 --- /dev/null +++ b/app/Domains/Contact/ManageContact/Dav/ExportWorkInformation.php @@ -0,0 +1,40 @@ + + */ +#[Order(40)] +class ExportWorkInformation extends Exporter implements ExportVCardResource +{ + public function getType(): string + { + return Contact::class; + } + + /** + * @param Contact $resource + */ + public function export(mixed $resource, VCard $vcard): void + { + $vcard->remove('ORG'); + $vcard->remove('TITLE'); + + if (($company = $resource->company) !== null) { + // https://datatracker.ietf.org/doc/html/rfc6350#section-6.6.4 + $vcard->add('ORG', $this->escape($company->name)); + } + + if (! empty($resource->job_position)) { + // https://datatracker.ietf.org/doc/html/rfc6350#section-6.6.1 + $vcard->add('TITLE', $this->escape($resource->job_position)); + } + } +} diff --git a/app/Domains/Contact/ManageContact/Web/ViewHelpers/ContactShowViewHelper.php b/app/Domains/Contact/ManageContact/Web/ViewHelpers/ContactShowViewHelper.php index 5385f6a8149..0764e0b7886 100644 --- a/app/Domains/Contact/ManageContact/Web/ViewHelpers/ContactShowViewHelper.php +++ b/app/Domains/Contact/ManageContact/Web/ViewHelpers/ContactShowViewHelper.php @@ -142,6 +142,10 @@ public static function dataForTemplatePage(Contact $contact, User $user, Templat 'vault' => $contact->vault_id, 'contact' => $contact->id, ]), + 'download_vcard' => route('contact.vcard.download', [ + 'vault' => $contact->vault, + 'contact' => $contact, + ]), ], ]; } diff --git a/app/Domains/Contact/ManageGroups/Dav/ExportMembers.php b/app/Domains/Contact/ManageGroups/Dav/ExportMembers.php index 8117ff5d5cd..678a8b1654c 100644 --- a/app/Domains/Contact/ManageGroups/Dav/ExportMembers.php +++ b/app/Domains/Contact/ManageGroups/Dav/ExportMembers.php @@ -27,6 +27,7 @@ public function export($resource, VCard $vcard): void { $kind = collect($vcard->select('X-ADDRESSBOOKSERVER-KIND'))->first(); + // https://datatracker.ietf.org/doc/html/rfc6350#section-6.6.5 $this->exportType($resource, $vcard, $kind ? 'X-ADDRESSBOOKSERVER-MEMBER' : 'MEMBER'); } diff --git a/app/Domains/Vault/ManageAddresses/Services/CreateAddress.php b/app/Domains/Vault/ManageAddresses/Services/CreateAddress.php index ad911e2ed55..ea92263f998 100644 --- a/app/Domains/Vault/ManageAddresses/Services/CreateAddress.php +++ b/app/Domains/Vault/ManageAddresses/Services/CreateAddress.php @@ -75,8 +75,10 @@ public function execute(array $data): Address private function geocodeAddress(): void { - GetGPSCoordinate::dispatch([ - 'address_id' => $this->address->id, - ])->onQueue('low'); + if (config('monica.location_iq_api_key')) { + GetGPSCoordinate::dispatch([ + 'address_id' => $this->address->id, + ])->onQueue('low'); + } } } diff --git a/app/Domains/Vault/ManageAddresses/Services/UpdateAddress.php b/app/Domains/Vault/ManageAddresses/Services/UpdateAddress.php index c13406240aa..03f00a5a4b7 100644 --- a/app/Domains/Vault/ManageAddresses/Services/UpdateAddress.php +++ b/app/Domains/Vault/ManageAddresses/Services/UpdateAddress.php @@ -89,8 +89,10 @@ private function update(): void private function geocodeAddress(): void { - GetGPSCoordinate::dispatch([ - 'address_id' => $this->address->id, - ])->onQueue('low'); + if (config('monica.location_iq_api_key')) { + GetGPSCoordinate::dispatch([ + 'address_id' => $this->address->id, + ])->onQueue('low'); + } } } diff --git a/database/factories/ContactFactory.php b/database/factories/ContactFactory.php index 281fac651d6..538a7a5747a 100644 --- a/database/factories/ContactFactory.php +++ b/database/factories/ContactFactory.php @@ -29,7 +29,6 @@ public function definition() 'can_be_deleted' => true, 'prefix' => 'Dr.', 'suffix' => 'III', - 'company_id' => Company::factory(), 'gender_id' => fn (array $properties) => Gender::factory()->create([ 'account_id' => Vault::find($properties['vault_id'])->account_id, ])->getKey(), @@ -84,4 +83,16 @@ public function nickname() 'nickname' => $this->faker->unique()->firstName, ]); } + + /** + * Indicate that the contact has a job. + * + * @return \Illuminate\Database\Eloquent\Factories\Factory + */ + public function company() + { + return $this->state(fn () => [ + 'company_id' => Company::factory(), + ]); + } } diff --git a/database/factories/ContactImportantDateTypeFactory.php b/database/factories/ContactImportantDateTypeFactory.php index f252bdf9dbe..be4fb299673 100644 --- a/database/factories/ContactImportantDateTypeFactory.php +++ b/database/factories/ContactImportantDateTypeFactory.php @@ -23,7 +23,7 @@ public function definition() { return [ 'vault_id' => Vault::factory(), - 'label' => 'birthdate', + 'label' => 'Birthdate', 'internal_type' => ContactImportantDate::TYPE_BIRTHDATE, 'can_be_deleted' => true, ]; diff --git a/database/factories/ContactInformationTypeFactory.php b/database/factories/ContactInformationTypeFactory.php index aa4ff2bf490..4e34ad2eaac 100644 --- a/database/factories/ContactInformationTypeFactory.php +++ b/database/factories/ContactInformationTypeFactory.php @@ -23,7 +23,7 @@ public function definition() return [ 'account_id' => Account::factory(), 'name' => $this->faker->name(), - 'protocol' => '+tel', + 'protocol' => 'mailto:', 'can_be_deleted' => false, 'type' => 'email', ]; diff --git a/server.php b/server.php index 9063fb1b0de..b07fa44b32c 100644 --- a/server.php +++ b/server.php @@ -1,7 +1,5 @@ createUser(); + $vault = $this->createVaultUser($user); + $contact = Contact::factory()->random()->create(['vault_id' => $vault->id]); + $address = Address::factory()->create(['vault_id' => $vault->id]); + $address->contacts()->attach($contact->id); + + $vCard = new VCard(); + (new ExportAdr)->export($contact, $vCard); + + $this->assertCount( + self::defaultPropsCount + 1, + $vCard->children() + ); + + $text = "ADR;TYPE={$address->addressType->name}:;{$address->line_1};{$address->line_2};{$address->city};{$address->province};{$address->postal_code};{$address->country}"; + $this->assertStringContainsString(Str::substr($text, 0, 75), $vCard->serialize()); + $this->assertStringContainsString(Str::substr($text, 75), $vCard->serialize()); + } +} diff --git a/tests/Unit/Domains/Contact/ManageContact/Dav/ExportContactInformationTest.php b/tests/Unit/Domains/Contact/ManageContact/Dav/ExportContactInformationTest.php new file mode 100644 index 00000000000..133baf3ae62 --- /dev/null +++ b/tests/Unit/Domains/Contact/ManageContact/Dav/ExportContactInformationTest.php @@ -0,0 +1,83 @@ +createUser(); + $vault = $this->createVaultUser($user); + $contact = Contact::factory()->random()->create(['vault_id' => $vault->id]); + $type = ContactInformationType::factory()->create([ + 'account_id' => $vault->account_id, + 'name' => 'Email address', + ]); + $info = ContactInformation::factory()->create([ + 'contact_id' => $contact->id, + 'type_id' => $type->id, + 'data' => 'fake@email.com', + ]); + + $vCard = new VCard(); + (new ExportContactInformation)->export($contact, $vCard); + + $this->assertCount( + self::defaultPropsCount + 1, + $vCard->children() + ); + + $this->assertStringContainsString("EMAIL:{$info->data}", $vCard->serialize()); + } + + #[Group('dav')] + #[Test] + public function it_adds_tel_to_vcard() + { + $user = $this->createUser(); + $vault = $this->createVaultUser($user); + $contact = Contact::factory()->random()->create(['vault_id' => $vault->id]); + $type = ContactInformationType::factory()->create([ + 'account_id' => $vault->account_id, + 'name' => 'Phone', + 'type' => 'phone', + 'protocol' => 'tel:', + ]); + $info = ContactInformation::factory()->create([ + 'contact_id' => $contact->id, + 'type_id' => $type->id, + 'data' => '1234567890', + ]); + + $vCard = new VCard(); + (new ExportContactInformation)->export($contact, $vCard); + + $this->assertCount( + self::defaultPropsCount + 1, + $vCard->children() + ); + + $this->assertStringContainsString("TEL:{$info->data}", $vCard->serialize()); + } +} diff --git a/tests/Unit/Domains/Settings/ManageGenders/Dav/ExportGenderTest.php b/tests/Unit/Domains/Contact/ManageContact/Dav/ExportGenderTest.php similarity index 91% rename from tests/Unit/Domains/Settings/ManageGenders/Dav/ExportGenderTest.php rename to tests/Unit/Domains/Contact/ManageContact/Dav/ExportGenderTest.php index 4383cbbebaa..a951ea1557b 100644 --- a/tests/Unit/Domains/Settings/ManageGenders/Dav/ExportGenderTest.php +++ b/tests/Unit/Domains/Contact/ManageContact/Dav/ExportGenderTest.php @@ -1,11 +1,13 @@ createUser(); @@ -41,11 +40,8 @@ public function it_adds_gender_to_vcard() $this->assertStringContainsString("GENDER:{$contact->gender->type}", $vCard->serialize()); } - /** - * @group dav - * - * @test - */ + #[Group('dav')] + #[Test] public function it_adds_gender_female() { $user = $this->createUser(); @@ -70,11 +66,8 @@ public function it_adds_gender_female() $this->assertStringContainsString('GENDER:F', $vCard->serialize()); } - /** - * @group dav - * - * @test - */ + #[Group('dav')] + #[Test] public function it_adds_gender_unknown() { $user = $this->createUser(); @@ -98,11 +91,8 @@ public function it_adds_gender_unknown() $this->assertStringContainsString('GENDER:U', $vCard->serialize()); } - /** - * @group dav - * - * @test - */ + #[Group('dav')] + #[Test] public function it_adds_gender_type_null() { $user = $this->createUser(); @@ -127,11 +117,8 @@ public function it_adds_gender_type_null() $this->assertStringContainsString('GENDER:O', $vCard->serialize()); } - /** - * @group dav - * - * @test - */ + #[Group('dav')] + #[Test] public function it_adds_gender_type_null_male() { $user = $this->createUser(); @@ -156,11 +143,8 @@ public function it_adds_gender_type_null_male() $this->assertStringContainsString('GENDER:M', $vCard->serialize()); } - /** - * @group dav - * - * @test - */ + #[Group('dav')] + #[Test] public function it_adds_gender_type_null_female() { $user = $this->createUser(); diff --git a/tests/Unit/Domains/Contact/ManageContact/Dav/ExportImportantDatesTest.php b/tests/Unit/Domains/Contact/ManageContact/Dav/ExportImportantDatesTest.php new file mode 100644 index 00000000000..e20d299f24a --- /dev/null +++ b/tests/Unit/Domains/Contact/ManageContact/Dav/ExportImportantDatesTest.php @@ -0,0 +1,48 @@ +createUser(); + $vault = $this->createVaultUser($user); + $contact = Contact::factory()->random()->create([ + 'vault_id' => $vault->id, + ]); + $date = ContactImportantDate::factory()->create([ + 'contact_id' => $contact->id, + ]); + + $vCard = new VCard(); + (new ExportImportantDates)->export($contact, $vCard); + + $this->assertCount( + self::defaultPropsCount + 1, + $vCard->children() + ); + + $this->assertStringContainsString('BDAY:19811029', $vCard->serialize()); + } +} diff --git a/tests/Unit/Domains/Contact/ManageContact/Dav/ExportNamesTest.php b/tests/Unit/Domains/Contact/ManageContact/Dav/ExportNamesTest.php index 62a0dae6f55..47cf05c9d98 100644 --- a/tests/Unit/Domains/Contact/ManageContact/Dav/ExportNamesTest.php +++ b/tests/Unit/Domains/Contact/ManageContact/Dav/ExportNamesTest.php @@ -5,6 +5,8 @@ use App\Domains\Contact\ManageContact\Dav\ExportNames; use App\Models\Contact; use Illuminate\Foundation\Testing\DatabaseTransactions; +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\Test; use Sabre\VObject\Component\VCard; use Tests\TestCase; @@ -15,11 +17,8 @@ class ExportNamesTest extends TestCase /** @var int */ const defaultPropsCount = 3; - /** - * @group dav - * - * @test - */ + #[Group('dav')] + #[Test] public function it_adds_names_in_vcard() { $user = $this->createUser(); @@ -39,11 +38,8 @@ public function it_adds_names_in_vcard() $this->assertStringContainsString("N:{$contact->last_name};{$contact->first_name};;;", $vCard->serialize()); } - /** - * @group dav - * - * @test - */ + #[Group('dav')] + #[Test] public function it_adds_nickname_in_vcard() { $user = $this->createUser(); diff --git a/tests/Unit/Domains/Contact/ManageContact/Dav/ExportWorkInformationTest.php b/tests/Unit/Domains/Contact/ManageContact/Dav/ExportWorkInformationTest.php new file mode 100644 index 00000000000..92290554820 --- /dev/null +++ b/tests/Unit/Domains/Contact/ManageContact/Dav/ExportWorkInformationTest.php @@ -0,0 +1,51 @@ +createUser(); + $vault = $this->createVaultUser($user); + $company = Company::factory()->create([ + 'vault_id' => $vault->id, + ]); + $contact = Contact::factory()->random()->create([ + 'vault_id' => $vault->id, + 'company_id' => $company->id, + 'job_position' => 'random', + ]); + + $vCard = new VCard(); + (new ExportWorkInformation)->export($contact, $vCard); + + $this->assertCount( + self::defaultPropsCount + 2, + $vCard->children() + ); + + $this->assertStringContainsString("ORG:{$company->name}", $vCard->serialize()); + $this->assertStringContainsString("TITLE:{$contact->job_position}", $vCard->serialize()); + } +} diff --git a/tests/Unit/Domains/Contact/ManageContact/Dav/ImportContactTest.php b/tests/Unit/Domains/Contact/ManageContact/Dav/ImportContactTest.php index 9252fd7d871..380e53f4a0d 100644 --- a/tests/Unit/Domains/Contact/ManageContact/Dav/ImportContactTest.php +++ b/tests/Unit/Domains/Contact/ManageContact/Dav/ImportContactTest.php @@ -7,6 +7,8 @@ use App\Models\User; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Arr; +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\Test; use Sabre\VObject\Component\VCard; use Sabre\VObject\PHPUnitAssertions; use Tests\TestCase; @@ -16,7 +18,8 @@ class ImportContactTest extends TestCase use DatabaseTransactions, PHPUnitAssertions; - /** @test */ + #[Group('dav')] + #[Test] public function it_imports_names_N() { $importContact = new ImportContact(); @@ -31,7 +34,8 @@ public function it_imports_names_N() $this->assertEquals('Jane', $contact['middle_name']); } - /** @test */ + #[Group('dav')] + #[Test] public function it_imports_names_NICKNAME() { $importContact = new ImportContact(); @@ -44,7 +48,8 @@ public function it_imports_names_NICKNAME() $this->assertEquals('John', $contact['first_name']); } - /** @test */ + #[Group('dav')] + #[Test] public function it_imports_names_FN() { $author = User::factory()->create(); @@ -62,7 +67,8 @@ public function it_imports_names_FN() $this->assertEquals('Doe', $contact['last_name']); } - /** @test */ + #[Group('dav')] + #[Test] public function it_imports_names_FN_last() { $author = User::factory()->create([ @@ -82,7 +88,8 @@ public function it_imports_names_FN_last() $this->assertEquals('John', $contact['last_name']); } - /** @test */ + #[Group('dav')] + #[Test] public function it_imports_names_FN_extra_space() { $author = User::factory()->create(); @@ -100,7 +107,8 @@ public function it_imports_names_FN_extra_space() $this->assertEquals('Doe', $contact['last_name']); } - /** @test */ + #[Group('dav')] + #[Test] public function it_imports_name_FN() { $author = User::factory()->create(); @@ -119,7 +127,8 @@ public function it_imports_name_FN() $this->assertEquals('', Arr::get($contact, 'last_name')); } - /** @test */ + #[Group('dav')] + #[Test] public function it_imports_name_FN_last() { $author = User::factory()->create([ @@ -140,7 +149,8 @@ public function it_imports_name_FN_last() $this->assertEquals('', Arr::get($contact, 'first_name')); } - /** @test */ + #[Group('dav')] + #[Test] public function it_imports_names_FN_multiple() { $author = User::factory()->create(); @@ -159,7 +169,8 @@ public function it_imports_names_FN_multiple() $this->assertEquals('Doe Marco', $contact['last_name']); } - /** @test */ + #[Group('dav')] + #[Test] public function it_imports_uuid_default() { $importContact = new ImportContact(); diff --git a/tests/Unit/Domains/Contact/ManageContactImportantDates/Web/ViewHelpers/ContactImportantDatesViewHelperTest.php b/tests/Unit/Domains/Contact/ManageContactImportantDates/Web/ViewHelpers/ContactImportantDatesViewHelperTest.php index d6b2bd34bfa..88a5fceb667 100644 --- a/tests/Unit/Domains/Contact/ManageContactImportantDates/Web/ViewHelpers/ContactImportantDatesViewHelperTest.php +++ b/tests/Unit/Domains/Contact/ManageContactImportantDates/Web/ViewHelpers/ContactImportantDatesViewHelperTest.php @@ -78,7 +78,7 @@ public function it_gets_the_data_transfer_object(): void 'date' => 'Oct 29, 1981', 'type' => [ 'id' => $date->contactImportantDateType->id, - 'label' => 'birthdate', + 'label' => 'Birthdate', ], 'age' => '40', 'choice' => 'full_date', diff --git a/tests/Unit/Domains/Contact/ManageContactImportantDates/Web/ViewHelpers/ModuleImportantDatesViewHelperTest.php b/tests/Unit/Domains/Contact/ManageContactImportantDates/Web/ViewHelpers/ModuleImportantDatesViewHelperTest.php index 1f140b4649b..48efb921e92 100644 --- a/tests/Unit/Domains/Contact/ManageContactImportantDates/Web/ViewHelpers/ModuleImportantDatesViewHelperTest.php +++ b/tests/Unit/Domains/Contact/ManageContactImportantDates/Web/ViewHelpers/ModuleImportantDatesViewHelperTest.php @@ -44,7 +44,7 @@ public function it_gets_the_data_needed_for_the_view(): void 'id' => $date->id, 'label' => $date->label, 'date' => 'Oct 29, 1981', - 'type' => ContactImportantDate::TYPE_BIRTHDATE, + 'type' => 'Birthdate', 'age' => 36, ], ], diff --git a/tests/Unit/Domains/Contact/ManageJobInformation/Web/ViewHelpers/ModuleCompanyViewHelperTest.php b/tests/Unit/Domains/Contact/ManageJobInformation/Web/ViewHelpers/ModuleCompanyViewHelperTest.php index abc679bfbca..2834d372274 100644 --- a/tests/Unit/Domains/Contact/ManageJobInformation/Web/ViewHelpers/ModuleCompanyViewHelperTest.php +++ b/tests/Unit/Domains/Contact/ManageJobInformation/Web/ViewHelpers/ModuleCompanyViewHelperTest.php @@ -16,7 +16,7 @@ class ModuleCompanyViewHelperTest extends TestCase /** @test */ public function it_gets_the_data_needed_for_the_view(): void { - $contact = Contact::factory()->create([ + $contact = Contact::factory()->company()->create([ 'job_position' => 'CEO', ]); diff --git a/tests/Unit/Domains/Vault/ManageAddresses/Services/CreateAddressTest.php b/tests/Unit/Domains/Vault/ManageAddresses/Services/CreateAddressTest.php index dbb09739461..4c26dd74bfc 100644 --- a/tests/Unit/Domains/Vault/ManageAddresses/Services/CreateAddressTest.php +++ b/tests/Unit/Domains/Vault/ManageAddresses/Services/CreateAddressTest.php @@ -84,6 +84,8 @@ public function it_fails_if_type_is_not_in_the_account(): void private function executeService(User $author, Account $account, Vault $vault, AddressType $type): void { + config(['monica.location_iq_api_key' => '12345']); + Queue::fake(); $request = [ diff --git a/tests/Unit/Domains/Vault/ManageAddresses/Services/UpdateAddressTest.php b/tests/Unit/Domains/Vault/ManageAddresses/Services/UpdateAddressTest.php index 3161b6702ef..c4673c58e48 100644 --- a/tests/Unit/Domains/Vault/ManageAddresses/Services/UpdateAddressTest.php +++ b/tests/Unit/Domains/Vault/ManageAddresses/Services/UpdateAddressTest.php @@ -114,6 +114,8 @@ public function it_fails_if_address_does_not_exist(): void private function executeService(User $author, Account $account, Vault $vault, AddressType $type, Address $address): void { + config(['monica.location_iq_api_key' => '12345']); + Queue::fake(); $request = [ diff --git a/tests/Unit/Models/ContactTest.php b/tests/Unit/Models/ContactTest.php index 13dc08695fa..16163a3c17e 100644 --- a/tests/Unit/Models/ContactTest.php +++ b/tests/Unit/Models/ContactTest.php @@ -4,7 +4,6 @@ use App\Models\Address; use App\Models\Call; -use App\Models\Company; use App\Models\Contact; use App\Models\ContactImportantDate; use App\Models\ContactImportantDateType; @@ -170,9 +169,7 @@ public function it_has_many_loans_as_loanee(): void /** @test */ public function it_has_one_company() { - $contact = Contact::factory()->create([ - 'company_id' => Company::factory()->create(), - ]); + $contact = Contact::factory()->company()->create(); $this->assertTrue($contact->company()->exists()); }