28d765d838772fd32778ed716b5c22e5ad356f57
[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 =
13 conn
14 |> put_req_header("accept", "application/activity+json")
15 |> get("/users/#{user.nickname}")
16
17 user = Repo.get(User, user.id)
18
19 assert json_response(conn, 200) == UserView.render("user.json", %{user: user})
20 end
21 end
22
23 describe "/object/:uuid" do
24 test "it returns a json representation of the object", %{conn: conn} do
25 note = insert(:note)
26 uuid = String.split(note.data["id"], "/") |> List.last()
27
28 conn =
29 conn
30 |> put_req_header("accept", "application/activity+json")
31 |> get("/objects/#{uuid}")
32
33 assert json_response(conn, 200) == ObjectView.render("object.json", %{object: note})
34 end
35 end
36
37 describe "/users/:nickname/inbox" do
38 test "it inserts an incoming activity into the database", %{conn: conn} do
39 data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
40
41 conn =
42 conn
43 |> assign(:valid_signature, true)
44 |> put_req_header("content-type", "application/activity+json")
45 |> post("/inbox", data)
46
47 assert "ok" == json_response(conn, 200)
48 :timer.sleep(500)
49 assert Activity.get_by_ap_id(data["id"])
50 end
51 end
52 end