X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Factivity_pub%2Factivity_pub_controller_test.exs;h=bbf89136b1b8ee786d6e3e96fcb1395a6f9b1b59;hb=8dc715b30bf310d040f72c0c01a5c668c3696b2a;hp=21ed28cf28b82ba7d6c1fb63350358131031d579;hpb=e2e636503525f4e295430ddb71007ab8e851e856;p=akkoma diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs index 21ed28cf2..bbf89136b 100644 --- a/test/web/activity_pub/activity_pub_controller_test.exs +++ b/test/web/activity_pub/activity_pub_controller_test.exs @@ -3,14 +3,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do import Pleroma.Factory alias Pleroma.Web.ActivityPub.{UserView, ObjectView} alias Pleroma.{Repo, User} + alias Pleroma.Activity describe "/users/:nickname" do test "it returns a json representation of the user", %{conn: conn} do user = insert(:user) - conn = conn - |> put_req_header("accept", "application/activity+json") - |> get("/users/#{user.nickname}") + conn = + conn + |> put_req_header("accept", "application/activity+json") + |> get("/users/#{user.nickname}") user = Repo.get(User, user.id) @@ -21,19 +23,125 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do describe "/object/:uuid" do test "it returns a json representation of the object", %{conn: conn} do note = insert(:note) - uuid = String.split(note.data["id"], "/") |> List.last + uuid = String.split(note.data["id"], "/") |> List.last() - conn = conn - |> put_req_header("accept", "application/activity+json") - |> get("/objects/#{uuid}") + conn = + conn + |> put_req_header("accept", "application/activity+json") + |> get("/objects/#{uuid}") assert json_response(conn, 200) == ObjectView.render("object.json", %{object: note}) end + + test "it returns 404 for non-public messages", %{conn: conn} do + note = insert(:direct_note) + uuid = String.split(note.data["id"], "/") |> List.last() + + conn = + conn + |> put_req_header("accept", "application/activity+json") + |> get("/objects/#{uuid}") + + assert json_response(conn, 404) + end end describe "/users/:nickname/inbox" do - test "it inserts an incoming activity into the database" do - assert false + test "it inserts an incoming activity into the database", %{conn: conn} do + data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!() + + conn = + conn + |> assign(:valid_signature, true) + |> put_req_header("content-type", "application/activity+json") + |> post("/inbox", data) + + assert "ok" == json_response(conn, 200) + :timer.sleep(500) + assert Activity.get_by_ap_id(data["id"]) + end + end + + describe "/users/:nickname/followers" do + test "it returns the followers in a collection", %{conn: conn} do + user = insert(:user) + user_two = insert(:user) + User.follow(user, user_two) + + result = + conn + |> get("/users/#{user_two.nickname}/followers") + |> json_response(200) + + assert result["first"]["orderedItems"] == [user.ap_id] + end + + test "it works for more than 10 users", %{conn: conn} do + user = insert(:user) + + Enum.each(1..15, fn _ -> + other_user = insert(:user) + User.follow(other_user, user) + end) + + result = + conn + |> get("/users/#{user.nickname}/followers") + |> json_response(200) + + assert length(result["first"]["orderedItems"]) == 10 + assert result["first"]["totalItems"] == 15 + assert result["totalItems"] == 15 + + result = + conn + |> get("/users/#{user.nickname}/followers?page=2") + |> json_response(200) + + assert length(result["orderedItems"]) == 5 + assert result["totalItems"] == 15 + end + end + + describe "/users/:nickname/following" do + test "it returns the following in a collection", %{conn: conn} do + user = insert(:user) + user_two = insert(:user) + User.follow(user, user_two) + + result = + conn + |> get("/users/#{user.nickname}/following") + |> json_response(200) + + assert result["first"]["orderedItems"] == [user_two.ap_id] + end + + test "it works for more than 10 users", %{conn: conn} do + user = insert(:user) + + Enum.each(1..15, fn _ -> + user = Repo.get(User, user.id) + other_user = insert(:user) + User.follow(user, other_user) + end) + + result = + conn + |> get("/users/#{user.nickname}/following") + |> json_response(200) + + assert length(result["first"]["orderedItems"]) == 10 + assert result["first"]["totalItems"] == 15 + assert result["totalItems"] == 15 + + result = + conn + |> get("/users/#{user.nickname}/following?page=2") + |> json_response(200) + + assert length(result["orderedItems"]) == 5 + assert result["totalItems"] == 15 end end end