diff --git a/tests/storage/test_receipts.py b/tests/storage/test_receipts.py index c89bfff24171..9a70982cf97c 100644 --- a/tests/storage/test_receipts.py +++ b/tests/storage/test_receipts.py @@ -270,3 +270,46 @@ def test_get_last_receipt_event_id_for_user(self) -> None: ) ) self.assertEqual(res, event2_1_id) + + def test_receipts_clear_push_actions(self) -> None: + event_1_id = self.create_and_send_event( + self.room_id1, UserID.from_string(OTHER_USER_ID) + ) + event_2_id = self.create_and_send_event( + self.room_id1, UserID.from_string(OTHER_USER_ID) + ) + + def _assert_push_action_count(expected: int): + result = self.get_success( + self.store.db_pool.simple_select_list( + table="event_push_actions", + keyvalues={"1": 1}, + retcols=("event_id",), + desc="", + ) + ) + self.assertEqual(len(result), expected) + + # Check we have 2 push actions pending + _assert_push_action_count(2) + + # Send a read receipt for the first event + self.get_success( + self.store.insert_receipt( + self.room_id1, ReceiptTypes.READ, OUR_USER_ID, [event_1_id], {} + ) + ) + + # Check that we now have a single push action pending + _assert_push_action_count(1) + + # Send a read receipt for the second event + self.get_success( + self.store.insert_receipt( + self.room_id1, ReceiptTypes.READ, OUR_USER_ID, [event_2_id], {} + ) + ) + + # Check that we have no push actions pending + _assert_push_action_count(0) +