Skip to content

Commit

Permalink
Update mention json payload
Browse files Browse the repository at this point in the history
  • Loading branch information
mtomilov committed Feb 7, 2025
1 parent a3a53e9 commit f6ffbe8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions docs/_extra/api-reference/schemas/annotation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ Annotation:
pattern: "acct:^[A-Za-z0-9._]{3,30}@.*$"
description: user account ID in the format `"acct:<username>@<authority>"`
example: "acct:[email protected]"
username:
original_userid:
type: string
description: The username of the user at the time of the mention
description: The original account ID mentioned in the annotation text
display_name:
type: string
description: The display name of the user
Expand Down
6 changes: 5 additions & 1 deletion h/presenters/mention_json.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any

from h.models import Mention
from h.util.user import format_userid


class MentionJSONPresenter:
Expand All @@ -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,
}
10 changes: 10 additions & 0 deletions tests/unit/h/presenters/mention_json_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()
Expand Down
1 change: 1 addition & 0 deletions tests/unit/h/services/mention_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f6ffbe8

Please sign in to comment.