1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
6 use Pleroma.Web.ConnCase
8 alias Pleroma.Notification
11 alias Pleroma.Web.CommonAPI
13 import Pleroma.Factory
17 mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
21 clear_config([:rich_media, :enabled])
23 test "getting a list of mutes", %{conn: conn} do
25 other_user = insert(:user)
27 {:ok, user} = User.mute(user, other_user)
31 |> assign(:user, user)
32 |> get("/api/v1/mutes")
34 other_user_id = to_string(other_user.id)
35 assert [%{"id" => ^other_user_id}] = json_response(conn, 200)
38 test "getting a list of blocks", %{conn: conn} do
40 other_user = insert(:user)
42 {:ok, user} = User.block(user, other_user)
46 |> assign(:user, user)
47 |> get("/api/v1/blocks")
49 other_user_id = to_string(other_user.id)
50 assert [%{"id" => ^other_user_id}] = json_response(conn, 200)
53 test "unimplemented follow_requests, blocks, domain blocks" do
56 ["blocks", "domain_blocks", "follow_requests"]
57 |> Enum.each(fn endpoint ->
60 |> assign(:user, user)
61 |> get("/api/v1/#{endpoint}")
63 assert [] = json_response(conn, 200)
67 test "returns the favorites of a user", %{conn: conn} do
69 other_user = insert(:user)
71 {:ok, _} = CommonAPI.post(other_user, %{"status" => "bla"})
72 {:ok, activity} = CommonAPI.post(other_user, %{"status" => "traps are happy"})
74 {:ok, _, _} = CommonAPI.favorite(activity.id, user)
78 |> assign(:user, user)
79 |> get("/api/v1/favourites")
81 assert [status] = json_response(first_conn, 200)
82 assert status["id"] == to_string(activity.id)
84 assert [{"link", _link_header}] =
85 Enum.filter(first_conn.resp_headers, fn element -> match?({"link", _}, element) end)
87 # Honours query params
88 {:ok, second_activity} =
89 CommonAPI.post(other_user, %{
91 "Trees Are Never Sad Look At Them Every Once In Awhile They're Quite Beautiful."
94 {:ok, _, _} = CommonAPI.favorite(second_activity.id, user)
96 last_like = status["id"]
100 |> assign(:user, user)
101 |> get("/api/v1/favourites?since_id=#{last_like}")
103 assert [second_status] = json_response(second_conn, 200)
104 assert second_status["id"] == to_string(second_activity.id)
108 |> assign(:user, user)
109 |> get("/api/v1/favourites?limit=0")
111 assert [] = json_response(third_conn, 200)
114 describe "link headers" do
115 test "preserves parameters in link headers", %{conn: conn} do
117 other_user = insert(:user)
120 CommonAPI.post(other_user, %{
121 "status" => "hi @#{user.nickname}",
122 "visibility" => "public"
126 CommonAPI.post(other_user, %{
127 "status" => "hi @#{user.nickname}",
128 "visibility" => "public"
131 notification1 = Repo.get_by(Notification, activity_id: activity1.id)
132 notification2 = Repo.get_by(Notification, activity_id: activity2.id)
136 |> assign(:user, user)
137 |> get("/api/v1/notifications", %{media_only: true})
139 assert [link_header] = get_resp_header(conn, "link")
140 assert link_header =~ ~r/media_only=true/
141 assert link_header =~ ~r/min_id=#{notification2.id}/
142 assert link_header =~ ~r/max_id=#{notification1.id}/
146 describe "empty_array, stubs for mastodon api" do
147 test "GET /api/v1/accounts/:id/identity_proofs", %{conn: conn} do
152 |> assign(:user, user)
153 |> get("/api/v1/accounts/#{user.id}/identity_proofs")
154 |> json_response(200)
159 test "GET /api/v1/endorsements", %{conn: conn} do
164 |> assign(:user, user)
165 |> get("/api/v1/endorsements")
166 |> json_response(200)
171 test "GET /api/v1/trends", %{conn: conn} do
176 |> assign(:user, user)
177 |> get("/api/v1/trends")
178 |> json_response(200)