Fix unliked post displaying in favourites endpoint (#512)
This commit is contained in:
parent
427744f5a7
commit
e43d0a052c
|
@ -1,6 +1,12 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
from activities.models import Hashtag, Post, PostInteraction, TimelineEvent
|
from activities.models import (
|
||||||
|
Hashtag,
|
||||||
|
Post,
|
||||||
|
PostInteraction,
|
||||||
|
PostInteractionStates,
|
||||||
|
TimelineEvent,
|
||||||
|
)
|
||||||
from activities.services import PostService
|
from activities.services import PostService
|
||||||
from users.models import Identity
|
from users.models import Identity
|
||||||
|
|
||||||
|
@ -92,6 +98,7 @@ class TimelineService:
|
||||||
.filter(
|
.filter(
|
||||||
interactions__identity=self.identity,
|
interactions__identity=self.identity,
|
||||||
interactions__type=PostInteraction.Types.like,
|
interactions__type=PostInteraction.Types.like,
|
||||||
|
interactions__state__in=PostInteractionStates.group_active(),
|
||||||
)
|
)
|
||||||
.order_by("-id")
|
.order_by("-id")
|
||||||
)
|
)
|
||||||
|
|
|
@ -154,11 +154,11 @@ class Status(Schema):
|
||||||
language: None = Field(...)
|
language: None = Field(...)
|
||||||
text: str | None = Field(...)
|
text: str | None = Field(...)
|
||||||
edited_at: str | None
|
edited_at: str | None
|
||||||
favourited: bool | None
|
favourited: bool = False
|
||||||
reblogged: bool | None
|
reblogged: bool = False
|
||||||
muted: bool | None
|
muted: bool = False
|
||||||
bookmarked: bool | None
|
bookmarked: bool = False
|
||||||
pinned: bool | None
|
pinned: bool = False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_post(
|
def from_post(
|
||||||
|
|
|
@ -23,3 +23,31 @@ def test_likes_flow(api_client):
|
||||||
# Check if it's displaying at likes endpoint
|
# Check if it's displaying at likes endpoint
|
||||||
response = api_client.get("/api/v1/favourites").json()
|
response = api_client.get("/api/v1/favourites").json()
|
||||||
assert response[0]["id"] == status_id
|
assert response[0]["id"] == status_id
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_unlike(api_client):
|
||||||
|
# Add a post
|
||||||
|
response = api_client.post(
|
||||||
|
"/api/v1/statuses",
|
||||||
|
content_type="application/json",
|
||||||
|
data={
|
||||||
|
"status": "Like test.",
|
||||||
|
"visibility": "public",
|
||||||
|
},
|
||||||
|
).json()
|
||||||
|
assert response["content"] == "<p>Like test.</p>"
|
||||||
|
|
||||||
|
status_id = response["id"]
|
||||||
|
|
||||||
|
# Like it
|
||||||
|
response = api_client.post(f"/api/v1/statuses/{status_id}/favourite").json()
|
||||||
|
assert response["favourited"] is True
|
||||||
|
|
||||||
|
# Unlike it
|
||||||
|
response = api_client.post(f"/api/v1/statuses/{status_id}/unfavourite").json()
|
||||||
|
assert response["favourited"] is False
|
||||||
|
|
||||||
|
# Unliked post should not display at the endpoint
|
||||||
|
response = api_client.get("/api/v1/favourites").json()
|
||||||
|
assert len(response) == 0
|
||||||
|
|
Loading…
Reference in New Issue