Merge branch 'develop' of https://git.pleroma.social/pleroma/pleroma into develop
[akkoma] / test / web / mastodon_api / mastodon_api_controller_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
6 use Pleroma.Web.ConnCase
7
8 alias Pleroma.Notification
9 alias Pleroma.Repo
10 alias Pleroma.Web.CommonAPI
11
12 import Pleroma.Factory
13 import Tesla.Mock
14
15 setup do
16 mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
17 :ok
18 end
19
20 clear_config([:rich_media, :enabled])
21
22 test "unimplemented follow_requests, blocks, domain blocks" do
23 user = insert(:user)
24
25 ["blocks", "domain_blocks", "follow_requests"]
26 |> Enum.each(fn endpoint ->
27 conn =
28 build_conn()
29 |> assign(:user, user)
30 |> get("/api/v1/#{endpoint}")
31
32 assert [] = json_response(conn, 200)
33 end)
34 end
35
36 describe "link headers" do
37 test "preserves parameters in link headers", %{conn: conn} do
38 user = insert(:user)
39 other_user = insert(:user)
40
41 {:ok, activity1} =
42 CommonAPI.post(other_user, %{
43 "status" => "hi @#{user.nickname}",
44 "visibility" => "public"
45 })
46
47 {:ok, activity2} =
48 CommonAPI.post(other_user, %{
49 "status" => "hi @#{user.nickname}",
50 "visibility" => "public"
51 })
52
53 notification1 = Repo.get_by(Notification, activity_id: activity1.id)
54 notification2 = Repo.get_by(Notification, activity_id: activity2.id)
55
56 conn =
57 conn
58 |> assign(:user, user)
59 |> get("/api/v1/notifications", %{media_only: true})
60
61 assert [link_header] = get_resp_header(conn, "link")
62 assert link_header =~ ~r/media_only=true/
63 assert link_header =~ ~r/min_id=#{notification2.id}/
64 assert link_header =~ ~r/max_id=#{notification1.id}/
65 end
66 end
67
68 describe "empty_array, stubs for mastodon api" do
69 test "GET /api/v1/accounts/:id/identity_proofs", %{conn: conn} do
70 user = insert(:user)
71
72 res =
73 conn
74 |> assign(:user, user)
75 |> get("/api/v1/accounts/#{user.id}/identity_proofs")
76 |> json_response(200)
77
78 assert res == []
79 end
80
81 test "GET /api/v1/endorsements", %{conn: conn} do
82 user = insert(:user)
83
84 res =
85 conn
86 |> assign(:user, user)
87 |> get("/api/v1/endorsements")
88 |> json_response(200)
89
90 assert res == []
91 end
92
93 test "GET /api/v1/trends", %{conn: conn} do
94 user = insert(:user)
95
96 res =
97 conn
98 |> assign(:user, user)
99 |> get("/api/v1/trends")
100 |> json_response(200)
101
102 assert res == []
103 end
104 end
105 end