Do not add the "next" key to likes.json if there is no more items
This commit is contained in:
parent
9e7c633b39
commit
e8ad116c2a
|
@ -66,8 +66,10 @@ def collection(collection, iri, page) do
|
||||||
"orderedItems" => items
|
"orderedItems" => items
|
||||||
}
|
}
|
||||||
|
|
||||||
if offset < total do
|
if offset + length(items) < total do
|
||||||
Map.put(map, "next", "#{iri}?page=#{page + 1}")
|
Map.put(map, "next", "#{iri}?page=#{page + 1}")
|
||||||
|
else
|
||||||
|
map
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -182,8 +182,8 @@ def announce_activity_factory(attrs \\ %{}) do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def like_activity_factory do
|
def like_activity_factory(attrs \\ %{}) do
|
||||||
note_activity = insert(:note_activity)
|
note_activity = attrs[:note_activity] || insert(:note_activity)
|
||||||
object = Object.normalize(note_activity)
|
object = Object.normalize(note_activity)
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
|
|
|
@ -180,18 +180,65 @@ test "it returns 404 for tombstone objects", %{conn: conn} do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "/object/:uuid/likes" do
|
describe "/object/:uuid/likes" do
|
||||||
test "it returns the like activities in a collection", %{conn: conn} do
|
setup do
|
||||||
like = insert(:like_activity)
|
like = insert(:like_activity)
|
||||||
like_object_ap_id = Object.normalize(like).data["id"]
|
like_object_ap_id = Object.normalize(like).data["id"]
|
||||||
uuid = String.split(like_object_ap_id, "/") |> List.last()
|
|
||||||
|
|
||||||
|
uuid =
|
||||||
|
like_object_ap_id
|
||||||
|
|> String.split("/")
|
||||||
|
|> List.last()
|
||||||
|
|
||||||
|
[id: like.data["id"], uuid: uuid]
|
||||||
|
end
|
||||||
|
|
||||||
|
test "it returns the like activities in a collection", %{conn: conn, id: id, uuid: uuid} do
|
||||||
result =
|
result =
|
||||||
conn
|
conn
|
||||||
|> put_req_header("accept", "application/activity+json")
|
|> put_req_header("accept", "application/activity+json")
|
||||||
|> get("/objects/#{uuid}/likes")
|
|> get("/objects/#{uuid}/likes")
|
||||||
|> json_response(200)
|
|> json_response(200)
|
||||||
|
|
||||||
assert List.first(result["first"]["orderedItems"])["id"] == like.data["id"]
|
assert List.first(result["first"]["orderedItems"])["id"] == id
|
||||||
|
assert result["type"] == "OrderedCollection"
|
||||||
|
assert result["totalItems"] == 1
|
||||||
|
refute result["first"]["next"]
|
||||||
|
end
|
||||||
|
|
||||||
|
test "it does not crash when page number is exceeded total pages", %{conn: conn, uuid: uuid} do
|
||||||
|
result =
|
||||||
|
conn
|
||||||
|
|> put_req_header("accept", "application/activity+json")
|
||||||
|
|> get("/objects/#{uuid}/likes?page=2")
|
||||||
|
|> json_response(200)
|
||||||
|
|
||||||
|
assert result["type"] == "OrderedCollectionPage"
|
||||||
|
assert result["totalItems"] == 1
|
||||||
|
refute result["next"]
|
||||||
|
assert Enum.empty?(result["orderedItems"])
|
||||||
|
end
|
||||||
|
|
||||||
|
test "it contains the next key when likes count is more than 10", %{conn: conn} do
|
||||||
|
note = insert(:note_activity)
|
||||||
|
insert_list(11, :like_activity, note_activity: note)
|
||||||
|
|
||||||
|
uuid =
|
||||||
|
note
|
||||||
|
|> Object.normalize()
|
||||||
|
|> Map.get(:data)
|
||||||
|
|> Map.get("id")
|
||||||
|
|> String.split("/")
|
||||||
|
|> List.last()
|
||||||
|
|
||||||
|
result =
|
||||||
|
conn
|
||||||
|
|> put_req_header("accept", "application/activity+json")
|
||||||
|
|> get("/objects/#{uuid}/likes?page=1")
|
||||||
|
|> json_response(200)
|
||||||
|
|
||||||
|
assert result["totalItems"] == 11
|
||||||
|
assert length(result["orderedItems"]) == 10
|
||||||
|
assert result["next"]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue