diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 9971ef26cd9..f6fa9b2954d 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -53,4 +53,5 @@ Simon Van Accoleyen @SimonVanacco Michael Bianco Ben Fesili @benfes Markus Dick @markusdick +Jacek Sawoszczuk @jsawo Dung Nguyen @nhymxu diff --git a/app/Helpers/AccountHelper.php b/app/Helpers/AccountHelper.php index 53ba23a89c8..7e4c7722b95 100644 --- a/app/Helpers/AccountHelper.php +++ b/app/Helpers/AccountHelper.php @@ -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(); } diff --git a/tests/Unit/Helpers/AccountHelperTest.php b/tests/Unit/Helpers/AccountHelperTest.php index 0533e805aeb..e359c4fc2c6 100644 --- a/tests/Unit/Helpers/AccountHelperTest.php +++ b/tests/Unit/Helpers/AccountHelperTest.php @@ -147,6 +147,9 @@ 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([ @@ -154,7 +157,7 @@ public function get_reminders_for_month_returns_no_reminders(): void ]); // 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 */ @@ -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 */