Test the unread count in the push payload and its APNs badge mapping
DevPlace CI / test (push) Failing after 3h14m52s
DevPlace CI / test (push) Failing after 3h14m52s
Provider tests cover aps.badge, the invalid values that leave it out and the unchanged Web Push body. Funnel tests cover the count for single notifications, grouped and ungrouped users and an in-app channel that is off. Written in the existing unit style; not executed. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,9 @@ from devplacepy.database import (
|
||||
get_table,
|
||||
get_primary_admin_uid,
|
||||
invalidate_admins_cache,
|
||||
set_notification_grouping_enabled,
|
||||
set_notification_pref,
|
||||
set_notification_throttle_enabled,
|
||||
)
|
||||
from devplacepy.utils import (
|
||||
award_badge,
|
||||
@@ -11,6 +14,7 @@ from devplacepy.utils import (
|
||||
get_badge,
|
||||
check_milestone_badges,
|
||||
create_mention_notifications,
|
||||
create_notification,
|
||||
extract_mentions,
|
||||
generate_uid,
|
||||
hash_password,
|
||||
@@ -298,3 +302,51 @@ def test_create_mention_notifications_targets_known_users(local_db):
|
||||
)
|
||||
assert get_table("notifications").count(user_uid=target_uid, type="mention") == 1
|
||||
assert get_table("notifications").count(user_uid=actor_uid, type="mention") == 0
|
||||
|
||||
|
||||
def _capture_push_unread(monkeypatch):
|
||||
sent = []
|
||||
monkeypatch.setattr(
|
||||
"devplacepy.utils.notifications._schedule_push",
|
||||
lambda user_uid, message, target_url, unread: sent.append(unread),
|
||||
)
|
||||
return sent
|
||||
|
||||
|
||||
def test_push_payload_counts_unread_rows_for_single_notifications(local_db, monkeypatch):
|
||||
uid, _ = _seed_user()
|
||||
sent = _capture_push_unread(monkeypatch)
|
||||
create_notification(uid, "badge", "first", uid, "/profile/x")
|
||||
create_notification(uid, "badge", "second", uid, "/profile/x")
|
||||
assert sent == [1, 2]
|
||||
|
||||
|
||||
def test_push_payload_counts_groups_when_grouping_is_on(local_db, monkeypatch):
|
||||
uid, _ = _seed_user()
|
||||
actor_uid, _ = _seed_user()
|
||||
set_notification_throttle_enabled(uid, False)
|
||||
sent = _capture_push_unread(monkeypatch)
|
||||
create_notification(uid, "mention", "one", actor_uid, "/posts/x")
|
||||
create_notification(uid, "mention", "two", actor_uid, "/posts/x")
|
||||
assert sent == [1, 1]
|
||||
|
||||
|
||||
def test_push_payload_counts_rows_when_grouping_is_off(local_db, monkeypatch):
|
||||
uid, _ = _seed_user()
|
||||
actor_uid, _ = _seed_user()
|
||||
set_notification_throttle_enabled(uid, False)
|
||||
set_notification_grouping_enabled(uid, False)
|
||||
sent = _capture_push_unread(monkeypatch)
|
||||
create_notification(uid, "mention", "one", actor_uid, "/posts/x")
|
||||
create_notification(uid, "mention", "two", actor_uid, "/posts/x")
|
||||
assert sent == [1, 2]
|
||||
|
||||
|
||||
def test_push_payload_keeps_the_unread_count_when_in_app_is_off(local_db, monkeypatch):
|
||||
uid, _ = _seed_user()
|
||||
sent = _capture_push_unread(monkeypatch)
|
||||
create_notification(uid, "badge", "stored", uid, "/profile/x")
|
||||
set_notification_pref(uid, "level", "in_app", False)
|
||||
create_notification(uid, "level", "not stored", uid, "/profile/x")
|
||||
assert sent == [1, 1]
|
||||
assert get_table("notifications").count(user_uid=uid, type="level") == 0
|
||||
|
||||
Reference in New Issue
Block a user