1 defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
2 use Pleroma.Web.ConnCase
4 alias Pleroma.Web.TwitterAPI.TwitterAPI
5 alias Pleroma.{Repo, User, Activity}
6 alias Pleroma.Web.OStatus
10 test "the home timeline", %{conn: conn} do
12 following = insert(:user)
14 {:ok, _activity} = TwitterAPI.create_status(following, %{"status" => "test"})
17 |> assign(:user, user)
18 |> get("/api/v1/timelines/home")
20 assert length(json_response(conn, 200)) == 0
22 {:ok, user} = User.follow(user, following)
25 |> assign(:user, user)
26 |> get("/api/v1/timelines/home")
28 assert [%{"content" => "test"}] = json_response(conn, 200)
31 test "the public timeline", %{conn: conn} do
32 following = insert(:user)
34 {:ok, _activity} = TwitterAPI.create_status(following, %{"status" => "test"})
35 {:ok, [_activity]} = OStatus.fetch_activity_from_url("https://shitposter.club/notice/2827873")
38 |> get("/api/v1/timelines/public")
40 assert length(json_response(conn, 200)) == 2
43 |> get("/api/v1/timelines/public", %{"local" => "True"})
45 assert [%{"content" => "test"}] = json_response(conn, 200)
48 test "posting a status", %{conn: conn} do
52 |> assign(:user, user)
53 |> post("/api/v1/statuses", %{"status" => "cofe"})
55 assert %{"content" => "cofe", "id" => id} = json_response(conn, 200)
56 assert Repo.get(Activity, id)
59 test "replying to a status", %{conn: conn} do
62 {:ok, replied_to} = TwitterAPI.create_status(user, %{"status" => "cofe"})
65 |> assign(:user, user)
66 |> post("/api/v1/statuses", %{"status" => "xD", "in_reply_to_id" => replied_to.id})
68 assert %{"content" => "xD", "id" => id} = json_response(conn, 200)
70 activity = Repo.get(Activity, id)
72 assert activity.data["context"] == replied_to.data["context"]
73 assert activity.data["object"]["inReplyToStatusId"] == replied_to.id
76 test "verify_credentials", %{conn: conn} do
80 |> assign(:user, user)
81 |> get("/api/v1/accounts/verify_credentials")
83 assert %{"id" => id} = json_response(conn, 200)
87 test "get a status", %{conn: conn} do
88 activity = insert(:note_activity)
91 |> get("/api/v1/statuses/#{activity.id}")
93 assert %{"id" => id} = json_response(conn, 200)
94 assert id == activity.id
97 describe "deleting a status" do
98 test "when you created it", %{conn: conn} do
99 activity = insert(:note_activity)
100 author = User.get_by_ap_id(activity.data["actor"])
103 |> assign(:user, author)
104 |> delete("/api/v1/statuses/#{activity.id}")
106 assert %{} = json_response(conn, 200)
108 assert Repo.get(Activity, activity.id) == nil
111 test "when you didn't create it", %{conn: conn} do
112 activity = insert(:note_activity)
116 |> assign(:user, user)
117 |> delete("/api/v1/statuses/#{activity.id}")
119 assert %{"error" => _} = json_response(conn, 403)
121 assert Repo.get(Activity, activity.id) == activity
125 describe "reblogging" do
126 test "reblogs and returns the reblogged status", %{conn: conn} do
127 activity = insert(:note_activity)
131 |> assign(:user, user)
132 |> post("/api/v1/statuses/#{activity.id}/reblog")
134 assert %{"id" => id, "reblogged" => true, "reblogs_count" => 1} = json_response(conn, 200)
135 assert activity.id == id
139 describe "favoriting" do
140 test "favs a status and returns it", %{conn: conn} do
141 activity = insert(:note_activity)
145 |> assign(:user, user)
146 |> post("/api/v1/statuses/#{activity.id}/favourite")
148 assert %{"id" => id, "favourites_count" => 1, "favourited" => true} = json_response(conn, 200)
149 assert activity.id == id