diff --git a/web/tests/lib/events.js b/web/tests/lib/events.js index 9632d4b20f..ee7754e712 100644 --- a/web/tests/lib/events.js +++ b/web/tests/lib/events.js @@ -625,6 +625,7 @@ exports.fixtures = { content: "Hello there!", rendered_content: "
Hello there!
", scheduled_delivery_timestamp: 1681662420, + failed: false, }, ], }, @@ -645,6 +646,7 @@ exports.fixtures = { content: "Hello there!", rendered_content: "Hello there!
", scheduled_delivery_timestamp: 1681662420, + failed: false, }, }, diff --git a/zerver/lib/event_schema.py b/zerver/lib/event_schema.py index 32920c03e8..74fedea462 100644 --- a/zerver/lib/event_schema.py +++ b/zerver/lib/event_schema.py @@ -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")), diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py index b2ecafd696..59297550c5 100644 --- a/zerver/tests/test_events.py +++ b/zerver/tests/test_events.py @@ -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])