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
2 changes: 1 addition & 1 deletion app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class User extends Authenticatable
{
use Notifiable,HasApiTokens;
use Notifiable, HasApiTokens;

/**
* The attributes that are mass assignable.
Expand Down
22 changes: 11 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions database/factories/ModelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@
];
});

$factory->define(App\Day::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\ContactFieldType::class, function (Faker\Generator $faker) {
return [
'id' => 1,
Expand Down
33 changes: 33 additions & 0 deletions tests/Unit/PetCategoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Tests\Unit;

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

class PetCategoryTest extends TestCase
{
use DatabaseTransactions;

public function test_it_gets_only_common_pets()
{
$petCategory = new PetCategory;

$this->assertEquals(
3,
$petCategory->common()->count()
);
}

public function test_it_gets_pet_category_name()
{
$petCategory = new PetCategory;
$petCategory->name = 'Rgis';

$this->assertEquals(
'Rgis',
$petCategory->name
);
}
}
8 changes: 7 additions & 1 deletion tests/Unit/ReminderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,14 @@ public function test_calculate_next_expected_date()
$reminder->next_expected_date = '1980-01-01 10:10:10';
$reminder->frequency_number = 1;

Carbon::setTestNow(Carbon::create(2017, 1, 1));
Carbon::setTestNow(Carbon::create(1980, 1, 1));
$reminder->frequency_type = 'week';
$this->assertEquals(
'1980-01-08',
$reminder->calculateNextExpectedDate($timezone)->next_expected_date->toDateString()
);

Carbon::setTestNow(Carbon::create(2017, 1, 1));
// from 1980, incrementing one week will lead to Jan 03, 2017
$reminder->frequency_type = 'week';
$this->assertEquals(
Expand Down
24 changes: 24 additions & 0 deletions tests/Unit/TagTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Tests\Unit;

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

class TagTest extends TestCase
{
use DatabaseTransactions;

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
);
}
}
50 changes: 50 additions & 0 deletions tests/Unit/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tests\Unit;

use App\User;
use App\Account;
use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseTransactions;

Expand Down Expand Up @@ -38,4 +39,53 @@ public function test_name_accessor_returns_name_in_the_user_preferred_way()
$user->name, 'Doe John'
);
}

public function test_it_gets_the_right_metric_symbol()
{
$user = new User;
$user->metric = 'fahrenheit';

$this->assertEquals(
'F', $user->getMetricSymbol()
);

$user->metric = 'celsius';
$this->assertEquals(
'C', $user->getMetricSymbol()
);
}

public function test_you_can_vote_if_you_havent_voted_yet_today()
{
$account = factory(Account::class)->create([]);
$user = factory('App\User')->create(['account_id' => $account->id]);

$this->assertFalse($user->hasAlreadyRatedToday());
}

public function test_you_cant_vote_if_you_have_already_voted_today()
{
$account = factory(Account::class)->create([]);
$user = factory('App\User')->create(['account_id' => $account->id]);
$day = factory('App\Day')->create([
'account_id' => $account->id,
'date' => \Carbon\Carbon::now(),
]);

$this->assertTrue($user->hasAlreadyRatedToday());
}

public function test_it_gets_2fa_secret_attribute()
{
$user = new User;

$this->assertNull($user->getGoogle2faSecretAttribute(null));

$string = 'pass1234';

$this->assertEquals(
$string,
$user->getGoogle2faSecretAttribute(encrypt($string))
);
}
}