tests: Update events and schemas for drafts events.

Updates the testing for draft event schemas to be fully checked by
`zerver/tests/test_events.py` and `tools/check-schema`.

Also, corrects the type for the timestamp field in Draft objects
in the OpenAPI documentation.
This commit is contained in:
Lauryn Menard 2023-10-03 17:07:22 +02:00 committed by Tim Abbott
parent ca5d1c1265
commit f2ee4e8288
3 changed files with 54 additions and 7 deletions

View File

@ -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")),

View File

@ -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

View File

@ -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):