activity_pub_controller_test.exs 1.5 KB
Newer Older
lain's avatar
lain committed
1
2
3
4
5
defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
  use Pleroma.Web.ConnCase
  import Pleroma.Factory
  alias Pleroma.Web.ActivityPub.{UserView, ObjectView}
  alias Pleroma.{Repo, User}
lain's avatar
lain committed
6
  alias Pleroma.Activity
lain's avatar
lain committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

  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}")

      user = Repo.get(User, user.id)

      assert json_response(conn, 200) == UserView.render("user.json", %{user: user})
    end
  end

  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

      conn = conn
      |> put_req_header("accept", "application/activity+json")
      |> get("/objects/#{uuid}")

      assert json_response(conn, 200) == ObjectView.render("object.json", %{object: note})
    end
  end

  describe "/users/:nickname/inbox" do
36
37
38
39
40
41
    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")
lain's avatar
lain committed
42
      |> post("/inbox", data)
43
44

      assert "ok" == json_response(conn, 200)
lain's avatar
lain committed
45
46
      :timer.sleep(500)
      assert Activity.get_by_ap_id(data["id"])
lain's avatar
lain committed
47
48
49
    end
  end
end