-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tracking pull request to merge release-2.10.0 to master (#2574)
* feat: updated feature branch references * chore: updated branch number * chore: updated readme versions * tfrs-2496tooltip font size increase (#2589) * TFRS - Remove link to credit market report on dashboard (#2586) * fix: minor fix and unit tests for user notifications (#2584) Co-authored-by: Your Name <[email protected]> * fix for rescind status not saving in history * adding LCFS box in BCeID dashboard * adding check if previous trasfer status is already rescinded * revise messaging for category D checkbox * fixing typo --------- Co-authored-by: Your Name <[email protected]> Co-authored-by: jig-patel <[email protected]>
- Loading branch information
1 parent
be06494
commit 06f401c
Showing
16 changed files
with
283 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
notifications_payload_active = [ | ||
{"notificationType":"CREDIT_TRANSFER_CREATED","channel":"IN_APP","subscribed":True}, | ||
{"notificationType":"CREDIT_TRANSFER_CREATED","channel":"EMAIL","subscribed":True}, | ||
{"notificationType":"CREDIT_TRANSFER_SIGNED_1OF2","channel":"IN_APP","subscribed":True}, | ||
{"notificationType":"CREDIT_TRANSFER_SIGNED_1OF2","channel":"EMAIL","subscribed":True}, | ||
{"notificationType":"CREDIT_TRANSFER_PROPOSAL_REFUSED","channel":"IN_APP","subscribed":True}, | ||
{"notificationType":"CREDIT_TRANSFER_PROPOSAL_REFUSED","channel":"EMAIL","subscribed":True}, | ||
{"notificationType":"CREDIT_TRANSFER_SIGNED_2OF2","channel":"IN_APP","subscribed":True}, | ||
{"notificationType":"CREDIT_TRANSFER_SIGNED_2OF2","channel":"EMAIL","subscribed":True}, | ||
{"notificationType":"CREDIT_TRANSFER_APPROVED","channel":"IN_APP","subscribed":True}, | ||
{"notificationType":"CREDIT_TRANSFER_APPROVED","channel":"EMAIL","subscribed":True}, | ||
{"notificationType":"CREDIT_TRANSFER_DECLINED","channel":"IN_APP","subscribed":True}, | ||
{"notificationType":"CREDIT_TRANSFER_DECLINED","channel":"EMAIL","subscribed":True}, | ||
{"notificationType":"CREDIT_TRANSFER_RESCINDED","channel":"IN_APP","subscribed":True}, | ||
{"notificationType":"CREDIT_TRANSFER_RESCINDED","channel":"EMAIL","subscribed":True}, | ||
{"notificationType":"PVR_APPROVED","channel":"IN_APP","subscribed":True}, | ||
{"notificationType":"PVR_APPROVED","channel":"EMAIL","subscribed":True}, | ||
{"notificationType":"PVR_DECLINED","channel":"IN_APP","subscribed":True}, | ||
{"notificationType":"PVR_DECLINED","channel":"EMAIL","subscribed":True}, | ||
{"notificationType":"DOCUMENT_PENDING_SUBMISSION","channel":"IN_APP","subscribed":True}, | ||
{"notificationType":"DOCUMENT_PENDING_SUBMISSION","channel":"EMAIL","subscribed":True}, | ||
{"notificationType":"DOCUMENT_SUBMITTED","channel":"IN_APP","subscribed":True}, | ||
{"notificationType":"DOCUMENT_SUBMITTED","channel":"EMAIL","subscribed":True}, | ||
{"notificationType":"DOCUMENT_RECEIVED","channel":"IN_APP","subscribed":True}, | ||
{"notificationType":"DOCUMENT_RECEIVED","channel":"EMAIL","subscribed":True}, | ||
{"notificationType":"DOCUMENT_ARCHIVED","channel":"IN_APP","subscribed":True}, | ||
{"notificationType":"DOCUMENT_ARCHIVED","channel":"EMAIL","subscribed":True}, | ||
{"notificationType":"COMPLIANCE_REPORT_DRAFT","channel":"IN_APP","subscribed":True}, | ||
{"notificationType":"COMPLIANCE_REPORT_DRAFT","channel":"EMAIL","subscribed":True}, | ||
{"notificationType":"COMPLIANCE_REPORT_SUBMITTED","channel":"IN_APP","subscribed":True}, | ||
{"notificationType":"COMPLIANCE_REPORT_SUBMITTED","channel":"EMAIL","subscribed":True}, | ||
{"notificationType":"COMPLIANCE_REPORT_REQUESTED_SUPPLEMENTAL","channel":"IN_APP","subscribed":True}, | ||
{"notificationType":"COMPLIANCE_REPORT_REQUESTED_SUPPLEMENTAL","channel":"EMAIL","subscribed":True}, | ||
{"notificationType":"COMPLIANCE_REPORT_ACCEPTED","channel":"IN_APP","subscribed":True}, | ||
{"notificationType":"COMPLIANCE_REPORT_ACCEPTED","channel":"EMAIL","subscribed":True}, | ||
{"notificationType":"COMPLIANCE_REPORT_REJECTED","channel":"IN_APP","subscribed":True}, | ||
{"notificationType":"COMPLIANCE_REPORT_REJECTED","channel":"EMAIL","subscribed":True}, | ||
{"notificationType":"EXCLUSION_REPORT_DRAFT","channel":"IN_APP","subscribed":True}, | ||
{"notificationType":"EXCLUSION_REPORT_DRAFT","channel":"EMAIL","subscribed":True}, | ||
{"notificationType":"EXCLUSION_REPORT_SUBMITTED","channel":"IN_APP","subscribed":True}, | ||
{"notificationType":"EXCLUSION_REPORT_SUBMITTED","channel":"EMAIL","subscribed":True}, | ||
{"notificationType":"EXCLUSION_REPORT_REQUESTED_SUPPLEMENTAL","channel":"IN_APP","subscribed":True}, | ||
{"notificationType":"EXCLUSION_REPORT_REQUESTED_SUPPLEMENTAL","channel":"EMAIL","subscribed":True}, | ||
{"notificationType":"EXCLUSION_REPORT_ACCEPTED","channel":"IN_APP","subscribed":True}, | ||
{"notificationType":"EXCLUSION_REPORT_ACCEPTED","channel":"EMAIL","subscribed":True}, | ||
{"notificationType":"EXCLUSION_REPORT_REJECTED","channel":"IN_APP","subscribed":True}, | ||
{"notificationType":"EXCLUSION_REPORT_REJECTED","channel":"EMAIL","subscribed":True} | ||
] | ||
|
||
notifications_payload_inactive = [ | ||
{"notificationType":"CREDIT_TRANSFER_CREATED","channel":"IN_APP","subscribed":False}, | ||
{"notificationType":"CREDIT_TRANSFER_CREATED","channel":"EMAIL","subscribed":False}, | ||
{"notificationType":"CREDIT_TRANSFER_SIGNED_1OF2","channel":"IN_APP","subscribed":False}, | ||
{"notificationType":"CREDIT_TRANSFER_SIGNED_1OF2","channel":"EMAIL","subscribed":False}, | ||
{"notificationType":"CREDIT_TRANSFER_PROPOSAL_REFUSED","channel":"IN_APP","subscribed":False}, | ||
{"notificationType":"CREDIT_TRANSFER_PROPOSAL_REFUSED","channel":"EMAIL","subscribed":False}, | ||
{"notificationType":"CREDIT_TRANSFER_SIGNED_2OF2","channel":"IN_APP","subscribed":False}, | ||
{"notificationType":"CREDIT_TRANSFER_SIGNED_2OF2","channel":"EMAIL","subscribed":False}, | ||
{"notificationType":"CREDIT_TRANSFER_APPROVED","channel":"IN_APP","subscribed":False}, | ||
{"notificationType":"CREDIT_TRANSFER_APPROVED","channel":"EMAIL","subscribed":False}, | ||
{"notificationType":"CREDIT_TRANSFER_DECLINED","channel":"IN_APP","subscribed":False}, | ||
{"notificationType":"CREDIT_TRANSFER_DECLINED","channel":"EMAIL","subscribed":False}, | ||
{"notificationType":"CREDIT_TRANSFER_RESCINDED","channel":"IN_APP","subscribed":False}, | ||
{"notificationType":"CREDIT_TRANSFER_RESCINDED","channel":"EMAIL","subscribed":False}, | ||
{"notificationType":"PVR_APPROVED","channel":"IN_APP","subscribed":False}, | ||
{"notificationType":"PVR_APPROVED","channel":"EMAIL","subscribed":False}, | ||
{"notificationType":"PVR_DECLINED","channel":"IN_APP","subscribed":False}, | ||
{"notificationType":"PVR_DECLINED","channel":"EMAIL","subscribed":False}, | ||
{"notificationType":"DOCUMENT_PENDING_SUBMISSION","channel":"IN_APP","subscribed":False}, | ||
{"notificationType":"DOCUMENT_PENDING_SUBMISSION","channel":"EMAIL","subscribed":False}, | ||
{"notificationType":"DOCUMENT_SUBMITTED","channel":"IN_APP","subscribed":False}, | ||
{"notificationType":"DOCUMENT_SUBMITTED","channel":"EMAIL","subscribed":False}, | ||
{"notificationType":"DOCUMENT_RECEIVED","channel":"IN_APP","subscribed":False}, | ||
{"notificationType":"DOCUMENT_RECEIVED","channel":"EMAIL","subscribed":False}, | ||
{"notificationType":"DOCUMENT_ARCHIVED","channel":"IN_APP","subscribed":False}, | ||
{"notificationType":"DOCUMENT_ARCHIVED","channel":"EMAIL","subscribed":False}, | ||
{"notificationType":"COMPLIANCE_REPORT_DRAFT","channel":"IN_APP","subscribed":False}, | ||
{"notificationType":"COMPLIANCE_REPORT_DRAFT","channel":"EMAIL","subscribed":False}, | ||
{"notificationType":"COMPLIANCE_REPORT_SUBMITTED","channel":"IN_APP","subscribed":False}, | ||
{"notificationType":"COMPLIANCE_REPORT_SUBMITTED","channel":"EMAIL","subscribed":False}, | ||
{"notificationType":"COMPLIANCE_REPORT_REQUESTED_SUPPLEMENTAL","channel":"IN_APP","subscribed":False}, | ||
{"notificationType":"COMPLIANCE_REPORT_REQUESTED_SUPPLEMENTAL","channel":"EMAIL","subscribed":False}, | ||
{"notificationType":"COMPLIANCE_REPORT_ACCEPTED","channel":"IN_APP","subscribed":False}, | ||
{"notificationType":"COMPLIANCE_REPORT_ACCEPTED","channel":"EMAIL","subscribed":False}, | ||
{"notificationType":"COMPLIANCE_REPORT_REJECTED","channel":"IN_APP","subscribed":False}, | ||
{"notificationType":"COMPLIANCE_REPORT_REJECTED","channel":"EMAIL","subscribed":False}, | ||
{"notificationType":"EXCLUSION_REPORT_DRAFT","channel":"IN_APP","subscribed":False}, | ||
{"notificationType":"EXCLUSION_REPORT_DRAFT","channel":"EMAIL","subscribed":False}, | ||
{"notificationType":"EXCLUSION_REPORT_SUBMITTED","channel":"IN_APP","subscribed":False}, | ||
{"notificationType":"EXCLUSION_REPORT_SUBMITTED","channel":"EMAIL","subscribed":False}, | ||
{"notificationType":"EXCLUSION_REPORT_REQUESTED_SUPPLEMENTAL","channel":"IN_APP","subscribed":False}, | ||
{"notificationType":"EXCLUSION_REPORT_REQUESTED_SUPPLEMENTAL","channel":"EMAIL","subscribed":False}, | ||
{"notificationType":"EXCLUSION_REPORT_ACCEPTED","channel":"IN_APP","subscribed":False}, | ||
{"notificationType":"EXCLUSION_REPORT_ACCEPTED","channel":"EMAIL","subscribed":False}, | ||
{"notificationType":"EXCLUSION_REPORT_REJECTED","channel":"IN_APP","subscribed":False}, | ||
{"notificationType":"EXCLUSION_REPORT_REJECTED","channel":"EMAIL","subscribed":False} | ||
] | ||
|
||
notifications_payload_single_false = [ | ||
{"notificationType":"CREDIT_TRANSFER_CREATED","channel":"EMAIL","subscribed":False} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import json | ||
from unittest.mock import patch, Mock | ||
from django.test import TestCase | ||
from .base_test_case import BaseTestCase | ||
from api.models.Organization import Organization | ||
from api.models.Role import Role | ||
from api.models.User import User | ||
from api.models.NotificationChannel import NotificationChannel | ||
from api.notifications.notification_types import NotificationType | ||
from api.notifications.notifications import AMQPNotificationService, NotificationDeliveryFailure, InvalidNotificationArguments | ||
from api.models.NotificationSubscription import NotificationSubscription | ||
from api.tests.payloads.notification_payloads import notifications_payload_active, notifications_payload_inactive, notifications_payload_single_false | ||
|
||
class TestAMQPNotificationService(BaseTestCase): | ||
|
||
@patch('api.notifications.notifications.send_amqp_notification') | ||
def setUp(self, mock_send_amqp): | ||
super().setUp() | ||
|
||
self.org1 = self.organizations['from'] | ||
self.user1 = self.users['fs_user_1'] | ||
self.org2 = self.organizations['to'] | ||
self.user2 = self.users['fs_user_2'] | ||
|
||
self.channel1 = NotificationChannel.objects.get(channel="IN_APP") | ||
self.channel2 = NotificationChannel.objects.get(channel="EMAIL") | ||
|
||
mock_send_amqp.return_value = True | ||
|
||
def test_compute_effective_subscriptions_default(self): | ||
subscriptions = AMQPNotificationService.compute_effective_subscriptions(self.user1) | ||
|
||
# There are two channels and each has one notification type in our setup. So 2 subscriptions. | ||
self.assertEqual(len(subscriptions), 132) | ||
|
||
def test_update_subscription_active(self): | ||
response = self.clients['fs_user_1'].post( | ||
'/api/notifications/update_subscription', | ||
content_type='application/json', | ||
data=json.dumps(notifications_payload_active) | ||
) | ||
|
||
subscription = NotificationSubscription.objects.get( | ||
user=self.user1, | ||
channel=self.channel1, | ||
notification_type=NotificationType.CREDIT_TRANSFER_CREATED | ||
) | ||
|
||
self.assertTrue(subscription.enabled) | ||
|
||
def test_update_subscription_inactive(self): | ||
response = self.clients['fs_user_1'].post( | ||
'/api/notifications/update_subscription', | ||
content_type='application/json', | ||
data=json.dumps(notifications_payload_inactive) | ||
) | ||
|
||
subscription = NotificationSubscription.objects.get( | ||
user=self.user1, | ||
channel=self.channel1, | ||
notification_type=NotificationType.CREDIT_TRANSFER_CREATED | ||
) | ||
|
||
self.assertFalse(subscription.enabled) | ||
|
||
def test_send_notification_global(self): | ||
response = self.clients['fs_user_1'].post( | ||
'/api/notifications/update_subscription', | ||
content_type='application/json', | ||
data=json.dumps(notifications_payload_active) | ||
) | ||
response = self.clients['fs_user_2'].post( | ||
'/api/notifications/update_subscription', | ||
content_type='application/json', | ||
data=json.dumps(notifications_payload_active) | ||
) | ||
with patch('api.notifications.notifications.AMQPNotificationService.send_email_for_notification') as mock_email: | ||
AMQPNotificationService.send_notification( | ||
message="Test Global Message", | ||
is_global=True, | ||
notification_type=NotificationType.CREDIT_TRANSFER_CREATED, | ||
originating_user=self.user1 | ||
) | ||
# Check that the in-app notification was sent to all active users | ||
self.assertEqual(mock_email.call_count, 2) | ||
|
||
def test_send_notification_specific_org(self): | ||
response = self.clients['fs_user_1'].post( | ||
'/api/notifications/update_subscription', | ||
content_type='application/json', | ||
data=json.dumps(notifications_payload_active) | ||
) | ||
with patch('api.notifications.notifications.AMQPNotificationService.send_email_for_notification') as mock_email: | ||
AMQPNotificationService.send_notification( | ||
message="Test Message to Org1", | ||
interested_organization=self.org1, | ||
notification_type=NotificationType.CREDIT_TRANSFER_CREATED, | ||
originating_user=self.user2 | ||
) | ||
# Check that the in-app notification was sent to all users in the specified organization | ||
self.assertEqual(mock_email.call_count, 1) | ||
|
||
def test_invalid_notification_args(self): | ||
with self.assertRaises(InvalidNotificationArguments): | ||
AMQPNotificationService.send_notification( | ||
message=None, # Invalid as message is required | ||
interested_organization=self.org1, | ||
notification_type=NotificationType.CREDIT_TRANSFER_CREATED, | ||
originating_user=self.user1 | ||
) | ||
|
||
def test_user_does_not_receive_unsubscribed_notification(self): | ||
# Deactivate a particular notification for user1 | ||
response = self.clients['fs_user_1'].post( | ||
'/api/notifications/update_subscription', | ||
content_type='application/json', | ||
data=json.dumps(notifications_payload_single_false) | ||
) | ||
with patch('api.notifications.notifications.AMQPNotificationService.send_email_for_notification') as mock_email: | ||
AMQPNotificationService.send_notification( | ||
message="Test Message to Org1", | ||
interested_organization=self.org1, | ||
notification_type=NotificationType.CREDIT_TRANSFER_CREATED, | ||
originating_user=self.user2 | ||
) | ||
|
||
# Check that the in-app notification was NOT sent to user1 | ||
mock_email.assert_not_called() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.