Skip to content

Commit 4734755

Browse files
committed
fix(tests): check global email opt-out in match notifications and fix whatsapp factory value
1 parent 3138c89 commit 4734755

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

fiesta/apps/notifications/services/match.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ def _get_prefs(user: User, section: Section) -> SectionNotificationPreferences |
3131
return None
3232

3333

34+
def _is_globally_opted_out(user: User) -> bool:
35+
"""Return True if user has disabled email notifications globally."""
36+
try:
37+
return not user.profile.email_notifications_enabled
38+
except Exception:
39+
return False
40+
41+
3442
def _notify_match_enabled(prefs: SectionNotificationPreferences | None) -> bool:
3543
"""Return True if user wants match notifications (default True when prefs missing)."""
3644
if prefs is None:
@@ -56,7 +64,7 @@ def notify_buddy_match(*, match: BuddyRequestMatch, request: BuddyRequest, secti
5664

5765
matcher = match.matcher
5866
matcher_prefs = _get_prefs(matcher, section)
59-
if _notify_match_enabled(matcher_prefs):
67+
if _notify_match_enabled(matcher_prefs) and not _is_globally_opted_out(matcher):
6068
_send_buddy_matcher_email(match=match, request=request, section=section)
6169

6270
issuer = request.issuer
@@ -104,7 +112,7 @@ def notify_pickup_match(*, match: PickupRequestMatch, request: PickupRequest, se
104112

105113
matcher = match.matcher
106114
matcher_prefs = _get_prefs(matcher, section)
107-
if _notify_match_enabled(matcher_prefs):
115+
if _notify_match_enabled(matcher_prefs) and not _is_globally_opted_out(matcher):
108116
_send_pickup_matcher_email(match=match, request=request, section=section)
109117

110118
issuer = request.issuer

fiesta/apps/utils/factories/accounts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ class Meta:
5858
facebook = factory.Faker("url")
5959
instagram = factory.Faker("user_name")
6060
telegram = factory.Faker("url")
61-
whatsapp = factory.Faker("phone_number")
61+
whatsapp = factory.Sequence(lambda n: f"+420600{n:06d}")

0 commit comments

Comments
 (0)