@@ -196,6 +196,32 @@ def config_setup(self, config: Dict[str, Any]) -> None:
196196 },
197197 }
198198
199+ config ["apps" ]["com.example.gcm.apiv1.disabled-badges" ] = {
200+ "type" : "tests.test_gcm.TestGcmPushkin" ,
201+ "api_version" : "v1" ,
202+ "project_id" : "example_project" ,
203+ "service_account_file" : self .service_account_file .name ,
204+ "send_badge_counts" : False ,
205+ "fcm_options" : {
206+ "android" : {
207+ "notification" : {
208+ "body" : {
209+ "test body" ,
210+ },
211+ },
212+ },
213+ "apns" : {
214+ "payload" : {
215+ "aps" : {
216+ "content-available" : 1 ,
217+ "mutable-content" : 1 ,
218+ "alert" : "" ,
219+ },
220+ },
221+ },
222+ },
223+ }
224+
199225 def tearDown (self ) -> None :
200226 self .service_account_file .close ()
201227
@@ -235,7 +261,6 @@ def test_expected(self) -> None:
235261 "sender" : "@exampleuser:matrix.org" ,
236262 "room_name" : "Mission Control" ,
237263 "room_alias" : "#exampleroom:matrix.org" ,
238- "membership" : None ,
239264 "sender_display_name" : "Major Tom" ,
240265 "content" : {
241266 "msgtype" : "m.text" ,
@@ -284,7 +309,6 @@ def test_expected_api_v1(self) -> None:
284309 "sender" : "@exampleuser:matrix.org" ,
285310 "room_name" : "Mission Control" ,
286311 "room_alias" : "#exampleroom:matrix.org" ,
287- "membership" : None ,
288312 "sender_display_name" : "Major Tom" ,
289313 "content_msgtype" : "m.text" ,
290314 "content_body" : "I'm floating in a most peculiar way." ,
@@ -500,7 +524,6 @@ async def side_effect(*_args: Any, **_kwargs: Any) -> None:
500524 "sender" : "@exampleuser:matrix.org" ,
501525 "room_name" : "Mission Control" ,
502526 "room_alias" : "#exampleroom:matrix.org" ,
503- "membership" : None ,
504527 "sender_display_name" : "Major Tom" ,
505528 "content_msgtype" : "m.text" ,
506529 "content_body" : "I'm floating in a most peculiar way." ,
@@ -584,7 +607,6 @@ def test_send_badge_counts(self) -> None:
584607 "other" : 1 ,
585608 },
586609 "event_id" : "$qTOWWTEL48yPm3uT-gdNhFcoHxfKbZuqRVnnWWSkGBs" ,
587- "membership" : None ,
588610 "prio" : "high" ,
589611 "room_alias" : "#exampleroom:matrix.org" ,
590612 "room_id" : "!slw48wfj34rtnrf:example.com" ,
@@ -595,6 +617,168 @@ def test_send_badge_counts(self) -> None:
595617 },
596618 )
597619
620+ def test_send_badge_counts_api_v1 (self ) -> None :
621+ """
622+ Tests that the config option `send_badge_counts` being disabled in API v1
623+ actually removes the unread and missed call count from notifications
624+ """
625+ gcm = self .get_test_pushkin ("com.example.gcm.apiv1.disabled-badges" )
626+ gcm .preload_with_response (
627+ 200 , {"results" : [{"registration_id" : "spqr_new" , "message_id" : "msg42" }]}
628+ )
629+
630+ resp = self ._request (
631+ self ._make_dummy_notification (
632+ [
633+ {
634+ "app_id" : "com.example.gcm.apiv1.disabled-badges" ,
635+ "pushkey" : "spqr" ,
636+ "pushkey_ts" : 42 ,
637+ }
638+ ]
639+ )
640+ )
641+
642+ self .assertEqual (resp , {"rejected" : []})
643+ assert gcm .last_request_body is not None
644+
645+ # No 'unread' or 'missed_call' fields are present
646+ self .assertEqual (
647+ gcm .last_request_body ["message" ]["data" ],
648+ {
649+ "content_body" : "I'm floating in a most peculiar way." ,
650+ "content_msgtype" : "m.text" ,
651+ "event_id" : "$qTOWWTEL48yPm3uT-gdNhFcoHxfKbZuqRVnnWWSkGBs" ,
652+ "prio" : "high" ,
653+ "room_alias" : "#exampleroom:matrix.org" ,
654+ "room_id" : "!slw48wfj34rtnrf:example.com" ,
655+ "room_name" : "Mission Control" ,
656+ "sender" : "@exampleuser:matrix.org" ,
657+ "sender_display_name" : "Major Tom" ,
658+ "type" : "m.room.message" ,
659+ },
660+ )
661+
662+ def test_send_badge_counts_with_badge_only_notification (self ) -> None :
663+ """
664+ Tests that the config option `send_badge_counts` being disabled
665+ prevents badge only notifications from being sent at all.
666+ """
667+ gcm = self .get_test_pushkin ("fcm-with-disabled-badge-count" )
668+ gcm .preload_with_response (
669+ 200 , {"results" : [{"registration_id" : "spqr_new" , "message_id" : "msg42" }]}
670+ )
671+
672+ resp = self ._request (
673+ self ._make_dummy_notification_badge_only (
674+ [
675+ {
676+ "app_id" : "fcm-with-disabled-badge-count" ,
677+ "pushkey" : "spqr" ,
678+ "pushkey_ts" : 42 ,
679+ }
680+ ]
681+ )
682+ )
683+
684+ self .assertEqual (resp , {"rejected" : []})
685+ self .assertEqual (gcm .num_requests , 0 )
686+
687+ def test_send_badge_counts_with_badge_only_notification_api_v1 (self ) -> None :
688+ """
689+ Tests that the config option `send_badge_counts` being disabled
690+ in API v1 prevents badge only notifications from being sent at all.
691+ """
692+ gcm = self .get_test_pushkin ("com.example.gcm.apiv1.disabled-badges" )
693+ gcm .preload_with_response (
694+ 200 , {"results" : [{"registration_id" : "spqr_new" , "message_id" : "msg42" }]}
695+ )
696+
697+ resp = self ._request (
698+ self ._make_dummy_notification_badge_only (
699+ [
700+ {
701+ "app_id" : "com.example.gcm.apiv1.disabled-badges" ,
702+ "pushkey" : "spqr" ,
703+ "pushkey_ts" : 42 ,
704+ }
705+ ]
706+ )
707+ )
708+
709+ self .assertEqual (resp , {"rejected" : []})
710+ self .assertEqual (gcm .num_requests , 0 )
711+
712+ def test_send_badge_counts_with_event_id_only_notification (self ) -> None :
713+ """
714+ Tests that the config option `send_badge_counts` being disabled
715+ actually removes the unread and missed call count from notifications
716+ """
717+ gcm = self .get_test_pushkin ("fcm-with-disabled-badge-count" )
718+ gcm .preload_with_response (
719+ 200 , {"results" : [{"registration_id" : "spqr_new" , "message_id" : "msg42" }]}
720+ )
721+
722+ resp = self ._request (
723+ self ._make_dummy_notification_event_id_only (
724+ [
725+ {
726+ "app_id" : "fcm-with-disabled-badge-count" ,
727+ "pushkey" : "spqr" ,
728+ "pushkey_ts" : 42 ,
729+ }
730+ ]
731+ )
732+ )
733+
734+ self .assertEqual (resp , {"rejected" : []})
735+ assert gcm .last_request_body is not None
736+
737+ # No 'unread' or 'missed_call' fields are present
738+ self .assertEqual (
739+ gcm .last_request_body ["data" ],
740+ {
741+ "event_id" : "$qTOWWTEL48yPm3uT-gdNhFcoHxfKbZuqRVnnWWSkGBs" ,
742+ "prio" : "high" ,
743+ "room_id" : "!slw48wfj34rtnrf:example.com" ,
744+ },
745+ )
746+
747+ def test_send_badge_counts_with_event_id_only_notification_api_v1 (self ) -> None :
748+ """
749+ Tests that the config option `send_badge_counts` being disabled in API v1
750+ actually removes the unread and missed call count from notifications
751+ """
752+ gcm = self .get_test_pushkin ("com.example.gcm.apiv1.disabled-badges" )
753+ gcm .preload_with_response (
754+ 200 , {"results" : [{"registration_id" : "spqr_new" , "message_id" : "msg42" }]}
755+ )
756+
757+ resp = self ._request (
758+ self ._make_dummy_notification_event_id_only (
759+ [
760+ {
761+ "app_id" : "com.example.gcm.apiv1.disabled-badges" ,
762+ "pushkey" : "spqr" ,
763+ "pushkey_ts" : 42 ,
764+ }
765+ ]
766+ )
767+ )
768+
769+ self .assertEqual (resp , {"rejected" : []})
770+ assert gcm .last_request_body is not None
771+
772+ # No 'unread' or 'missed_call' fields are present
773+ self .assertEqual (
774+ gcm .last_request_body ["message" ]["data" ],
775+ {
776+ "event_id" : "$qTOWWTEL48yPm3uT-gdNhFcoHxfKbZuqRVnnWWSkGBs" ,
777+ "prio" : "high" ,
778+ "room_id" : "!slw48wfj34rtnrf:example.com" ,
779+ },
780+ )
781+
598782 def test_api_v1_large_fields (self ) -> None :
599783 """
600784 Tests the gcm pushkin truncates unusually large fields. Includes large
@@ -644,7 +828,6 @@ def test_api_v1_large_fields(self) -> None:
644828 xxxxxxxxxxooooooooooxxxxxxxxxxooooooooooxxxxxxxxxxooooooooooxxxxxxxxxx\
645829 ooooooooooxxxxxxxxxxooooooooooxxxxxxxxxxoooooooooox…" ,
646830 "room_alias" : "#exampleroom:matrix.org" ,
647- "membership" : None ,
648831 "sender_display_name" : "Major Tom" ,
649832 "content_msgtype" : "m.text" ,
650833 "content_body" : "I'm floating in a most peculiar way." ,
0 commit comments