mirror of
https://github.com/zulip/zulip.git
synced 2025-11-16 11:52:01 +00:00
worker: Ensure complete coverage for PushNotificationsWorker.
The `# nocoverage` was unnecessary apart from for the compatibility code,
so add a test for that code and remove the `# nocoverage`.
The `message_id` -> `message_ids` conversion was done in
9869153ae8.
This commit is contained in:
committed by
Tim Abbott
parent
801ebba7c7
commit
e63e86dcb2
@@ -301,6 +301,23 @@ class WorkerTest(ZulipTestCase):
|
||||
* 2,
|
||||
)
|
||||
|
||||
# This verifies the compatibility code for the `message_id` -> `message_ids`
|
||||
# conversion for "remove" events.
|
||||
with patch(
|
||||
"zerver.worker.queue_processors.handle_remove_push_notification"
|
||||
) as mock_handle_remove, patch(
|
||||
"zerver.worker.queue_processors.initialize_push_notifications"
|
||||
):
|
||||
event_new = dict(
|
||||
user_profile_id=10,
|
||||
message_id=33,
|
||||
type="remove",
|
||||
)
|
||||
fake_client.enqueue("missedmessage_mobile_notifications", event_new)
|
||||
worker.start()
|
||||
# The `message_id` field should have been converted to a list with a single element.
|
||||
mock_handle_remove.assert_called_once_with(10, [33])
|
||||
|
||||
@patch("zerver.worker.queue_processors.mirror_email")
|
||||
def test_mirror_worker(self, mock_mirror_email: MagicMock) -> None:
|
||||
fake_client = self.FakeClient()
|
||||
|
||||
@@ -667,7 +667,7 @@ class EmailSendingWorker(LoopQueueProcessingWorker):
|
||||
|
||||
|
||||
@assign_queue("missedmessage_mobile_notifications")
|
||||
class PushNotificationsWorker(QueueProcessingWorker): # nocoverage
|
||||
class PushNotificationsWorker(QueueProcessingWorker):
|
||||
def start(self) -> None:
|
||||
# initialize_push_notifications doesn't strictly do anything
|
||||
# beyond printing some logging warnings if push notifications
|
||||
@@ -679,7 +679,13 @@ class PushNotificationsWorker(QueueProcessingWorker): # nocoverage
|
||||
try:
|
||||
if event.get("type", "add") == "remove":
|
||||
message_ids = event.get("message_ids")
|
||||
if message_ids is None: # legacy task across an upgrade
|
||||
if message_ids is None:
|
||||
# TODO/compatibility: Previously, we sent only one `message_id` in
|
||||
# a payload for notification remove events. This was later changed
|
||||
# to send a list of `message_ids` (with that field name), but we need
|
||||
# compatibility code for events present in the queue during upgrade.
|
||||
# Remove this when one can no longer upgrade from 1.9.2 (or earlier)
|
||||
# to any version after 2.0.0
|
||||
message_ids = [event["message_id"]]
|
||||
handle_remove_push_notification(event["user_profile_id"], message_ids)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user