Skip to content

Commit

Permalink
fix: exclude partials from contact limit (#2058)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbirrell authored and asbiin committed Nov 20, 2018
1 parent 3a5a7d1 commit 5823d77
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/Models/Account/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ public function hasLimitations()
*/
public function hasReachedContactLimit()
{
return $this->contacts->count() >= config('monica.number_of_allowed_contacts_free_account');
return $this->contacts()->real()->count() >= config('monica.number_of_allowed_contacts_free_account');
}

/**
Expand Down
3 changes: 3 additions & 0 deletions database/factories/ModelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@
},
];
});
$factory->state(App\Models\Contact\Contact::class, 'partial', [
'is_partial' => 1,
]);

$factory->define(App\Models\Contact\Gift::class, function (Faker\Generator $faker) {
return [
Expand Down
9 changes: 9 additions & 0 deletions tests/Unit/Models/AccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,15 @@ public function test_account_has_reached_contact_limit_on_free_plan()
$account->hasReachedContactLimit()
);

$partials = factory(Contact::class, 5)->state('partial')->create([
'account_id' => $account->id,
]);

config(['monica.number_of_allowed_contacts_free_account' => 15]);

$this->assertFalse(
$account->hasReachedContactLimit()
);
config(['monica.number_of_allowed_contacts_free_account' => 100]);

$this->assertFalse(
Expand Down

0 comments on commit 5823d77

Please sign in to comment.