Skip to content

Commit

Permalink
Added notification information to the push notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
RishiDiwanTT committed Sep 6, 2023
1 parent 66093b2 commit 1a0ea04
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
11 changes: 8 additions & 3 deletions core/util/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,15 @@ def send_loan_expiry_message(
edition: Edition = loan.license_pool.presentation_edition
identifier: Identifier = loan.license_pool.identifier
library_short_name = loan.library and loan.library.short_name
title = f"Only {days_to_expiry} {'days' if days_to_expiry != 1 else 'day'} left on your loan!"
body = f"Your loan on {edition.title} is expiring soon"
for token in tokens:
msg = messaging.Message(
token=token.device_token,
notification=dict(title=title, body=body),
data=dict(
title=f"Only {days_to_expiry} {'days' if days_to_expiry != 1 else 'day'} left on your loan!",
body=f"Your loan on {edition.title} is expiring soon",
title=title,
body=body,
event_type=NotificationConstants.LOAN_EXPIRY_TYPE,
loans_endpoint=f"{url}/{loan.library.short_name}/loans",
external_identifier=loan.patron.external_identifier,
Expand Down Expand Up @@ -129,11 +132,13 @@ def send_holds_notifications(cls, holds: list[Hold]) -> list[str]:
loans_api = f"{url}/{hold.patron.library.short_name}/loans"
work: Work = hold.work
identifier: Identifier = hold.license_pool.identifier
title = f'Your hold on "{work.title}" is available!'
for token in tokens:
msg = messaging.Message(
token=token.device_token,
notification=dict(title=title),
data=dict(
title=f'Your hold on "{work.title}" is available!',
title=title,
event_type=NotificationConstants.HOLD_AVAILABLE_TYPE,
loans_endpoint=loans_api,
external_identifier=hold.patron.external_identifier,
Expand Down
13 changes: 13 additions & 0 deletions tests/core/util/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ def test_send_loan_notification(self, push_notf_fixture: PushNotificationsFixtur
(),
{
"token": "atoken",
"notification": dict(
title="Only 1 day left on your loan!",
body=f"Your loan on {work.presentation_edition.title} is expiring soon",
),
"data": dict(
title="Only 1 day left on your loan!",
body=f"Your loan on {work.presentation_edition.title} is expiring soon",
Expand Down Expand Up @@ -176,6 +180,9 @@ def test_holds_notification(self, push_notf_fixture: PushNotificationsFixture):
assert messaging.Message.call_args_list == [
mock.call(
token="test-token-1",
notification=dict(
title=f'Your hold on "{work1.title}" is available!',
),
data=dict(
title=f'Your hold on "{work1.title}" is available!',
event_type=NotificationConstants.HOLD_AVAILABLE_TYPE,
Expand All @@ -189,6 +196,9 @@ def test_holds_notification(self, push_notf_fixture: PushNotificationsFixture):
),
mock.call(
token="test-token-2",
notification=dict(
title=f'Your hold on "{work1.title}" is available!',
),
data=dict(
title=f'Your hold on "{work1.title}" is available!',
event_type=NotificationConstants.HOLD_AVAILABLE_TYPE,
Expand All @@ -202,6 +212,9 @@ def test_holds_notification(self, push_notf_fixture: PushNotificationsFixture):
),
mock.call(
token="test-token-3",
notification=dict(
title=f'Your hold on "{work2.title}" is available!',
),
data=dict(
title=f'Your hold on "{work2.title}" is available!',
event_type=NotificationConstants.HOLD_AVAILABLE_TYPE,
Expand Down

0 comments on commit 1a0ea04

Please sign in to comment.