From 2248f0abac402f9e3f6ea8a96419a38352c406e0 Mon Sep 17 00:00:00 2001 From: vagrant Date: Wed, 24 Jan 2018 00:59:27 +0000 Subject: [PATCH 1/4] Finalize Tag unit test --- database/factories/ModelFactory.php | 1 - tests/Unit/SpecialDateTest.php | 4 ++-- tests/Unit/TagTest.php | 26 ++++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index 201fb297430..5ae787005cd 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -59,7 +59,6 @@ $factory->define(App\Contact::class, function (Faker\Generator $faker) { return [ - 'id' => 1, 'account_id' => 1, 'first_name' => 'John', 'last_name' => 'Doe', diff --git a/tests/Unit/SpecialDateTest.php b/tests/Unit/SpecialDateTest.php index 702c317e8c7..069233efcb2 100644 --- a/tests/Unit/SpecialDateTest.php +++ b/tests/Unit/SpecialDateTest.php @@ -201,7 +201,7 @@ public function test_set_contact_sets_the_contact_information() { $specialDate = factory(\App\SpecialDate::class)->make(); - $contact = factory(\App\Contact::class)->make(); + $contact = factory(\App\Contact::class)->create(); $specialDate->setToContact($contact); @@ -211,7 +211,7 @@ public function test_set_contact_sets_the_contact_information() ); $this->assertEquals( - 1, + $contact->id, $specialDate->contact_id ); } diff --git a/tests/Unit/TagTest.php b/tests/Unit/TagTest.php index 838865c9aef..73d674b1002 100644 --- a/tests/Unit/TagTest.php +++ b/tests/Unit/TagTest.php @@ -2,6 +2,8 @@ namespace Tests\Unit; +use App\Tag; +use App\Contact; use App\Account; use Tests\TestCase; use Illuminate\Foundation\Testing\DatabaseTransactions; @@ -20,4 +22,28 @@ public function test_it_belongs_to_an_account() $this->assertTrue($tag->account()->exists()); } + + public function test_it_belongs_to_many_contacts() + { + $account = factory(Account::class)->create([]); + $contact = factory('App\Contact')->create(['account_id' => $account->id]); + $tag = factory('App\Tag')->create(['account_id' => $account->id]); + $contact->tags()->sync($tag->id); + + $contact = factory('App\Contact')->create(['account_id' => $account->id]); + $tag = factory('App\Tag')->create(['account_id' => $account->id]); + $contact->tags()->sync($tag->id); + + $this->assertTrue($tag->contacts()->exists()); + } + + public function test_it_updates_the_slug() + { + $tag = factory(Tag::class)->create(['name' => 'this is great']); + $tag->updateSlug(); + $this->assertEquals( + 'this-is-great', + $tag->name_slug + ); + } } From 3ab096196eced562a01795d3ad71b4fdc3ccc4be Mon Sep 17 00:00:00 2001 From: Regis Freyd Date: Wed, 24 Jan 2018 22:32:26 -0500 Subject: [PATCH 2/4] Add unit test for Special Date model --- tests/Unit/SpecialDateTest.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/Unit/SpecialDateTest.php b/tests/Unit/SpecialDateTest.php index 069233efcb2..3fb2b34debb 100644 --- a/tests/Unit/SpecialDateTest.php +++ b/tests/Unit/SpecialDateTest.php @@ -12,6 +12,40 @@ class SpecialDateTest extends FeatureTestCase { use DatabaseTransactions; + public function test_it_belongs_to_an_account() + { + $account = factory('App\Account')->create([]); + $specialDate = factory('App\SpecialDate')->create([ + 'account_id' => $account->id, + ]); + + $this->assertTrue($specialDate->account()->exists()); + } + + public function test_it_belongs_to_a_contact() + { + $account = factory('App\Account')->create([]); + $contact = factory('App\Contact')->create([]); + $specialDate = factory('App\SpecialDate')->create([ + 'account_id' => $account->id, + 'contact_id' => $contact->id, + ]); + + $this->assertTrue($specialDate->contact()->exists()); + } + + public function test_it_belongs_to_a_reminder() + { + $account = factory('App\Account')->create([]); + $reminder = factory('App\Reminder')->create([]); + $specialDate = factory('App\SpecialDate')->create([ + 'account_id' => $account->id, + 'reminder_id' => $reminder->id, + ]); + + $this->assertTrue($specialDate->reminder()->exists()); + } + public function test_reminder_id_getter_returns_null_if_undefined() { $reminder = new Reminder; From 2492ef2702c72088ab73f020d17ea9c4d14301e1 Mon Sep 17 00:00:00 2001 From: Regis Freyd Date: Wed, 24 Jan 2018 22:55:06 -0500 Subject: [PATCH 3/4] More unit tests --- database/factories/ModelFactory.php | 16 +++++++++ tests/Unit/NoteTest.php | 45 +++++++++++++++++++++++ tests/Unit/OffspringTest.php | 23 ++++++++++++ tests/Unit/PetTest.php | 55 +++++++++++++++++++++++++++++ tests/Unit/ProgenitorTest.php | 21 +++++++++++ tests/Unit/RelationshipTest.php | 20 +++++++++++ tests/Unit/ReminderTest.php | 20 +++++++++++ 7 files changed, 200 insertions(+) create mode 100644 tests/Unit/OffspringTest.php create mode 100644 tests/Unit/PetTest.php create mode 100644 tests/Unit/ProgenitorTest.php diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index 5ae787005cd..b5b159deb97 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -151,12 +151,28 @@ ]; }); +$factory->define(App\Progenitor::class, function (Faker\Generator $faker) { + return [ + 'account_id' => 1, + ]; +}); + $factory->define(App\Tag::class, function (Faker\Generator $faker) { return [ 'account_id' => 1, ]; }); +$factory->define(App\Pet::class, function (Faker\Generator $faker) { + return [ + 'account_id' => 1, + ]; +}); + +$factory->define(App\PetCategory::class, function (Faker\Generator $faker) { + return []; +}); + $factory->define(App\ContactFieldType::class, function (Faker\Generator $faker) { return [ 'id' => 1, diff --git a/tests/Unit/NoteTest.php b/tests/Unit/NoteTest.php index 1b9aeb79395..66b5687b2b8 100644 --- a/tests/Unit/NoteTest.php +++ b/tests/Unit/NoteTest.php @@ -10,6 +10,51 @@ class NoteTest extends TestCase { use DatabaseTransactions; + public function test_it_belongs_to_an_account() + { + $account = factory('App\Account')->create([]); + $contact = factory('App\Contact')->create(['account_id' => $account->id]); + $note = factory('App\Note')->create([ + 'account_id' => $account->id, + ]); + + $this->assertTrue($note->account()->exists()); + } + + public function test_it_belongs_to_a_contact() + { + $contact = factory('App\Contact')->create([]); + $note = factory('App\Note')->create([ + 'contact_id' => $contact->id, + ]); + + $this->assertTrue($note->contact()->exists()); + } + + public function test_it_filters_by_favorited_notes() + { + $note = factory('App\Note')->create(['is_favorited' => true]); + $note = factory('App\Note')->create(['is_favorited' => true]); + $note = factory('App\Note')->create(['is_favorited' => false]); + $note = factory('App\Note')->create(['is_favorited' => true]); + + $this->assertEquals( + 3, + Note::favorited()->count() + ); + } + + public function test_it_returns_body_in_markdown() + { + $note = new Note; + $note->body = '# Test'; + + $this->assertEquals( + '

Test

', + $note->getParsedBodyAttribute() + ); + } + public function testGetBodyReturnsNullIfUndefined() { $note = new Note; diff --git a/tests/Unit/OffspringTest.php b/tests/Unit/OffspringTest.php new file mode 100644 index 00000000000..87e4054082d --- /dev/null +++ b/tests/Unit/OffspringTest.php @@ -0,0 +1,23 @@ +create([]); + $contact = factory('App\Contact')->create([]); + $offspring = factory('App\Offspring')->create([ + 'account_id' => $account->id, + 'contact_id' => $contact->id, + ]); + + $this->assertTrue($offspring->contact()->exists()); + } +} diff --git a/tests/Unit/PetTest.php b/tests/Unit/PetTest.php new file mode 100644 index 00000000000..7a97427ef10 --- /dev/null +++ b/tests/Unit/PetTest.php @@ -0,0 +1,55 @@ +create([]); + $contact = factory('App\Contact')->create(['account_id' => $account->id]); + $pet = factory('App\Pet')->create([ + 'account_id' => $account->id, + ]); + + $this->assertTrue($pet->account()->exists()); + } + + public function test_it_belongs_to_a_contact() + { + $contact = factory('App\Contact')->create([]); + $pet = factory('App\Pet')->create([ + 'contact_id' => $contact->id, + ]); + + $this->assertTrue($pet->contact()->exists()); + } + + public function test_it_belongs_to_a_pet_category() + { + $petCategory = factory('App\PetCategory')->create([]); + $pet = factory('App\Pet')->create([ + 'pet_category_id' => $petCategory->id, + ]); + + $this->assertTrue($pet->petCategory()->exists()); + } + + public function test_it_sets_name() + { + $pet = new Pet; + $this->assertNull($pet->name); + + $pet->name = 'henri'; + $this->assertEquals( + 'henri', + $pet->name + ); + } +} diff --git a/tests/Unit/ProgenitorTest.php b/tests/Unit/ProgenitorTest.php new file mode 100644 index 00000000000..8a086781950 --- /dev/null +++ b/tests/Unit/ProgenitorTest.php @@ -0,0 +1,21 @@ +create([]); + $progenitor = factory('App\Progenitor')->create([ + 'contact_id' => $contact->id, + ]); + + $this->assertTrue($progenitor->contact()->exists()); + } +} diff --git a/tests/Unit/RelationshipTest.php b/tests/Unit/RelationshipTest.php index 401fd480c81..660ca0594fd 100644 --- a/tests/Unit/RelationshipTest.php +++ b/tests/Unit/RelationshipTest.php @@ -9,6 +9,26 @@ class RelationshipTest extends TestCase { use DatabaseTransactions; + public function test_it_belongs_to_a_contact() + { + $contact = factory('App\Contact')->create([]); + $relationship = factory('App\Relationship')->create([ + 'contact_id' => $contact->id, + ]); + + $this->assertTrue($relationship->contact()->exists()); + } + + public function test_it_belongs_to_a_contact_through_with_contact_field() + { + $contact = factory('App\Contact')->create([]); + $relationship = factory('App\Relationship')->create([ + 'with_contact_id' => $contact->id, + ]); + + $this->assertTrue($relationship->with_contact()->exists()); + } + public function test_get_potential_partners_does_not_return_contacts_who_are_already_partner_with_the_contact() { $account = factory(\App\Account::class)->create(); diff --git a/tests/Unit/ReminderTest.php b/tests/Unit/ReminderTest.php index 05f85214dfe..f62b0b14ac3 100644 --- a/tests/Unit/ReminderTest.php +++ b/tests/Unit/ReminderTest.php @@ -11,6 +11,26 @@ class ReminderTest extends TestCase { use DatabaseTransactions; + public function test_it_belongs_to_an_account() + { + $account = factory('App\Account')->create([]); + $reminder = factory('App\Reminder')->create([ + 'account_id' => $account->id, + ]); + + $this->assertTrue($reminder->account()->exists()); + } + + public function test_it_belongs_to_a_contact() + { + $contact = factory('App\Contact')->create([]); + $reminder = factory('App\Reminder')->create([ + 'contact_id' => $contact->id, + ]); + + $this->assertTrue($reminder->contact()->exists()); + } + public function test_title_getter_returns_null_if_undefined() { $reminder = new Reminder; From aacd75dfdee2669534490ff3abbd3df86dbfa26d Mon Sep 17 00:00:00 2001 From: Regis Freyd Date: Wed, 24 Jan 2018 22:56:26 -0500 Subject: [PATCH 4/4] Fix styleci --- tests/Unit/TagTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Unit/TagTest.php b/tests/Unit/TagTest.php index 73d674b1002..c8959bf7264 100644 --- a/tests/Unit/TagTest.php +++ b/tests/Unit/TagTest.php @@ -3,7 +3,6 @@ namespace Tests\Unit; use App\Tag; -use App\Contact; use App\Account; use Tests\TestCase; use Illuminate\Foundation\Testing\DatabaseTransactions;