Merge branch 'feld-mastoweb5000' into 'develop'
[akkoma] / test / web / activity_pub / activity_pub_controller_test.exs
1 defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
2 use Pleroma.Web.ConnCase
3 import Pleroma.Factory
4 alias Pleroma.Web.ActivityPub.{UserView, ObjectView}
5 alias Pleroma.{Repo, User}
6 alias Pleroma.Activity
7
8 describe "/users/:nickname" do
9 test "it returns a json representation of the user", %{conn: conn} do
10 user = insert(:user)
11
12 conn = conn
13 |> put_req_header("accept", "application/activity+json")
14 |> get("/users/#{user.nickname}")
15
16 user = Repo.get(User, user.id)
17
18 assert json_response(conn, 200) == UserView.render("user.json", %{user: user})
19 end
20 end
21
22 describe "/object/:uuid" do
23 test "it returns a json representation of the object", %{conn: conn} do
24 note = insert(:note)
25 uuid = String.split(note.data["id"], "/") |> List.last
26
27 conn = conn
28 |> put_req_header("accept", "application/activity+json")
29 |> get("/objects/#{uuid}")
30
31 assert json_response(conn, 200) == ObjectView.render("object.json", %{object: note})
32 end
33 end
34
35 describe "/users/:nickname/inbox" do
36 test "it inserts an incoming activity into the database", %{conn: conn} do
37 data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!
38
39 conn = conn
40 |> assign(:valid_signature, true)
41 |> put_req_header("content-type", "application/activity+json")
42 |> post("/inbox", data)
43
44 assert "ok" == json_response(conn, 200)
45 :timer.sleep(500)
46 assert Activity.get_by_ap_id(data["id"])
47 end
48 end
49 end