Skip to content

Commit

Permalink
fix: misc bugfixes to reminders (#6931)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexis Saettler <alexis@saettler.org>
  • Loading branch information
evanlihou and asbiin committed Nov 1, 2023
1 parent 511cb5d commit 9c86c4d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private function update(): void

private function deleteOldScheduledReminders(): void
{
$this->reminder->userNotificationChannels->each->delete();
$this->reminder->userNotificationChannels()->detach();
}

private function scheduledReminderForAllUsersInVault(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

use App\Domains\Settings\ManageNotificationChannels\Services\ScheduleAllContactRemindersForNotificationChannel;
use App\Http\Controllers\Controller;
use App\Models\UserNotificationChannel;
use Exception;
Expand Down Expand Up @@ -52,6 +53,12 @@ public function store(Request $request)
$channel->active = true;
$channel->save();

(new ScheduleAllContactRemindersForNotificationChannel())->execute([
'account_id' => $channel->user->account_id,
'author_id' => $channel->user->id,
'user_notification_channel_id' => $channel->id,
]);

return response('Success', 200);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,43 @@ public function it_updates_a_reminder(): void
$this->executeService($regis, $regis->account, $vault, $contact, $reminder);
}

/** @test */
public function it_persists_notification_channels(): void
{
$regis = $this->createUser();
$vault = $this->createVault($regis->account);
$vault = $this->setPermissionInVault($regis, Vault::PERMISSION_EDIT, $vault);
$contact = Contact::factory()->create(['vault_id' => $vault->id]);
$reminder = ContactReminder::factory()->create([
'contact_id' => $contact->id,
]);

UserNotificationChannel::factory()->create([
'user_id' => $regis->id,
'preferred_time' => '18:00',
]);

$request = [
'account_id' => $regis->account->id,
'vault_id' => $vault->id,
'author_id' => $regis->id,
'contact_id' => $contact->id,
'contact_reminder_id' => $reminder->id,
'label' => 'birthdate',
'day' => 29,
'month' => 10,
'year' => 1981,
'type' => ContactReminder::TYPE_ONE_TIME,
'frequency_number' => null,
];

(new UpdateContactReminder())->execute($request);

$this->assertDatabaseHas('user_notification_channels', [
'user_id' => $regis->id,
]);
}

/** @test */
public function it_fails_if_wrong_parameters_are_given(): void
{
Expand Down

0 comments on commit 9c86c4d

Please sign in to comment.