Added tests for update_message
@@ -1166,17 +1166,33 @@ class TestStateRegistryImpl:
):
raise NotImplementedError
- @pytest.mark.xfail(reason="Not yet implemented")
def test_update_message_when_existing_message_uncached_returns_None(
self, registry: state_registry_impl.StateRegistryImpl
):
- raise NotImplementedError
+ registry._message_cache = {}
+ payload = {"message_id": "1234"}
+
+ diff = registry.update_message(payload)
+
+ assert diff is None
- @pytest.mark.xfail(reason="Not yet implemented")
def test_update_message_when_existing_message_cached_returns_old_state_copy_and_updated_new_state(
self, registry: state_registry_impl.StateRegistryImpl
):
- raise NotImplementedError
+ original_message_obj = _helpers.mock_model(messages.Message, id=123)
+ cloned_message_obj = _helpers.mock_model(messages.Message, id=123)
+ original_message_obj.copy = mock.MagicMock(spec_set=original_message_obj.copy, return_value=cloned_message_obj)
+ registry._message_cache = {original_message_obj.id : original_message_obj}
+ payload = {"message_id": "123"}
+
+ old, new = registry.update_message(payload)
+
+ assert old is not None
+ assert new is not None
+
+ assert new is original_message_obj, "existing message was not used as target for update!"
+ assert old is cloned_message_obj, "existing message did not get the old state copied and returned!"
+
@pytest.mark.xfail(reason="Not yet implemented")
def test_update_role_when_existing_role_does_not_exist_returns_None(
