Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion database/factories/ModelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -152,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,
Expand Down
45 changes: 45 additions & 0 deletions tests/Unit/NoteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'<h1>Test</h1>',
$note->getParsedBodyAttribute()
);
}

public function testGetBodyReturnsNullIfUndefined()
{
$note = new Note;
Expand Down
23 changes: 23 additions & 0 deletions tests/Unit/OffspringTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Tests\Unit;

use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class OffspringTest extends TestCase
{
use DatabaseTransactions;

public function test_it_belongs_to_a_contact()
{
$account = factory('App\Account')->create([]);
$contact = factory('App\Contact')->create([]);
$offspring = factory('App\Offspring')->create([
'account_id' => $account->id,
'contact_id' => $contact->id,
]);

$this->assertTrue($offspring->contact()->exists());
}
}
55 changes: 55 additions & 0 deletions tests/Unit/PetTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Tests\Unit;

use App\Pet;
use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class PetTest 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]);
$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
);
}
}
21 changes: 21 additions & 0 deletions tests/Unit/ProgenitorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Tests\Unit;

use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class ProgenitorTest extends TestCase
{
use DatabaseTransactions;

public function test_it_belongs_to_a_contact()
{
$contact = factory('App\Contact')->create([]);
$progenitor = factory('App\Progenitor')->create([
'contact_id' => $contact->id,
]);

$this->assertTrue($progenitor->contact()->exists());
}
}
20 changes: 20 additions & 0 deletions tests/Unit/RelationshipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
20 changes: 20 additions & 0 deletions tests/Unit/ReminderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
38 changes: 36 additions & 2 deletions tests/Unit/SpecialDateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -201,7 +235,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);

Expand All @@ -211,7 +245,7 @@ public function test_set_contact_sets_the_contact_information()
);

$this->assertEquals(
1,
$contact->id,
$specialDate->contact_id
);
}
Expand Down
25 changes: 25 additions & 0 deletions tests/Unit/TagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tests\Unit;

use App\Tag;
use App\Account;
use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseTransactions;
Expand All @@ -20,4 +21,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
);
}
}