ritesh19180 commited on
Commit
a357cf8
·
verified ·
1 Parent(s): 446f291

Upload folder using huggingface_hub

Browse files
backend/services/notification_routing.py CHANGED
@@ -154,12 +154,15 @@ class NotificationRoutingMiddleware:
154
  """
155
  settings = self.get_system_settings(company_id)
156
 
157
- if not settings["admin_alerts"]:
158
  self.log_notification_skipped(
159
  company_id, NotificationType.ADMIN_ALERT, "admin_alerts_disabled"
160
  )
161
  return False
162
 
 
 
 
163
  self.log_notification_sent(company_id, NotificationType.ADMIN_ALERT)
164
  return True
165
 
 
154
  """
155
  settings = self.get_system_settings(company_id)
156
 
157
+ if settings.get("admin_alerts") is False:
158
  self.log_notification_skipped(
159
  company_id, NotificationType.ADMIN_ALERT, "admin_alerts_disabled"
160
  )
161
  return False
162
 
163
+ if settings.get("admin_alerts") is None:
164
+ return False
165
+
166
  self.log_notification_sent(company_id, NotificationType.ADMIN_ALERT)
167
  return True
168
 
backend/tests/test_notification_routing.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+ import sys
3
+ from unittest.mock import patch, MagicMock
4
+
5
+ sys.modules['supabase'] = MagicMock()
6
+ sys.modules['dotenv'] = MagicMock()
7
+
8
+ from backend.services.notification_routing import NotificationRoutingMiddleware, NotificationType
9
+
10
+
11
+ class TestNotificationRoutingNoneHandling:
12
+ """Tests for handling None values in notification_routing service"""
13
+
14
+ def test_should_send_admin_alert_with_none_admin_alerts(self):
15
+ """Test that admin_alerts=None returns False"""
16
+ svc = NotificationRoutingMiddleware()
17
+
18
+ with patch.object(svc, 'get_system_settings', return_value={"admin_alerts": None}):
19
+ result = svc.should_send_admin_alert("company-123")
20
+ assert result is False
21
+
22
+ def test_should_send_admin_alert_with_false_admin_alerts(self):
23
+ """Test that admin_alerts=False returns False"""
24
+ svc = NotificationRoutingMiddleware()
25
+
26
+ with patch.object(svc, 'get_system_settings', return_value={"admin_alerts": False}):
27
+ result = svc.should_send_admin_alert("company-123")
28
+ assert result is False
29
+
30
+ def test_should_send_admin_alert_with_true_admin_alerts(self):
31
+ """Test that admin_alerts=True returns True"""
32
+ svc = NotificationRoutingMiddleware()
33
+
34
+ with patch.object(svc, 'get_system_settings', return_value={"admin_alerts": True}):
35
+ result = svc.should_send_admin_alert("company-123")
36
+ assert result is True