Fix unliked post displaying in favourites endpoint (#512)

This commit is contained in:
Humberto Rocha 2023-02-15 18:05:48 -05:00 committed by GitHub
parent 427744f5a7
commit e43d0a052c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 6 deletions

View file

@ -1,6 +1,12 @@
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 users.models import Identity
@ -92,6 +98,7 @@ class TimelineService:
.filter(
interactions__identity=self.identity,
interactions__type=PostInteraction.Types.like,
interactions__state__in=PostInteractionStates.group_active(),
)
.order_by("-id")
)

View file

@ -154,11 +154,11 @@ class Status(Schema):
language: None = Field(...)
text: str | None = Field(...)
edited_at: str | None
favourited: bool | None
reblogged: bool | None
muted: bool | None
bookmarked: bool | None
pinned: bool | None
favourited: bool = False
reblogged: bool = False
muted: bool = False
bookmarked: bool = False
pinned: bool = False
@classmethod
def from_post(

View file

@ -23,3 +23,31 @@ def test_likes_flow(api_client):
# Check if it's displaying at likes endpoint
response = api_client.get("/api/v1/favourites").json()
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