Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

tests: Update events and schemas for drafts events.

Lauryn Menardf2ee4e8288d4
diff --git a/zerver/lib/event_schema.py b/zerver/lib/event_schema.py
index 74fedea4629..aab4e396f71 100644
--- a/zerver/lib/event_schema.py
+++ b/zerver/lib/event_schema.py
@@ -259,6 +259,47 @@ def check_delete_message(
assert set(event.keys()) == keys
+draft_fields = DictType(
+ required_keys=[
+ ("id", int),
+ ("type", EnumType(["", "stream", "private"])),
+ ("to", ListType(int)),
+ ("topic", str),
+ ("content", str),
+ ],
+ optional_keys=[
+ ("timestamp", int),
+ ],
+)
+
+drafts_add_event = event_dict_type(
+ required_keys=[
+ ("type", Equals("drafts")),
+ ("op", Equals("add")),
+ ("drafts", ListType(draft_fields)),
+ ]
+)
+check_draft_add = make_checker(drafts_add_event)
+
+drafts_update_event = event_dict_type(
+ required_keys=[
+ ("type", Equals("drafts")),
+ ("op", Equals("update")),
+ ("draft", draft_fields),
+ ]
+)
+check_draft_update = make_checker(drafts_update_event)
+
+drafts_remove_event = event_dict_type(
+ required_keys=[
+ ("type", Equals("drafts")),
+ ("op", Equals("remove")),
+ ("draft_id", int),
+ ]
+)
+check_draft_remove = make_checker(drafts_remove_event)
+
+
has_zoom_token_event = event_dict_type(
required_keys=[
("type", Equals("has_zoom_token")),
diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml
index 318b1c5c95b..313629ef349 100644
--- a/zerver/openapi/zulip.yaml
+++ b/zerver/openapi/zulip.yaml
@@ -5085,7 +5085,7 @@ paths:
"to": [3],
"topic": "sync drafts",
"content": "Let's add backend support for syncing drafts.",
- "timestamp": 1595479019.43915,
+ "timestamp": 1595479019,
},
{
"id": 2,
@@ -5093,7 +5093,7 @@ paths:
"to": [4],
"topic": "",
"content": "What if we made it possible to sync drafts in Zulip?",
- "timestamp": 1595479020.43916,
+ "timestamp": 1595479019,
},
{
"id": 3,
@@ -5101,7 +5101,7 @@ paths:
"to": [4, 10],
"topic": "",
"content": "What if we made it possible to sync drafts in Zulip?",
- "timestamp": 1595479021.43916,
+ "timestamp": 1595479019,
},
],
}
@@ -18785,7 +18785,7 @@ components:
description: |
The body of the draft. Should not contain null bytes.
timestamp:
- type: number
+ type: integer
description: |
A Unix timestamp (seconds only) representing when the draft was
last edited. When creating a draft, this key need not be present
diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py
index 59297550c55..7097dd3dd51 100644
--- a/zerver/tests/test_events.py
+++ b/zerver/tests/test_events.py
@@ -137,6 +137,9 @@ from zerver.lib.event_schema import (
check_default_stream_groups,
check_default_streams,
check_delete_message,
+ check_draft_add,
+ check_draft_remove,
+ check_draft_update,
check_has_zoom_token,
check_heartbeat,
check_hotspots,
@@ -3583,7 +3586,8 @@ class DraftActionTest(BaseAction):
timestamp=1596820995,
)
action = lambda: do_create_drafts([dummy_draft], self.user_profile)
- self.verify_action(action)
+ events = self.verify_action(action)
+ check_draft_add("events[0]", events[0])
def test_draft_edit_event(self) -> None:
self.do_enable_drafts_synchronization(self.user_profile)
@@ -3597,7 +3601,8 @@ class DraftActionTest(BaseAction):
draft_id = do_create_drafts([dummy_draft], self.user_profile)[0].id
dummy_draft.content = "Some more sample draft content"
action = lambda: do_edit_draft(draft_id, dummy_draft, self.user_profile)
- self.verify_action(action)
+ events = self.verify_action(action)
+ check_draft_update("events[0]", events[0])
def test_draft_delete_event(self) -> None:
self.do_enable_drafts_synchronization(self.user_profile)
@@ -3610,7 +3615,8 @@ class DraftActionTest(BaseAction):
)
draft_id = do_create_drafts([dummy_draft], self.user_profile)[0].id
action = lambda: do_delete_draft(draft_id, self.user_profile)
- self.verify_action(action)
+ events = self.verify_action(action)
+ check_draft_remove("events[0]", events[0])
class ScheduledMessagesEventsTest(BaseAction):