1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15+ from typing import Tuple
16+
1517from twisted .test .proto_helpers import MemoryReactor
1618
1719from synapse .rest import admin
2224
2325from tests .unittest import HomeserverTestCase
2426
25- USER_ID = "@user:example.com"
26-
2727
2828class EventPushActionsStoreTestCase (HomeserverTestCase ):
2929 servlets = [
@@ -38,21 +38,13 @@ def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:
3838 assert persist_events_store is not None
3939 self .persist_events_store = persist_events_store
4040
41- def test_get_unread_push_actions_for_user_in_range_for_http (self ) -> None :
42- self .get_success (
43- self .store .get_unread_push_actions_for_user_in_range_for_http (
44- USER_ID , 0 , 1000 , 20
45- )
46- )
41+ def _create_users_and_room (self ) -> Tuple [str , str , str , str , str ]:
42+ """
43+ Creates two users and a shared room.
4744
48- def test_get_unread_push_actions_for_user_in_range_for_email (self ) -> None :
49- self .get_success (
50- self .store .get_unread_push_actions_for_user_in_range_for_email (
51- USER_ID , 0 , 1000 , 20
52- )
53- )
54-
55- def test_count_aggregation (self ) -> None :
45+ Returns:
46+ Tuple of (user 1 ID, user 1 token, user 2 ID, user 2 token, room ID).
47+ """
5648 # Create a user to receive notifications and send receipts.
5749 user_id = self .register_user ("user1235" , "pass" )
5850 token = self .login ("user1235" , "pass" )
@@ -65,6 +57,70 @@ def test_count_aggregation(self) -> None:
6557 room_id = self .helper .create_room_as (user_id , tok = token )
6658 self .helper .join (room_id , other_id , tok = other_token )
6759
60+ return user_id , token , other_id , other_token , room_id
61+
62+ def test_get_unread_push_actions_for_user_in_range (self ) -> None :
63+ """Test getting unread push actions for HTTP and email pushers."""
64+ user_id , token , _ , other_token , room_id = self ._create_users_and_room ()
65+
66+ # Create two events, one of which is a highlight.
67+ self .helper .send_event (
68+ room_id ,
69+ type = "m.room.message" ,
70+ content = {"msgtype" : "m.text" , "body" : "msg" },
71+ tok = other_token ,
72+ )
73+ event_id = self .helper .send_event (
74+ room_id ,
75+ type = "m.room.message" ,
76+ content = {"msgtype" : "m.text" , "body" : user_id },
77+ tok = other_token ,
78+ )["event_id" ]
79+
80+ # Fetch unread actions for HTTP pushers.
81+ http_actions = self .get_success (
82+ self .store .get_unread_push_actions_for_user_in_range_for_http (
83+ user_id , 0 , 1000 , 20
84+ )
85+ )
86+ self .assertEqual (2 , len (http_actions ))
87+
88+ # Fetch unread actions for email pushers.
89+ email_actions = self .get_success (
90+ self .store .get_unread_push_actions_for_user_in_range_for_email (
91+ user_id , 0 , 1000 , 20
92+ )
93+ )
94+ self .assertEqual (2 , len (email_actions ))
95+
96+ # Send a receipt, which should clear any actions.
97+ self .get_success (
98+ self .store .insert_receipt (
99+ room_id ,
100+ "m.read" ,
101+ user_id = user_id ,
102+ event_ids = [event_id ],
103+ thread_id = None ,
104+ data = {},
105+ )
106+ )
107+ http_actions = self .get_success (
108+ self .store .get_unread_push_actions_for_user_in_range_for_http (
109+ user_id , 0 , 1000 , 20
110+ )
111+ )
112+ self .assertEqual ([], http_actions )
113+ email_actions = self .get_success (
114+ self .store .get_unread_push_actions_for_user_in_range_for_email (
115+ user_id , 0 , 1000 , 20
116+ )
117+ )
118+ self .assertEqual ([], email_actions )
119+
120+ def test_count_aggregation (self ) -> None :
121+ # Create a user to receive notifications and send receipts.
122+ user_id , token , _ , other_token , room_id = self ._create_users_and_room ()
123+
68124 last_event_id : str
69125
70126 def _assert_counts (noitf_count : int , highlight_count : int ) -> None :
0 commit comments