create(); $this->assertTrue($contact->vault()->exists()); } /** @test */ public function it_has_one_gender() { $contact = Contact::factory()->create([ 'gender_id' => Gender::factory()->create(), ]); $this->assertTrue($contact->gender()->exists()); } /** @test */ public function it_has_one_pronoun() { $contact = Contact::factory()->create([ 'pronoun_id' => Pronoun::factory()->create(), ]); $this->assertTrue($contact->pronoun()->exists()); } /** @test */ public function it_has_one_template() { $contact = Contact::factory()->create([ 'template_id' => Template::factory()->create(), ]); $this->assertTrue($contact->template()->exists()); } /** @test */ public function it_has_many_relationships(): void { $contact = Contact::factory()->create([]); $monica = Contact::factory()->create(); $relationshipType = RelationshipType::factory()->create(); $contact->relationships()->sync([$monica->id => ['relationship_type_id' => $relationshipType->id]]); $this->assertTrue($contact->relationships()->exists()); } /** @test */ public function it_has_many_labels(): void { $contact = Contact::factory()->create([]); $label = Label::factory()->create(); $contact->labels()->sync([$label->id]); $this->assertTrue($contact->labels()->exists()); } /** @test */ public function it_has_many_contact_information(): void { $contact = Contact::factory()->create(); ContactInformation::factory()->count(2)->create([ 'contact_id' => $contact->id, ]); $this->assertTrue($contact->contactInformations()->exists()); } /** @test */ public function it_has_many_notes(): void { $contact = Contact::factory()->create(); Note::factory()->count(2)->create([ 'contact_id' => $contact->id, ]); $this->assertTrue($contact->notes()->exists()); } /** @test */ public function it_has_many_dates(): void { $contact = Contact::factory()->create(); ContactImportantDate::factory()->count(2)->create([ 'contact_id' => $contact->id, ]); $this->assertTrue($contact->importantDates()->exists()); } /** @test */ public function it_has_many_reminders(): void { $contact = Contact::factory()->create(); ContactReminder::factory()->count(2)->create([ 'contact_id' => $contact->id, ]); $this->assertTrue($contact->reminders()->exists()); } /** @test */ public function it_has_many_loans_as_loaner(): void { $contact = Contact::factory()->create([]); $monica = Contact::factory()->create(); $loan = Loan::factory()->create(); $contact->loansAsLoaner()->sync([$loan->id => ['loanee_id' => $monica->id]]); $this->assertTrue($contact->loansAsLoaner()->exists()); } /** @test */ public function it_has_many_loans_as_loanee(): void { $contact = Contact::factory()->create([]); $monica = Contact::factory()->create(); $loan = Loan::factory()->create(); $contact->loansAsLoanee()->sync([$loan->id => ['loaner_id' => $monica->id]]); $this->assertTrue($contact->loansAsLoanee()->exists()); } /** @test */ public function it_has_one_company() { $contact = Contact::factory()->company()->create(); $this->assertTrue($contact->company()->exists()); } /** @test */ public function it_has_many_tasks(): void { $contact = Contact::factory()->create(); ContactTask::factory()->count(2)->create([ 'contact_id' => $contact->id, ]); $this->assertTrue($contact->tasks()->exists()); } /** @test */ public function it_has_many_calls(): void { $contact = Contact::factory()->create(); Call::factory()->count(2)->create([ 'contact_id' => $contact->id, ]); $this->assertTrue($contact->calls()->exists()); } /** @test */ public function it_has_many_pets(): void { $contact = Contact::factory()->create(); Pet::factory()->count(2)->create([ 'contact_id' => $contact->id, ]); $this->assertTrue($contact->pets()->exists()); } /** @test */ public function it_has_many_goals(): void { $contact = Contact::factory()->create(); Goal::factory()->count(2)->create([ 'contact_id' => $contact->id, ]); $this->assertTrue($contact->goals()->exists()); } /** @test */ public function it_has_many_files(): void { $contact = Contact::factory()->create(); File::factory()->count(2)->create([ 'ufileable_id' => $contact->id, 'fileable_type' => Contact::class, ]); $this->assertTrue($contact->files()->exists()); } /** @test */ public function it_has_one_file(): void { $contact = Contact::factory()->create(); $file = File::factory()->create(); $contact->file_id = $file->id; $contact->save(); $this->assertTrue($contact->file()->exists()); } /** @test */ public function it_has_many_groups(): void { $contact = Contact::factory()->create(); $group = Group::factory()->create(); $contact->groups()->sync([$group->id]); $this->assertTrue($contact->groups()->exists()); } /** @test */ public function it_has_many_posts(): void { $contact = Contact::factory()->create(); $post = Post::factory()->create(); $contact->posts()->sync([$post->id]); $this->assertTrue($contact->posts()->exists()); } /** @test */ public function it_has_one_religion(): void { $contact = Contact::factory()->create(); $religion = Religion::factory()->create(); $contact->religion_id = $religion->id; $contact->save(); $this->assertTrue($contact->religion()->exists()); } /** @test */ public function it_has_many_life_events(): void { $contact = Contact::factory()->create(); $lifeEvent = LifeEvent::factory()->create(); $contact->lifeEvents()->sync([$lifeEvent->id]); $this->assertTrue($contact->lifeEvents()->exists()); } /** @test */ public function it_has_many_timeline_events(): void { $contact = Contact::factory()->create(); $timelineEvent = TimelineEvent::factory()->create(); $contact->timelineEvents()->sync([$timelineEvent->id]); $this->assertTrue($contact->timelineEvents()->exists()); } /** @test */ public function it_has_many_mood_tracking_events(): void { $contact = Contact::factory()->create(); MoodTrackingEvent::factory()->count(2)->create([ 'contact_id' => $contact->id, ]); $this->assertTrue($contact->moodTrackingEvents()->exists()); } /** @test */ public function it_has_many_addresses(): void { $contact = Contact::factory()->create([]); $address = Address::factory()->create(); $contact->addresses()->sync([$address->id => ['is_past_address' => false]]); $this->assertTrue($contact->addresses()->exists()); } /** @test */ public function it_has_many_quick_facts(): void { $contact = Contact::factory()->create([]); QuickFact::factory()->create(['contact_id' => $contact->id]); $this->assertTrue($contact->quickFacts()->exists()); } /** @test */ public function it_has_many_life_metrics(): void { $contact = Contact::factory()->create([]); $lifeMetric = LifeMetric::factory()->create(); $contact->lifeMetrics()->sync([$lifeMetric->id]); $this->assertTrue($contact->lifeMetrics()->exists()); } /** @test */ public function it_gets_the_name(): void { $user = User::factory()->create([ 'name_order' => '%first_name%', ]); $this->be($user); $contact = Contact::factory()->create([ 'first_name' => 'James', 'last_name' => 'Bond', 'nickname' => '007', 'middle_name' => 'W.', 'maiden_name' => 'Muller', ]); $this->assertEquals( 'Dr. James III', $contact->name ); $user->update(['name_order' => '%last_name%']); $this->assertEquals( 'Dr. Bond III', $contact->name ); $user->update(['name_order' => '%first_name% %last_name%']); $this->assertEquals( 'Dr. James Bond III', $contact->name ); $user->update(['name_order' => '%first_name% (%maiden_name%) %last_name%']); $this->assertEquals( 'Dr. James (Muller) Bond III', $contact->name ); $user->update(['name_order' => '%last_name% (%maiden_name%) || (%nickname%) || %first_name%']); $this->assertEquals( 'Dr. Bond (Muller) || (007) || James III', $contact->name ); } /** @test */ public function it_gets_the_age(): void { Carbon::setTestNow(Carbon::create(2022, 1, 1)); $contact = Contact::factory()->create(); $type = ContactImportantDateType::factory()->create([ 'vault_id' => $contact->vault_id, 'internal_type' => ContactImportantDate::TYPE_BIRTHDATE, ]); $this->assertNull( $contact->age ); ContactImportantDate::factory()->create([ 'contact_id' => $contact->id, 'contact_important_date_type_id' => $type->id, 'day' => 1, 'month' => 10, 'year' => 2000, ]); $contact->refresh(); $this->assertEquals( 21, $contact->age ); } /** @test */ public function it_gets_the_avatar(): void { $contact = Contact::factory()->create([ 'first_name' => 'Regis', 'last_name' => 'Troyat', ]); $this->assertEquals( [ 'type' => 'svg', 'content' => '', ], $contact->avatar ); $file = File::factory()->create([ 'uuid' => 123, ]); $contact->file_id = $file->id; $contact->save(); $contact->refresh(); $this->assertEquals( [ 'type' => 'url', 'content' => 'https://ucarecdn.com/123/-/scale_crop/300x300/smart/-/format/auto/-/quality/smart_retina/', ], $contact->avatar ); } }