summary refs log tree commit diff
path: root/tests/rest/client/test_sync.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2024-07-30 13:34:44 +0100
committerErik Johnston <erik@matrix.org>2024-07-30 13:34:44 +0100
commit394c25a7fecfb56eb67dfba4cab26a7e405724ac (patch)
tree3d01fb5d039fc2d5cdf573d99ba3a88816c5b9fa /tests/rest/client/test_sync.py
parentOnly mark as updated if entry has changed (diff)
downloadsynapse-394c25a7fecfb56eb67dfba4cab26a7e405724ac.tar.xz
Remember previous timeline limit
Diffstat (limited to 'tests/rest/client/test_sync.py')
-rw-r--r--tests/rest/client/test_sync.py47
1 files changed, 36 insertions, 11 deletions
diff --git a/tests/rest/client/test_sync.py b/tests/rest/client/test_sync.py
index 5abf1041be..8d5fd30fdd 100644
--- a/tests/rest/client/test_sync.py
+++ b/tests/rest/client/test_sync.py
@@ -39,7 +39,8 @@ from synapse.api.constants import (
 )
 from synapse.api.room_versions import RoomVersions
 from synapse.events import EventBase
-from synapse.handlers.sliding_sync import StateValues
+from synapse.handlers.sliding_sync import RoomSyncConfig, StateValues
+from synapse.http.servlet import validate_json_object
 from synapse.rest.client import (
     devices,
     knock,
@@ -53,6 +54,7 @@ from synapse.rest.client import (
 from synapse.server import HomeServer
 from synapse.types import (
     JsonDict,
+    Requester,
     RoomStreamToken,
     SlidingSyncStreamToken,
     StreamKeyType,
@@ -60,6 +62,7 @@ from synapse.types import (
     UserID,
 )
 from synapse.types.handlers import SlidingSyncConfig
+from synapse.types.rest.client import SlidingSyncBody
 from synapse.util import Clock
 from synapse.util.stringutils import random_string
 
@@ -1357,6 +1360,22 @@ class SlidingSyncBase(unittest.HomeserverTestCase):
                 "Expected `notifier.wait_for_events(...)` to be triggered"
             )
 
+    def make_sync_config(
+        self, user: UserID, requester: Requester, content: JsonDict
+    ) -> SlidingSyncConfig:
+        """Helper function to turn a dict sync body to a sync config"""
+        body = validate_json_object(content, SlidingSyncBody)
+
+        sync_config = SlidingSyncConfig(
+            user=user,
+            requester=requester,
+            conn_id=body.conn_id,
+            lists=body.lists,
+            room_subscriptions=body.room_subscriptions,
+            extensions=body.extensions,
+        )
+        return sync_config
+
 
 class SlidingSyncTestCase(SlidingSyncBase):
     """
@@ -4538,7 +4557,6 @@ class SlidingSyncTestCase(SlidingSyncBase):
         self.helper.send(room_id1, "msg", tok=user1_tok)
 
         timeline_limit = 5
-        conn_id = "conn_id"
         sync_body = {
             "lists": {
                 "foo-list": {
@@ -4584,19 +4602,22 @@ class SlidingSyncTestCase(SlidingSyncBase):
         requester = self.get_success(
             self.hs.get_auth().get_user_by_access_token(user1_tok)
         )
-        sync_config = SlidingSyncConfig(
-            user=requester.user,
-            requester=requester,
-            conn_id=conn_id,
+        sync_config = self.make_sync_config(
+            user=requester.user, requester=requester, content=sync_body
         )
 
         parsed_initial_from_token = self.get_success(
             SlidingSyncStreamToken.from_string(self.store, initial_from_token)
         )
+        assert sync_config.lists
+        room_configs = {
+            room_id1: RoomSyncConfig.from_room_config(sync_config.lists["foo-list"])
+        }
         connection_position = self.get_success(
             sliding_sync_handler.connection_store.record_rooms(
                 sync_config,
-                parsed_initial_from_token,
+                room_configs=room_configs,
+                from_token=parsed_initial_from_token,
                 sent_room_ids=[],
                 unsent_room_ids=[room_id1],
             )
@@ -4646,7 +4667,6 @@ class SlidingSyncTestCase(SlidingSyncBase):
 
         self.helper.send(room_id1, "msg", tok=user1_tok)
 
-        conn_id = "conn_id"
         sync_body = {
             "lists": {
                 "foo-list": {
@@ -4693,19 +4713,24 @@ class SlidingSyncTestCase(SlidingSyncBase):
         requester = self.get_success(
             self.hs.get_auth().get_user_by_access_token(user1_tok)
         )
-        sync_config = SlidingSyncConfig(
+        sync_config = self.make_sync_config(
             user=requester.user,
             requester=requester,
-            conn_id=conn_id,
+            content=sync_body,
         )
 
         parsed_initial_from_token = self.get_success(
             SlidingSyncStreamToken.from_string(self.store, initial_from_token)
         )
+        assert sync_config.lists
+        room_configs = {
+            room_id1: RoomSyncConfig.from_room_config(sync_config.lists["foo-list"])
+        }
         connection_position = self.get_success(
             sliding_sync_handler.connection_store.record_rooms(
                 sync_config,
-                parsed_initial_from_token,
+                room_configs=room_configs,
+                from_token=parsed_initial_from_token,
                 sent_room_ids=[],
                 unsent_room_ids=[room_id1],
             )