Skip to content

Commit

Permalink
fix: fix duplicate reminders on dashboard (#5569)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsawo authored Oct 13, 2021
1 parent 399b862 commit bb97115
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ Simon Van Accoleyen @SimonVanacco <simon@vanacco.fr>
Michael Bianco <mike@mikebian.co>
Ben Fesili @benfes
Markus Dick @markusdick
Jacek Sawoszczuk @jsawo
Dung Nguyen @nhymxu
5 changes: 4 additions & 1 deletion app/Helpers/AccountHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ public static function getUpcomingRemindersForMonth(Account $account, int $month
return $account->reminderOutboxes()
->with(['reminder', 'reminder.contact'])
->whereBetween('planned_date', [$startOfMonth, $endOfMonth])
->where('nature', 'reminder')
->where([
'user_id' => auth()->user()->id,
'nature' => 'reminder',
])
->orderBy('planned_date', 'asc')
->get();
}
Expand Down
34 changes: 32 additions & 2 deletions tests/Unit/Helpers/AccountHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,17 @@ public function it_gets_the_default_gender_for_the_account(): void
public function get_reminders_for_month_returns_no_reminders(): void
{
$account = factory(Account::class)->create();
$user = factory(User::class)->create([
'account_id' => $account->id,
]);

Carbon::setTestNow(Carbon::create(2017, 1, 1));
factory(Reminder::class, 3)->create([
'account_id' => $account->id,
]);

// check if there are reminders for the month of March
$this->assertCount(0, AccountHelper::getUpcomingRemindersForMonth($account, 3));
$this->actingAs($user)->assertCount(0, AccountHelper::getUpcomingRemindersForMonth($account, 3));
}

/** @test */
Expand All @@ -177,7 +180,34 @@ public function get_reminders_for_month_returns_reminders_for_given_month(): voi
$reminder->schedule($user);
}

$this->assertCount(3, AccountHelper::getUpcomingRemindersForMonth($account, 2));
$this->actingAs($user)->assertCount(3, AccountHelper::getUpcomingRemindersForMonth($account, 2));
}

/** @test */
public function get_reminders_for_month_returns_reminders_for_current_user_only(): void
{
$account = factory(Account::class)->create();
$user1 = factory(User::class)->create([
'account_id' => $account->id,
]);
$user2 = factory(User::class)->create([
'account_id' => $account->id,
]);

Carbon::setTestNow(Carbon::create(2017, 1, 1));

// add 3 reminders for the month of March
for ($i = 0; $i < 3; $i++) {
$reminder = factory(Reminder::class)->create([
'account_id' => $account->id,
'initial_date' => '2017-03-03 00:00:00',
]);

$reminder->schedule($user1);
$reminder->schedule($user2);
}

$this->actingAs($user1)->assertCount(3, AccountHelper::getUpcomingRemindersForMonth($account, 2));
}

/** @test */
Expand Down

0 comments on commit bb97115

Please sign in to comment.