Skip to content

Commit 9c86c4d

Browse files
NixFeyasbiin
andauthored
fix: misc bugfixes to reminders (#6931)
Co-authored-by: Alexis Saettler <[email protected]>
1 parent 511cb5d commit 9c86c4d

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

app/Domains/Contact/ManageReminders/Services/UpdateContactReminder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private function update(): void
8383

8484
private function deleteOldScheduledReminders(): void
8585
{
86-
$this->reminder->userNotificationChannels->each->delete();
86+
$this->reminder->userNotificationChannels()->detach();
8787
}
8888

8989
private function scheduledReminderForAllUsersInVault(): void

app/Domains/Settings/ManageNotificationChannels/Web/Controllers/TelegramWebhookController.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Domains\Settings\ManageNotificationChannels\Web\Controllers;
44

5+
use App\Domains\Settings\ManageNotificationChannels\Services\ScheduleAllContactRemindersForNotificationChannel;
56
use App\Http\Controllers\Controller;
67
use App\Models\UserNotificationChannel;
78
use Exception;
@@ -52,6 +53,12 @@ public function store(Request $request)
5253
$channel->active = true;
5354
$channel->save();
5455

56+
(new ScheduleAllContactRemindersForNotificationChannel())->execute([
57+
'account_id' => $channel->user->account_id,
58+
'author_id' => $channel->user->id,
59+
'user_notification_channel_id' => $channel->id,
60+
]);
61+
5562
return response('Success', 200);
5663
}
5764
}

tests/Unit/Domains/Contact/ManageReminders/Services/UpdateContactReminderTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,43 @@ public function it_updates_a_reminder(): void
3333
$this->executeService($regis, $regis->account, $vault, $contact, $reminder);
3434
}
3535

36+
/** @test */
37+
public function it_persists_notification_channels(): void
38+
{
39+
$regis = $this->createUser();
40+
$vault = $this->createVault($regis->account);
41+
$vault = $this->setPermissionInVault($regis, Vault::PERMISSION_EDIT, $vault);
42+
$contact = Contact::factory()->create(['vault_id' => $vault->id]);
43+
$reminder = ContactReminder::factory()->create([
44+
'contact_id' => $contact->id,
45+
]);
46+
47+
UserNotificationChannel::factory()->create([
48+
'user_id' => $regis->id,
49+
'preferred_time' => '18:00',
50+
]);
51+
52+
$request = [
53+
'account_id' => $regis->account->id,
54+
'vault_id' => $vault->id,
55+
'author_id' => $regis->id,
56+
'contact_id' => $contact->id,
57+
'contact_reminder_id' => $reminder->id,
58+
'label' => 'birthdate',
59+
'day' => 29,
60+
'month' => 10,
61+
'year' => 1981,
62+
'type' => ContactReminder::TYPE_ONE_TIME,
63+
'frequency_number' => null,
64+
];
65+
66+
(new UpdateContactReminder())->execute($request);
67+
68+
$this->assertDatabaseHas('user_notification_channels', [
69+
'user_id' => $regis->id,
70+
]);
71+
}
72+
3673
/** @test */
3774
public function it_fails_if_wrong_parameters_are_given(): void
3875
{

0 commit comments

Comments
 (0)