diff options
| author | Sergey Suprunenko <suprunenko.s@gmail.com> | 2019-08-04 17:13:06 +0000 | 
|---|---|---|
| committer | kaniini <ariadne@dereferenced.org> | 2019-08-04 17:13:06 +0000 | 
| commit | e8ad116c2a5a166613f9609c8fe2559af2b97505 (patch) | |
| tree | b3a5bf521de42a1834bd55e580b18757008a43c8 /test/web | |
| parent | 9e7c633b39bb430f2d6d68656e681218d421e780 (diff) | |
| download | pleroma-e8ad116c2a5a166613f9609c8fe2559af2b97505.tar.gz pleroma-e8ad116c2a5a166613f9609c8fe2559af2b97505.zip | |
Do not add the "next" key to likes.json if there is no more items
Diffstat (limited to 'test/web')
| -rw-r--r-- | test/web/activity_pub/activity_pub_controller_test.exs | 53 | 
1 files changed, 50 insertions, 3 deletions
| diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs index 40344f17e..251055ee1 100644 --- a/test/web/activity_pub/activity_pub_controller_test.exs +++ b/test/web/activity_pub/activity_pub_controller_test.exs @@ -180,18 +180,65 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do    end    describe "/object/:uuid/likes" do -    test "it returns the like activities in a collection", %{conn: conn} do +    setup do        like = insert(:like_activity)        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 =          conn          |> put_req_header("accept", "application/activity+json")          |> get("/objects/#{uuid}/likes")          |> 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 | 
