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 "unimplemented follow_requests, blocks, domain blocks" do
26 ["blocks", "domain_blocks", "follow_requests"]
27 |> Enum.each(fn endpoint ->
30 |> assign(:user, user)
31 |> get("/api/v1/#{endpoint}")
33 assert [] = json_response(conn, 200)
37 test "returns the favorites of a user", %{conn: conn} do
39 other_user = insert(:user)
41 {:ok, _} = CommonAPI.post(other_user, %{"status" => "bla"})
42 {:ok, activity} = CommonAPI.post(other_user, %{"status" => "traps are happy"})
44 {:ok, _, _} = CommonAPI.favorite(activity.id, user)
48 |> assign(:user, user)
49 |> get("/api/v1/favourites")
51 assert [status] = json_response(first_conn, 200)
52 assert status["id"] == to_string(activity.id)
54 assert [{"link", _link_header}] =
55 Enum.filter(first_conn.resp_headers, fn element -> match?({"link", _}, element) end)
57 # Honours query params
58 {:ok, second_activity} =
59 CommonAPI.post(other_user, %{
61 "Trees Are Never Sad Look At Them Every Once In Awhile They're Quite Beautiful."
64 {:ok, _, _} = CommonAPI.favorite(second_activity.id, user)
66 last_like = status["id"]
70 |> assign(:user, user)
71 |> get("/api/v1/favourites?since_id=#{last_like}")
73 assert [second_status] = json_response(second_conn, 200)
74 assert second_status["id"] == to_string(second_activity.id)
78 |> assign(:user, user)
79 |> get("/api/v1/favourites?limit=0")
81 assert [] = json_response(third_conn, 200)
84 describe "link headers" do
85 test "preserves parameters in link headers", %{conn: conn} do
87 other_user = insert(:user)
90 CommonAPI.post(other_user, %{
91 "status" => "hi @#{user.nickname}",
92 "visibility" => "public"
96 CommonAPI.post(other_user, %{
97 "status" => "hi @#{user.nickname}",
98 "visibility" => "public"
101 notification1 = Repo.get_by(Notification, activity_id: activity1.id)
102 notification2 = Repo.get_by(Notification, activity_id: activity2.id)
106 |> assign(:user, user)
107 |> get("/api/v1/notifications", %{media_only: true})
109 assert [link_header] = get_resp_header(conn, "link")
110 assert link_header =~ ~r/media_only=true/
111 assert link_header =~ ~r/min_id=#{notification2.id}/
112 assert link_header =~ ~r/max_id=#{notification1.id}/
116 describe "empty_array, stubs for mastodon api" do
117 test "GET /api/v1/accounts/:id/identity_proofs", %{conn: conn} do
122 |> assign(:user, user)
123 |> get("/api/v1/accounts/#{user.id}/identity_proofs")
124 |> json_response(200)
129 test "GET /api/v1/endorsements", %{conn: conn} do
134 |> assign(:user, user)
135 |> get("/api/v1/endorsements")
136 |> json_response(200)
141 test "GET /api/v1/trends", %{conn: conn} do
146 |> assign(:user, user)
147 |> get("/api/v1/trends")
148 |> json_response(200)