Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: misc bugfixes to reminders #6931

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,44 @@ 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);
(new UpdateContactReminder())->execute($request);
NixFey marked this conversation as resolved.
Show resolved Hide resolved

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

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