diff --git a/h/presenters/mention_json.py b/h/presenters/mention_json.py index ebd61188f41..b0098f37f53 100644 --- a/h/presenters/mention_json.py +++ b/h/presenters/mention_json.py @@ -1,6 +1,7 @@ from typing import Any from h.models import Mention +from h.util.user import format_userid class MentionJSONPresenter: @@ -12,7 +13,10 @@ def __init__(self, mention: Mention): def asdict(self) -> dict[str, Any]: return { "userid": self._mention.user.userid, - "username": self._mention.username, + "original_userid": format_userid( + self._mention.username, self._mention.user.authority + ), + "username": self._mention.user.username, "display_name": self._mention.user.display_name, "link": self._mention.user.uri, } diff --git a/tests/unit/h/presenters/mention_json_test.py b/tests/unit/h/presenters/mention_json_test.py index 23cf9db902f..b5251c9f914 100644 --- a/tests/unit/h/presenters/mention_json_test.py +++ b/tests/unit/h/presenters/mention_json_test.py @@ -2,6 +2,7 @@ from h.models import Mention from h.presenters.mention_json import MentionJSONPresenter +from h.util.user import format_userid class TestMentionJSONPresenter: @@ -12,11 +13,20 @@ def test_as_dict(self, user, annotation): assert data == { "userid": user.userid, + "original_userid": user.userid, "username": user.username, "display_name": user.display_name, "link": user.uri, } + def test_as_dict_with_different_username(self, user, annotation): + new_username = "new_username" + mention = Mention(annotation=annotation, user=user, username=new_username) + + data = MentionJSONPresenter(mention).asdict() + + assert data["original_userid"] == format_userid(new_username, user.authority) + @pytest.fixture def user(self, factories): return factories.User.build() diff --git a/tests/unit/h/services/mention_test.py b/tests/unit/h/services/mention_test.py index 5ca404353e5..480dc9935c9 100644 --- a/tests/unit/h/services/mention_test.py +++ b/tests/unit/h/services/mention_test.py @@ -104,6 +104,7 @@ def test_it(self, pyramid_request, user_service, MentionService): session=pyramid_request.db, user_service=user_service, ) + assert service == MentionService.return_value @pytest.fixture