feat: added channels column to send notification on specific channels (#34289)

* feat: added channels column to send notifications on specific channels
This commit is contained in:
Ahtisham Shahid
2024-03-20 13:17:45 +05:00
committed by GitHub
parent cee42fd543
commit c344fdc698
8 changed files with 105 additions and 19 deletions

View File

@@ -176,6 +176,8 @@ class SendNotificationsTest(ModuleStoreTestCase):
preference = CourseNotificationPreference.get_user_course_preference(self.user.id, self.course_1.id)
app_prefs = preference.notification_preference_config[app_name]
app_prefs['notification_types']['core']['web'] = False
app_prefs['notification_types']['core']['email'] = False
app_prefs['notification_types']['core']['push'] = False
preference.save()
send_notifications([self.user.id], str(self.course_1.id), app_name, notification_type, context, content_url)

View File

@@ -570,11 +570,10 @@ class UserNotificationChannelPreferenceAPITest(ModuleStoreTestCase):
if expected_status == status.HTTP_200_OK:
expected_data = self._expected_api_response()
expected_app_prefs = expected_data['notification_preference_config'][notification_app]
for notification_type_name, notification_type_preferences in expected_app_prefs[
'notification_types'].items():
non_editable_channels = expected_app_prefs['non_editable'].get(notification_type_name, [])
for notification_type, __ in expected_app_prefs['notification_types'].items():
non_editable_channels = expected_app_prefs['non_editable'].get(notification_type, [])
if notification_channel not in non_editable_channels:
expected_app_prefs['notification_types'][notification_type_name][notification_channel] = value
expected_app_prefs['notification_types'][notification_type][notification_channel] = value
expected_data = remove_notifications_with_visibility_settings(expected_data)
self.assertEqual(response.data, expected_data)
event_name, event_data = mock_emit.call_args[0]
@@ -584,6 +583,7 @@ class UserNotificationChannelPreferenceAPITest(ModuleStoreTestCase):
self.assertEqual(event_data['value'], value)
@ddt.ddt
class NotificationListAPIViewTest(APITestCase):
"""
Tests suit for the NotificationListAPIView.
@@ -663,6 +663,43 @@ class NotificationListAPIViewTest(APITestCase):
'<p><strong>test_user</strong> responded to your post <strong>This is a test post.</strong></p>'
)
@ddt.data(
([], 0),
(['web'], 1),
(['email'], 0),
(['web', 'email'], 1),
(['web', 'email', 'push'], 1),
)
@ddt.unpack
def test_list_notifications_with_channels(self, channels, expected_count):
"""
Test that the view can filter notifications by app name and channels.
"""
Notification.objects.create(
user=self.user,
app_name='discussion',
notification_type='new_response',
content_context={
'replier_name': 'test_user',
'post_title': 'This is a test post.',
},
web='web' in channels,
email='email' in channels
)
self.client.login(username=self.user.username, password=self.TEST_PASSWORD)
# Make a request to the view with the app_name query parameter set to 'app1'.
response = self.client.get(self.url + "?app_name=discussion")
# Assert that the response is successful.
self.assertEqual(response.status_code, 200)
# Assert that the response contains expected results i.e. channels contains web or is null.
data = response.data['results']
self.assertEqual(len(data), expected_count)
@mock.patch("eventtracking.tracker.emit")
def test_list_notifications_with_tray_opened_param(self, mock_emit):
"""