tests: Update events and schemas for scheduled message events.

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

Adds the missing 'failed' field to the scheduled message events
in `web/tests/lib/events.js` as well.
This commit is contained in:
Lauryn Menard 2023-10-03 17:02:25 +02:00 committed by Tim Abbott
parent 6ad3ec0891
commit ca5d1c1265
3 changed files with 57 additions and 5 deletions

View File

@ -625,6 +625,7 @@ exports.fixtures = {
content: "Hello there!",
rendered_content: "<p>Hello there!</p>",
scheduled_delivery_timestamp: 1681662420,
failed: false,
},
],
},
@ -645,6 +646,7 @@ exports.fixtures = {
content: "Hello there!",
rendered_content: "<p>Hello there!</p>",
scheduled_delivery_timestamp: 1681662420,
failed: false,
},
},

View File

@ -1188,6 +1188,48 @@ restart_event = event_dict_type(
)
check_restart_event = make_checker(restart_event)
scheduled_message_fields = DictType(
required_keys=[
("scheduled_message_id", int),
("type", EnumType(["stream", "private"])),
("to", UnionType([ListType(int), int])),
("content", str),
("rendered_content", str),
("scheduled_delivery_timestamp", int),
("failed", bool),
],
optional_keys=[
("topic", str),
],
)
scheduled_messages_add_event = event_dict_type(
required_keys=[
("type", Equals("scheduled_messages")),
("op", Equals("add")),
("scheduled_messages", ListType(scheduled_message_fields)),
]
)
check_scheduled_message_add = make_checker(scheduled_messages_add_event)
scheduled_messages_update_event = event_dict_type(
required_keys=[
("type", Equals("scheduled_messages")),
("op", Equals("update")),
("scheduled_message", scheduled_message_fields),
]
)
check_scheduled_message_update = make_checker(scheduled_messages_update_event)
scheduled_messages_remove_event = event_dict_type(
required_keys=[
("type", Equals("scheduled_messages")),
("op", Equals("remove")),
("scheduled_message_id", int),
]
)
check_scheduled_message_remove = make_checker(scheduled_messages_remove_event)
stream_create_event = event_dict_type(
required_keys=[
("type", Equals("stream")),

View File

@ -165,6 +165,9 @@ from zerver.lib.event_schema import (
check_realm_user_add,
check_realm_user_remove,
check_realm_user_update,
check_scheduled_message_add,
check_scheduled_message_remove,
check_scheduled_message_update,
check_stream_create,
check_stream_delete,
check_stream_update,
@ -3623,7 +3626,8 @@ class ScheduledMessagesEventsTest(BaseAction):
convert_to_UTC(dateparser("2023-04-19 18:24:56")),
self.user_profile.realm,
)
self.verify_action(action)
events = self.verify_action(action)
check_scheduled_message_add("events[0]", events[0])
def test_create_event_with_existing_scheduled_messages(self) -> None:
# Create stream scheduled message
@ -3649,7 +3653,8 @@ class ScheduledMessagesEventsTest(BaseAction):
convert_to_UTC(dateparser("2023-04-19 18:24:56")),
self.user_profile.realm,
)
self.verify_action(action)
events = self.verify_action(action)
check_scheduled_message_add("events[0]", events[0])
def test_private_scheduled_message_create_event(self) -> None:
# Create direct scheduled message
@ -3663,7 +3668,8 @@ class ScheduledMessagesEventsTest(BaseAction):
convert_to_UTC(dateparser("2023-04-19 18:24:56")),
self.user_profile.realm,
)
self.verify_action(action)
events = self.verify_action(action)
check_scheduled_message_add("events[0]", events[0])
def test_scheduled_message_edit_event(self) -> None:
scheduled_message_id = check_schedule_message(
@ -3687,7 +3693,8 @@ class ScheduledMessagesEventsTest(BaseAction):
convert_to_UTC(dateparser("2023-04-20 18:24:56")),
self.user_profile.realm,
)
self.verify_action(action)
events = self.verify_action(action)
check_scheduled_message_update("events[0]", events[0])
def test_scheduled_message_delete_event(self) -> None:
scheduled_message_id = check_schedule_message(
@ -3701,4 +3708,5 @@ class ScheduledMessagesEventsTest(BaseAction):
self.user_profile.realm,
)
action = lambda: delete_scheduled_message(self.user_profile, scheduled_message_id)
self.verify_action(action)
events = self.verify_action(action)
check_scheduled_message_remove("events[0]", events[0])