refactor title and subtitle of shift notifications (#2288)
# What this PR does ## Which issue(s) this PR fixes ## Checklist - [x] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [ ] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not required) --------- Co-authored-by: Joey Orlando <joseph.t.orlando@gmail.com> Co-authored-by: Joey Orlando <joey.orlando@grafana.com>
This commit is contained in:
parent
4f2d3bee9f
commit
0177301bb8
3 changed files with 44 additions and 35 deletions
|
|
@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
|||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## Unreleased
|
||||
|
||||
## Changed
|
||||
|
||||
- Change mobile shift notifications title and subtitle by @imtoori ([#2288](https://github.com/grafana/oncall/pull/2288))
|
||||
|
||||
## v1.2.45 (2023-06-19)
|
||||
|
||||
### Changed
|
||||
|
|
|
|||
|
|
@ -226,14 +226,17 @@ def _get_alert_group_escalation_fcm_message(
|
|||
return _construct_fcm_message(message_type, device_to_notify, thread_id, fcm_message_data, apns_payload)
|
||||
|
||||
|
||||
def _get_youre_going_oncall_notification_title(
|
||||
def _get_youre_going_oncall_notification_title(seconds_until_going_oncall: int) -> str:
|
||||
time_until_going_oncall = humanize.naturaldelta(seconds_until_going_oncall)
|
||||
|
||||
return f"Your on-call shift starts in {time_until_going_oncall}"
|
||||
|
||||
|
||||
def _get_youre_going_oncall_notification_subtitle(
|
||||
schedule: OnCallSchedule,
|
||||
seconds_until_going_oncall: int,
|
||||
schedule_event: ScheduleEvent,
|
||||
mobile_app_user_settings: "MobileAppUserSettings",
|
||||
) -> str:
|
||||
time_until_going_oncall = humanize.naturaldelta(seconds_until_going_oncall)
|
||||
|
||||
shift_start = schedule_event["start"]
|
||||
shift_end = schedule_event["end"]
|
||||
shift_starts_and_ends_on_same_day = shift_start.date() == shift_end.date()
|
||||
|
|
@ -244,7 +247,7 @@ def _get_youre_going_oncall_notification_title(
|
|||
|
||||
formatted_shift = f"{_format_datetime(shift_start)} - {_format_datetime(shift_end)}"
|
||||
|
||||
return f"You're going on call in {time_until_going_oncall} for schedule {schedule.name}, {formatted_shift}"
|
||||
return f"{formatted_shift}\nSchedule {schedule.name}"
|
||||
|
||||
|
||||
def _get_youre_going_oncall_fcm_message(
|
||||
|
|
@ -261,12 +264,14 @@ def _get_youre_going_oncall_fcm_message(
|
|||
|
||||
mobile_app_user_settings, _ = MobileAppUserSettings.objects.get_or_create(user=user)
|
||||
|
||||
notification_title = _get_youre_going_oncall_notification_title(
|
||||
schedule, seconds_until_going_oncall, schedule_event, mobile_app_user_settings
|
||||
notification_title = _get_youre_going_oncall_notification_title(seconds_until_going_oncall)
|
||||
notification_subtitle = _get_youre_going_oncall_notification_subtitle(
|
||||
schedule, schedule_event, mobile_app_user_settings
|
||||
)
|
||||
|
||||
data: FCMMessageData = {
|
||||
"title": notification_title,
|
||||
"subtitle": notification_subtitle,
|
||||
"info_notification_sound_name": (
|
||||
mobile_app_user_settings.info_notification_sound_name + MobileAppUserSettings.ANDROID_SOUND_NAME_EXTENSION
|
||||
),
|
||||
|
|
@ -278,7 +283,7 @@ def _get_youre_going_oncall_fcm_message(
|
|||
apns_payload = APNSPayload(
|
||||
aps=Aps(
|
||||
thread_id=thread_id,
|
||||
alert=ApsAlert(title=notification_title),
|
||||
alert=ApsAlert(title=notification_title, subtitle=notification_subtitle),
|
||||
sound=CriticalSound(
|
||||
critical=False,
|
||||
name=mobile_app_user_settings.info_notification_sound_name
|
||||
|
|
|
|||
|
|
@ -95,42 +95,36 @@ def test_get_youre_going_oncall_notification_title(make_organization_and_user, m
|
|||
##################
|
||||
# same day shift
|
||||
##################
|
||||
same_day_shift_title = tasks._get_youre_going_oncall_notification_title(
|
||||
schedule, seconds_until_going_oncall, same_day_shift, maus
|
||||
)
|
||||
same_day_shift_no_locale_title = tasks._get_youre_going_oncall_notification_title(
|
||||
schedule, seconds_until_going_oncall, same_day_shift, maus_no_locale
|
||||
same_day_shift_title = tasks._get_youre_going_oncall_notification_title(seconds_until_going_oncall)
|
||||
same_day_shift_subtitle = tasks._get_youre_going_oncall_notification_subtitle(schedule, same_day_shift, maus)
|
||||
same_day_shift_no_locale_subtitle = tasks._get_youre_going_oncall_notification_subtitle(
|
||||
schedule, same_day_shift, maus_no_locale
|
||||
)
|
||||
|
||||
assert (
|
||||
same_day_shift_title
|
||||
== f"You're going on call in {humanized_time_until_going_oncall} for schedule {schedule_name}, 09 h 00 - 17 h 00"
|
||||
)
|
||||
assert (
|
||||
same_day_shift_no_locale_title
|
||||
== f"You're going on call in {humanized_time_until_going_oncall} for schedule {schedule_name}, 9:00\u202fAM - 5:00\u202fPM"
|
||||
)
|
||||
assert same_day_shift_title == f"Your on-call shift starts in {humanized_time_until_going_oncall}"
|
||||
assert same_day_shift_subtitle == f"09 h 00 - 17 h 00\nSchedule {schedule_name}"
|
||||
assert same_day_shift_no_locale_subtitle == f"9:00\u202fAM - 5:00\u202fPM\nSchedule {schedule_name}"
|
||||
|
||||
##################
|
||||
# multiple day shift
|
||||
##################
|
||||
multiple_day_shift_title = tasks._get_youre_going_oncall_notification_title(
|
||||
schedule, seconds_until_going_oncall, multiple_day_shift, maus
|
||||
multiple_day_shift_title = tasks._get_youre_going_oncall_notification_title(seconds_until_going_oncall)
|
||||
multiple_day_shift_subtitle = tasks._get_youre_going_oncall_notification_subtitle(
|
||||
schedule, multiple_day_shift, maus
|
||||
)
|
||||
multiple_day_shift_no_locale_title = tasks._get_youre_going_oncall_notification_title(
|
||||
schedule, seconds_until_going_oncall, multiple_day_shift, maus_no_locale
|
||||
multiple_day_shift_no_locale_subtitle = tasks._get_youre_going_oncall_notification_subtitle(
|
||||
schedule, multiple_day_shift, maus_no_locale
|
||||
)
|
||||
|
||||
assert multiple_day_shift_title == f"Your on-call shift starts in {humanized_time_until_going_oncall}"
|
||||
assert multiple_day_shift_subtitle == f"2023-07-08 09 h 00 - 2023-07-12 17 h 00\nSchedule {schedule_name}"
|
||||
assert (
|
||||
multiple_day_shift_title
|
||||
== f"You're going on call in {humanized_time_until_going_oncall} for schedule {schedule_name}, 2023-07-08 09 h 00 - 2023-07-12 17 h 00"
|
||||
)
|
||||
assert (
|
||||
multiple_day_shift_no_locale_title
|
||||
== f"You're going on call in {humanized_time_until_going_oncall} for schedule {schedule_name}, 7/8/23, 9:00\u202fAM - 7/12/23, 5:00\u202fPM"
|
||||
multiple_day_shift_no_locale_subtitle
|
||||
== f"7/8/23, 9:00\u202fAM - 7/12/23, 5:00\u202fPM\nSchedule {schedule_name}"
|
||||
)
|
||||
|
||||
|
||||
@mock.patch("apps.mobile_app.tasks._get_youre_going_oncall_notification_subtitle")
|
||||
@mock.patch("apps.mobile_app.tasks._get_youre_going_oncall_notification_title")
|
||||
@mock.patch("apps.mobile_app.tasks._construct_fcm_message")
|
||||
@mock.patch("apps.mobile_app.tasks.APNSPayload")
|
||||
|
|
@ -145,16 +139,19 @@ def test_get_youre_going_oncall_fcm_message(
|
|||
mock_apns_payload,
|
||||
mock_construct_fcm_message,
|
||||
mock_get_youre_going_oncall_notification_title,
|
||||
mock_get_youre_going_oncall_notification_subtitle,
|
||||
make_organization_and_user,
|
||||
make_schedule,
|
||||
):
|
||||
mock_fcm_message = "mncvmnvcmnvcnmvcmncvmn"
|
||||
mock_notification_title = "asdfasdf"
|
||||
mock_notification_subtitle = f"9:06\u202fAM - 9:06\u202fAM\nSchedule XYZ"
|
||||
shift_pk = "mncvmnvc"
|
||||
seconds_until_going_oncall = 600
|
||||
|
||||
mock_construct_fcm_message.return_value = mock_fcm_message
|
||||
mock_get_youre_going_oncall_notification_title.return_value = mock_notification_title
|
||||
mock_get_youre_going_oncall_notification_subtitle.return_value = mock_notification_subtitle
|
||||
|
||||
organization, user = make_organization_and_user()
|
||||
user_pk = user.public_primary_key
|
||||
|
|
@ -177,6 +174,7 @@ def test_get_youre_going_oncall_fcm_message(
|
|||
|
||||
data = {
|
||||
"title": mock_notification_title,
|
||||
"subtitle": mock_notification_subtitle,
|
||||
"info_notification_sound_name": (
|
||||
maus.info_notification_sound_name + MobileAppUserSettings.ANDROID_SOUND_NAME_EXTENSION
|
||||
),
|
||||
|
|
@ -191,7 +189,7 @@ def test_get_youre_going_oncall_fcm_message(
|
|||
|
||||
assert fcm_message == mock_fcm_message
|
||||
|
||||
mock_aps_alert.assert_called_once_with(title=mock_notification_title)
|
||||
mock_aps_alert.assert_called_once_with(title=mock_notification_title, subtitle=mock_notification_subtitle)
|
||||
mock_critical_sound.assert_called_once_with(
|
||||
critical=False, name=maus.info_notification_sound_name + MobileAppUserSettings.IOS_SOUND_NAME_EXTENSION
|
||||
)
|
||||
|
|
@ -205,9 +203,9 @@ def test_get_youre_going_oncall_fcm_message(
|
|||
)
|
||||
mock_apns_payload.assert_called_once_with(aps=mock_aps.return_value)
|
||||
|
||||
mock_get_youre_going_oncall_notification_title.assert_called_once_with(
|
||||
schedule, seconds_until_going_oncall, schedule_event, maus
|
||||
)
|
||||
mock_get_youre_going_oncall_notification_subtitle.assert_called_once_with(schedule, schedule_event, maus)
|
||||
mock_get_youre_going_oncall_notification_title.assert_called_once_with(seconds_until_going_oncall)
|
||||
|
||||
mock_construct_fcm_message.assert_called_once_with(
|
||||
tasks.MessageType.INFO, device, notification_thread_id, data, mock_apns_payload.return_value
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue