1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
6 use Pleroma.Web.ConnCase
10 alias Pleroma.Web.ActivityPub.ActivityPub
11 alias Pleroma.Web.ActivityPub.InternalFetchActor
12 alias Pleroma.Web.CommonAPI
13 alias Pleroma.Web.OAuth.Token
15 import Pleroma.Factory
17 describe "account fetching" do
19 %User{id: user_id} = insert(:user)
21 assert %{"id" => ^user_id} =
23 |> get("/api/v1/accounts/#{user_id}")
24 |> json_response_and_validate_schema(200)
26 assert %{"error" => "Can't find user"} =
28 |> get("/api/v1/accounts/-1")
29 |> json_response_and_validate_schema(404)
32 test "works by nickname" do
35 assert %{"id" => _user_id} =
37 |> get("/api/v1/accounts/#{user.nickname}")
38 |> json_response_and_validate_schema(200)
41 test "works by nickname for remote users" do
42 clear_config([:instance, :limit_to_local_content], false)
44 user = insert(:user, nickname: "user@example.com", local: false)
46 assert %{"id" => _user_id} =
48 |> get("/api/v1/accounts/#{user.nickname}")
49 |> json_response_and_validate_schema(200)
52 test "respects limit_to_local_content == :all for remote user nicknames" do
53 clear_config([:instance, :limit_to_local_content], :all)
55 user = insert(:user, nickname: "user@example.com", local: false)
58 |> get("/api/v1/accounts/#{user.nickname}")
59 |> json_response_and_validate_schema(404)
62 test "respects limit_to_local_content == :unauthenticated for remote user nicknames" do
63 clear_config([:instance, :limit_to_local_content], :unauthenticated)
65 user = insert(:user, nickname: "user@example.com", local: false)
66 reading_user = insert(:user)
70 |> get("/api/v1/accounts/#{user.nickname}")
72 assert json_response_and_validate_schema(conn, 404)
76 |> assign(:user, reading_user)
77 |> assign(:token, insert(:oauth_token, user: reading_user, scopes: ["read:accounts"]))
78 |> get("/api/v1/accounts/#{user.nickname}")
80 assert %{"id" => id} = json_response_and_validate_schema(conn, 200)
84 test "accounts fetches correct account for nicknames beginning with numbers", %{conn: conn} do
85 # Need to set an old-style integer ID to reproduce the problem
86 # (these are no longer assigned to new accounts but were preserved
87 # for existing accounts during the migration to flakeIDs)
88 user_one = insert(:user, %{id: 1212})
89 user_two = insert(:user, %{nickname: "#{user_one.id}garbage"})
93 |> get("/api/v1/accounts/#{user_one.id}")
94 |> json_response_and_validate_schema(:ok)
98 |> get("/api/v1/accounts/#{user_two.nickname}")
99 |> json_response_and_validate_schema(:ok)
103 |> get("/api/v1/accounts/#{user_two.id}")
104 |> json_response_and_validate_schema(:ok)
106 refute acc_one == acc_two
107 assert acc_two == acc_three
110 test "returns 404 when user is invisible", %{conn: conn} do
111 user = insert(:user, %{invisible: true})
113 assert %{"error" => "Can't find user"} =
115 |> get("/api/v1/accounts/#{user.nickname}")
116 |> json_response_and_validate_schema(404)
119 test "returns 404 for internal.fetch actor", %{conn: conn} do
120 %User{nickname: "internal.fetch"} = InternalFetchActor.get_actor()
122 assert %{"error" => "Can't find user"} =
124 |> get("/api/v1/accounts/internal.fetch")
125 |> json_response_and_validate_schema(404)
128 test "returns 404 for deactivated user", %{conn: conn} do
129 user = insert(:user, deactivated: true)
131 assert %{"error" => "Can't find user"} =
133 |> get("/api/v1/accounts/#{user.id}")
134 |> json_response_and_validate_schema(:not_found)
138 defp local_and_remote_users do
139 local = insert(:user)
140 remote = insert(:user, local: false)
141 {:ok, local: local, remote: remote}
144 describe "user fetching with restrict unauthenticated profiles for local and remote" do
145 setup do: local_and_remote_users()
147 setup do: clear_config([:restrict_unauthenticated, :profiles, :local], true)
149 setup do: clear_config([:restrict_unauthenticated, :profiles, :remote], true)
151 test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
152 assert %{"error" => "This API requires an authenticated user"} ==
154 |> get("/api/v1/accounts/#{local.id}")
155 |> json_response_and_validate_schema(:unauthorized)
157 assert %{"error" => "This API requires an authenticated user"} ==
159 |> get("/api/v1/accounts/#{remote.id}")
160 |> json_response_and_validate_schema(:unauthorized)
163 test "if user is authenticated", %{local: local, remote: remote} do
164 %{conn: conn} = oauth_access(["read"])
166 res_conn = get(conn, "/api/v1/accounts/#{local.id}")
167 assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
169 res_conn = get(conn, "/api/v1/accounts/#{remote.id}")
170 assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
174 describe "user fetching with restrict unauthenticated profiles for local" do
175 setup do: local_and_remote_users()
177 setup do: clear_config([:restrict_unauthenticated, :profiles, :local], true)
179 test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
180 res_conn = get(conn, "/api/v1/accounts/#{local.id}")
182 assert json_response_and_validate_schema(res_conn, :unauthorized) == %{
183 "error" => "This API requires an authenticated user"
186 res_conn = get(conn, "/api/v1/accounts/#{remote.id}")
187 assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
190 test "if user is authenticated", %{local: local, remote: remote} do
191 %{conn: conn} = oauth_access(["read"])
193 res_conn = get(conn, "/api/v1/accounts/#{local.id}")
194 assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
196 res_conn = get(conn, "/api/v1/accounts/#{remote.id}")
197 assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
201 describe "user fetching with restrict unauthenticated profiles for remote" do
202 setup do: local_and_remote_users()
204 setup do: clear_config([:restrict_unauthenticated, :profiles, :remote], true)
206 test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
207 res_conn = get(conn, "/api/v1/accounts/#{local.id}")
208 assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
210 res_conn = get(conn, "/api/v1/accounts/#{remote.id}")
212 assert json_response_and_validate_schema(res_conn, :unauthorized) == %{
213 "error" => "This API requires an authenticated user"
217 test "if user is authenticated", %{local: local, remote: remote} do
218 %{conn: conn} = oauth_access(["read"])
220 res_conn = get(conn, "/api/v1/accounts/#{local.id}")
221 assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
223 res_conn = get(conn, "/api/v1/accounts/#{remote.id}")
224 assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
228 describe "user timelines" do
229 setup do: oauth_access(["read:statuses"])
231 test "works with announces that are just addressed to public", %{conn: conn} do
232 user = insert(:user, ap_id: "https://honktest/u/test", local: false)
233 other_user = insert(:user)
235 {:ok, post} = CommonAPI.post(other_user, %{status: "bonkeronk"})
239 "@context" => "https://www.w3.org/ns/activitystreams",
240 "actor" => "https://honktest/u/test",
241 "id" => "https://honktest/u/test/bonk/1793M7B9MQ48847vdx",
242 "object" => post.data["object"],
243 "published" => "2019-06-25T19:33:58Z",
244 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
247 |> ActivityPub.persist(local: false)
251 |> get("/api/v1/accounts/#{user.id}/statuses")
252 |> json_response_and_validate_schema(200)
254 assert [%{"id" => id}] = resp
255 assert id == announce.id
258 test "deactivated user", %{conn: conn} do
259 user = insert(:user, deactivated: true)
261 assert %{"error" => "Can't find user"} ==
263 |> get("/api/v1/accounts/#{user.id}/statuses")
264 |> json_response_and_validate_schema(:not_found)
267 test "returns 404 when user is invisible", %{conn: conn} do
268 user = insert(:user, %{invisible: true})
270 assert %{"error" => "Can't find user"} =
272 |> get("/api/v1/accounts/#{user.id}")
273 |> json_response_and_validate_schema(404)
276 test "respects blocks", %{user: user_one, conn: conn} do
277 user_two = insert(:user)
278 user_three = insert(:user)
280 User.block(user_one, user_two)
282 {:ok, activity} = CommonAPI.post(user_two, %{status: "User one sux0rz"})
283 {:ok, repeat} = CommonAPI.repeat(activity.id, user_three)
287 |> get("/api/v1/accounts/#{user_two.id}/statuses")
288 |> json_response_and_validate_schema(200)
290 assert [%{"id" => id}] = resp
291 assert id == activity.id
293 # Even a blocked user will deliver the full user timeline, there would be
294 # no point in looking at a blocked users timeline otherwise
297 |> get("/api/v1/accounts/#{user_two.id}/statuses")
298 |> json_response_and_validate_schema(200)
300 assert [%{"id" => id}] = resp
301 assert id == activity.id
303 # Third user's timeline includes the repeat when viewed by unauthenticated user
306 |> get("/api/v1/accounts/#{user_three.id}/statuses")
307 |> json_response_and_validate_schema(200)
309 assert [%{"id" => id}] = resp
310 assert id == repeat.id
312 # When viewing a third user's timeline, the blocked users' statuses will NOT be shown
313 resp = get(conn, "/api/v1/accounts/#{user_three.id}/statuses")
315 assert [] == json_response_and_validate_schema(resp, 200)
318 test "gets users statuses", %{conn: conn} do
319 user_one = insert(:user)
320 user_two = insert(:user)
321 user_three = insert(:user)
323 {:ok, _user_three, _user_one} = User.follow(user_three, user_one)
325 {:ok, activity} = CommonAPI.post(user_one, %{status: "HI!!!"})
327 {:ok, direct_activity} =
328 CommonAPI.post(user_one, %{
329 status: "Hi, @#{user_two.nickname}.",
333 {:ok, private_activity} =
334 CommonAPI.post(user_one, %{status: "private", visibility: "private"})
339 |> get("/api/v1/accounts/#{user_one.id}/statuses")
340 |> json_response_and_validate_schema(200)
342 assert [%{"id" => id}] = resp
343 assert id == to_string(activity.id)
347 |> assign(:user, user_two)
348 |> assign(:token, insert(:oauth_token, user: user_two, scopes: ["read:statuses"]))
349 |> get("/api/v1/accounts/#{user_one.id}/statuses")
350 |> json_response_and_validate_schema(200)
352 assert [%{"id" => id_one}, %{"id" => id_two}] = resp
353 assert id_one == to_string(direct_activity.id)
354 assert id_two == to_string(activity.id)
358 |> assign(:user, user_three)
359 |> assign(:token, insert(:oauth_token, user: user_three, scopes: ["read:statuses"]))
360 |> get("/api/v1/accounts/#{user_one.id}/statuses")
361 |> json_response_and_validate_schema(200)
363 assert [%{"id" => id_one}, %{"id" => id_two}] = resp
364 assert id_one == to_string(private_activity.id)
365 assert id_two == to_string(activity.id)
368 test "unimplemented pinned statuses feature", %{conn: conn} do
369 note = insert(:note_activity)
370 user = User.get_cached_by_ap_id(note.data["actor"])
372 conn = get(conn, "/api/v1/accounts/#{user.id}/statuses?pinned=true")
374 assert json_response_and_validate_schema(conn, 200) == []
377 test "gets an users media, excludes reblogs", %{conn: conn} do
378 note = insert(:note_activity)
379 user = User.get_cached_by_ap_id(note.data["actor"])
380 other_user = insert(:user)
383 content_type: "image/jpeg",
384 path: Path.absname("test/fixtures/image.jpg"),
385 filename: "an_image.jpg"
388 {:ok, %{id: media_id}} = ActivityPub.upload(file, actor: user.ap_id)
390 {:ok, %{id: image_post_id}} = CommonAPI.post(user, %{status: "cofe", media_ids: [media_id]})
392 {:ok, %{id: media_id}} = ActivityPub.upload(file, actor: other_user.ap_id)
394 {:ok, %{id: other_image_post_id}} =
395 CommonAPI.post(other_user, %{status: "cofe2", media_ids: [media_id]})
397 {:ok, _announce} = CommonAPI.repeat(other_image_post_id, user)
399 conn = get(conn, "/api/v1/accounts/#{user.id}/statuses?only_media=true")
401 assert [%{"id" => ^image_post_id}] = json_response_and_validate_schema(conn, 200)
403 conn = get(build_conn(), "/api/v1/accounts/#{user.id}/statuses?only_media=1")
405 assert [%{"id" => ^image_post_id}] = json_response_and_validate_schema(conn, 200)
408 test "gets a user's statuses without reblogs", %{user: user, conn: conn} do
409 {:ok, %{id: post_id}} = CommonAPI.post(user, %{status: "HI!!!"})
410 {:ok, _} = CommonAPI.repeat(post_id, user)
412 conn = get(conn, "/api/v1/accounts/#{user.id}/statuses?exclude_reblogs=true")
413 assert [%{"id" => ^post_id}] = json_response_and_validate_schema(conn, 200)
415 conn = get(conn, "/api/v1/accounts/#{user.id}/statuses?exclude_reblogs=1")
416 assert [%{"id" => ^post_id}] = json_response_and_validate_schema(conn, 200)
419 test "filters user's statuses by a hashtag", %{user: user, conn: conn} do
420 {:ok, %{id: post_id}} = CommonAPI.post(user, %{status: "#hashtag"})
421 {:ok, _post} = CommonAPI.post(user, %{status: "hashtag"})
423 conn = get(conn, "/api/v1/accounts/#{user.id}/statuses?tagged=hashtag")
424 assert [%{"id" => ^post_id}] = json_response_and_validate_schema(conn, 200)
427 test "the user views their own timelines and excludes direct messages", %{
431 {:ok, %{id: public_activity_id}} =
432 CommonAPI.post(user, %{status: ".", visibility: "public"})
434 {:ok, _direct_activity} = CommonAPI.post(user, %{status: ".", visibility: "direct"})
436 conn = get(conn, "/api/v1/accounts/#{user.id}/statuses?exclude_visibilities[]=direct")
437 assert [%{"id" => ^public_activity_id}] = json_response_and_validate_schema(conn, 200)
440 test "muted reactions", %{user: user, conn: conn} do
441 user2 = insert(:user)
442 User.mute(user, user2)
443 {:ok, activity} = CommonAPI.post(user, %{status: "."})
444 {:ok, _} = CommonAPI.react_with_emoji(activity.id, user2, "🎅")
448 |> get("/api/v1/accounts/#{user.id}/statuses")
449 |> json_response_and_validate_schema(200)
454 "emoji_reactions" => []
461 |> get("/api/v1/accounts/#{user.id}/statuses?with_muted=true")
462 |> json_response_and_validate_schema(200)
467 "emoji_reactions" => [%{"count" => 1, "me" => false, "name" => "🎅"}]
473 test "paginates a user's statuses", %{user: user, conn: conn} do
474 {:ok, post_1} = CommonAPI.post(user, %{status: "first post"})
475 {:ok, post_2} = CommonAPI.post(user, %{status: "second post"})
477 response_1 = get(conn, "/api/v1/accounts/#{user.id}/statuses?limit=1")
478 assert [res] = json_response(response_1, 200)
479 assert res["id"] == post_2.id
481 response_2 = get(conn, "/api/v1/accounts/#{user.id}/statuses?limit=1&max_id=#{res["id"]}")
482 assert [res] = json_response(response_2, 200)
483 assert res["id"] == post_1.id
485 refute response_1 == response_2
489 defp local_and_remote_activities(%{local: local, remote: remote}) do
490 insert(:note_activity, user: local)
491 insert(:note_activity, user: remote, local: false)
496 describe "statuses with restrict unauthenticated profiles for local and remote" do
497 setup do: local_and_remote_users()
498 setup :local_and_remote_activities
500 setup do: clear_config([:restrict_unauthenticated, :profiles, :local], true)
502 setup do: clear_config([:restrict_unauthenticated, :profiles, :remote], true)
504 test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
505 assert %{"error" => "This API requires an authenticated user"} ==
507 |> get("/api/v1/accounts/#{local.id}/statuses")
508 |> json_response_and_validate_schema(:unauthorized)
510 assert %{"error" => "This API requires an authenticated user"} ==
512 |> get("/api/v1/accounts/#{remote.id}/statuses")
513 |> json_response_and_validate_schema(:unauthorized)
516 test "if user is authenticated", %{local: local, remote: remote} do
517 %{conn: conn} = oauth_access(["read"])
519 res_conn = get(conn, "/api/v1/accounts/#{local.id}/statuses")
520 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
522 res_conn = get(conn, "/api/v1/accounts/#{remote.id}/statuses")
523 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
527 describe "statuses with restrict unauthenticated profiles for local" do
528 setup do: local_and_remote_users()
529 setup :local_and_remote_activities
531 setup do: clear_config([:restrict_unauthenticated, :profiles, :local], true)
533 test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
534 assert %{"error" => "This API requires an authenticated user"} ==
536 |> get("/api/v1/accounts/#{local.id}/statuses")
537 |> json_response_and_validate_schema(:unauthorized)
539 res_conn = get(conn, "/api/v1/accounts/#{remote.id}/statuses")
540 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
543 test "if user is authenticated", %{local: local, remote: remote} do
544 %{conn: conn} = oauth_access(["read"])
546 res_conn = get(conn, "/api/v1/accounts/#{local.id}/statuses")
547 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
549 res_conn = get(conn, "/api/v1/accounts/#{remote.id}/statuses")
550 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
554 describe "statuses with restrict unauthenticated profiles for remote" do
555 setup do: local_and_remote_users()
556 setup :local_and_remote_activities
558 setup do: clear_config([:restrict_unauthenticated, :profiles, :remote], true)
560 test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
561 res_conn = get(conn, "/api/v1/accounts/#{local.id}/statuses")
562 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
564 assert %{"error" => "This API requires an authenticated user"} ==
566 |> get("/api/v1/accounts/#{remote.id}/statuses")
567 |> json_response_and_validate_schema(:unauthorized)
570 test "if user is authenticated", %{local: local, remote: remote} do
571 %{conn: conn} = oauth_access(["read"])
573 res_conn = get(conn, "/api/v1/accounts/#{local.id}/statuses")
574 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
576 res_conn = get(conn, "/api/v1/accounts/#{remote.id}/statuses")
577 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
581 describe "followers" do
582 setup do: oauth_access(["read:accounts"])
584 test "getting followers", %{user: user, conn: conn} do
585 other_user = insert(:user)
586 {:ok, %{id: user_id}, other_user} = User.follow(user, other_user)
588 conn = get(conn, "/api/v1/accounts/#{other_user.id}/followers")
590 assert [%{"id" => ^user_id}] = json_response_and_validate_schema(conn, 200)
593 test "getting followers, hide_followers", %{user: user, conn: conn} do
594 other_user = insert(:user, hide_followers: true)
595 {:ok, _user, _other_user} = User.follow(user, other_user)
597 conn = get(conn, "/api/v1/accounts/#{other_user.id}/followers")
599 assert [] == json_response_and_validate_schema(conn, 200)
602 test "getting followers, hide_followers, same user requesting" do
604 other_user = insert(:user, hide_followers: true)
605 {:ok, _user, _other_user} = User.follow(user, other_user)
609 |> assign(:user, other_user)
610 |> assign(:token, insert(:oauth_token, user: other_user, scopes: ["read:accounts"]))
611 |> get("/api/v1/accounts/#{other_user.id}/followers")
613 refute [] == json_response_and_validate_schema(conn, 200)
616 test "getting followers, pagination", %{user: user, conn: conn} do
617 {:ok, %User{id: follower1_id}, _user} = :user |> insert() |> User.follow(user)
618 {:ok, %User{id: follower2_id}, _user} = :user |> insert() |> User.follow(user)
619 {:ok, %User{id: follower3_id}, _user} = :user |> insert() |> User.follow(user)
621 assert [%{"id" => ^follower3_id}, %{"id" => ^follower2_id}] =
623 |> get("/api/v1/accounts/#{user.id}/followers?since_id=#{follower1_id}")
624 |> json_response_and_validate_schema(200)
626 assert [%{"id" => ^follower2_id}, %{"id" => ^follower1_id}] =
628 |> get("/api/v1/accounts/#{user.id}/followers?max_id=#{follower3_id}")
629 |> json_response_and_validate_schema(200)
631 assert [%{"id" => ^follower2_id}, %{"id" => ^follower1_id}] =
634 "/api/v1/accounts/#{user.id}/followers?id=#{user.id}&limit=20&max_id=#{
638 |> json_response_and_validate_schema(200)
640 res_conn = get(conn, "/api/v1/accounts/#{user.id}/followers?limit=1&max_id=#{follower3_id}")
642 assert [%{"id" => ^follower2_id}] = json_response_and_validate_schema(res_conn, 200)
644 assert [link_header] = get_resp_header(res_conn, "link")
645 assert link_header =~ ~r/min_id=#{follower2_id}/
646 assert link_header =~ ~r/max_id=#{follower2_id}/
650 describe "following" do
651 setup do: oauth_access(["read:accounts"])
653 test "getting following", %{user: user, conn: conn} do
654 other_user = insert(:user)
655 {:ok, user, other_user} = User.follow(user, other_user)
657 conn = get(conn, "/api/v1/accounts/#{user.id}/following")
659 assert [%{"id" => id}] = json_response_and_validate_schema(conn, 200)
660 assert id == to_string(other_user.id)
663 test "getting following, hide_follows, other user requesting" do
664 user = insert(:user, hide_follows: true)
665 other_user = insert(:user)
666 {:ok, user, other_user} = User.follow(user, other_user)
670 |> assign(:user, other_user)
671 |> assign(:token, insert(:oauth_token, user: other_user, scopes: ["read:accounts"]))
672 |> get("/api/v1/accounts/#{user.id}/following")
674 assert [] == json_response_and_validate_schema(conn, 200)
677 test "getting following, hide_follows, same user requesting" do
678 user = insert(:user, hide_follows: true)
679 other_user = insert(:user)
680 {:ok, user, _other_user} = User.follow(user, other_user)
684 |> assign(:user, user)
685 |> assign(:token, insert(:oauth_token, user: user, scopes: ["read:accounts"]))
686 |> get("/api/v1/accounts/#{user.id}/following")
688 refute [] == json_response_and_validate_schema(conn, 200)
691 test "getting following, pagination", %{user: user, conn: conn} do
692 following1 = insert(:user)
693 following2 = insert(:user)
694 following3 = insert(:user)
695 {:ok, _, _} = User.follow(user, following1)
696 {:ok, _, _} = User.follow(user, following2)
697 {:ok, _, _} = User.follow(user, following3)
699 res_conn = get(conn, "/api/v1/accounts/#{user.id}/following?since_id=#{following1.id}")
701 assert [%{"id" => id3}, %{"id" => id2}] = json_response_and_validate_schema(res_conn, 200)
702 assert id3 == following3.id
703 assert id2 == following2.id
705 res_conn = get(conn, "/api/v1/accounts/#{user.id}/following?max_id=#{following3.id}")
707 assert [%{"id" => id2}, %{"id" => id1}] = json_response_and_validate_schema(res_conn, 200)
708 assert id2 == following2.id
709 assert id1 == following1.id
714 "/api/v1/accounts/#{user.id}/following?id=#{user.id}&limit=20&max_id=#{following3.id}"
717 assert [%{"id" => id2}, %{"id" => id1}] = json_response_and_validate_schema(res_conn, 200)
718 assert id2 == following2.id
719 assert id1 == following1.id
722 get(conn, "/api/v1/accounts/#{user.id}/following?limit=1&max_id=#{following3.id}")
724 assert [%{"id" => id2}] = json_response_and_validate_schema(res_conn, 200)
725 assert id2 == following2.id
727 assert [link_header] = get_resp_header(res_conn, "link")
728 assert link_header =~ ~r/min_id=#{following2.id}/
729 assert link_header =~ ~r/max_id=#{following2.id}/
733 describe "follow/unfollow" do
734 setup do: oauth_access(["follow"])
736 test "following / unfollowing a user", %{conn: conn} do
737 %{id: other_user_id, nickname: other_user_nickname} = insert(:user)
739 assert %{"id" => _id, "following" => true} =
741 |> post("/api/v1/accounts/#{other_user_id}/follow")
742 |> json_response_and_validate_schema(200)
744 assert %{"id" => _id, "following" => false} =
746 |> post("/api/v1/accounts/#{other_user_id}/unfollow")
747 |> json_response_and_validate_schema(200)
749 assert %{"id" => ^other_user_id} =
751 |> put_req_header("content-type", "application/json")
752 |> post("/api/v1/follows", %{"uri" => other_user_nickname})
753 |> json_response_and_validate_schema(200)
756 test "cancelling follow request", %{conn: conn} do
757 %{id: other_user_id} = insert(:user, %{is_locked: true})
759 assert %{"id" => ^other_user_id, "following" => false, "requested" => true} =
761 |> post("/api/v1/accounts/#{other_user_id}/follow")
762 |> json_response_and_validate_schema(:ok)
764 assert %{"id" => ^other_user_id, "following" => false, "requested" => false} =
766 |> post("/api/v1/accounts/#{other_user_id}/unfollow")
767 |> json_response_and_validate_schema(:ok)
770 test "following without reblogs" do
771 %{conn: conn} = oauth_access(["follow", "read:statuses"])
772 followed = insert(:user)
773 other_user = insert(:user)
777 |> put_req_header("content-type", "application/json")
778 |> post("/api/v1/accounts/#{followed.id}/follow", %{reblogs: false})
780 assert %{"showing_reblogs" => false} = json_response_and_validate_schema(ret_conn, 200)
782 {:ok, activity} = CommonAPI.post(other_user, %{status: "hey"})
783 {:ok, %{id: reblog_id}} = CommonAPI.repeat(activity.id, followed)
787 |> get("/api/v1/timelines/home")
788 |> json_response(200)
790 assert %{"showing_reblogs" => true} =
792 |> put_req_header("content-type", "application/json")
793 |> post("/api/v1/accounts/#{followed.id}/follow", %{reblogs: true})
794 |> json_response_and_validate_schema(200)
796 assert [%{"id" => ^reblog_id}] =
798 |> get("/api/v1/timelines/home")
799 |> json_response(200)
802 test "following with reblogs" do
803 %{conn: conn} = oauth_access(["follow", "read:statuses"])
804 followed = insert(:user)
805 other_user = insert(:user)
807 ret_conn = post(conn, "/api/v1/accounts/#{followed.id}/follow")
809 assert %{"showing_reblogs" => true} = json_response_and_validate_schema(ret_conn, 200)
811 {:ok, activity} = CommonAPI.post(other_user, %{status: "hey"})
812 {:ok, %{id: reblog_id}} = CommonAPI.repeat(activity.id, followed)
814 assert [%{"id" => ^reblog_id}] =
816 |> get("/api/v1/timelines/home")
817 |> json_response(200)
819 assert %{"showing_reblogs" => false} =
821 |> put_req_header("content-type", "application/json")
822 |> post("/api/v1/accounts/#{followed.id}/follow", %{reblogs: false})
823 |> json_response_and_validate_schema(200)
827 |> get("/api/v1/timelines/home")
828 |> json_response(200)
831 test "following / unfollowing errors", %{user: user, conn: conn} do
833 conn_res = post(conn, "/api/v1/accounts/#{user.id}/follow")
835 assert %{"error" => "Can not follow yourself"} =
836 json_response_and_validate_schema(conn_res, 400)
839 user = User.get_cached_by_id(user.id)
840 conn_res = post(conn, "/api/v1/accounts/#{user.id}/unfollow")
842 assert %{"error" => "Can not unfollow yourself"} =
843 json_response_and_validate_schema(conn_res, 400)
845 # self follow via uri
846 user = User.get_cached_by_id(user.id)
848 assert %{"error" => "Can not follow yourself"} =
850 |> put_req_header("content-type", "multipart/form-data")
851 |> post("/api/v1/follows", %{"uri" => user.nickname})
852 |> json_response_and_validate_schema(400)
854 # follow non existing user
855 conn_res = post(conn, "/api/v1/accounts/doesntexist/follow")
856 assert %{"error" => "Record not found"} = json_response_and_validate_schema(conn_res, 404)
858 # follow non existing user via uri
861 |> put_req_header("content-type", "multipart/form-data")
862 |> post("/api/v1/follows", %{"uri" => "doesntexist"})
864 assert %{"error" => "Record not found"} = json_response_and_validate_schema(conn_res, 404)
866 # unfollow non existing user
867 conn_res = post(conn, "/api/v1/accounts/doesntexist/unfollow")
868 assert %{"error" => "Record not found"} = json_response_and_validate_schema(conn_res, 404)
872 describe "mute/unmute" do
873 setup do: oauth_access(["write:mutes"])
875 test "with notifications", %{conn: conn} do
876 other_user = insert(:user)
878 assert %{"id" => _id, "muting" => true, "muting_notifications" => true} =
880 |> post("/api/v1/accounts/#{other_user.id}/mute")
881 |> json_response_and_validate_schema(200)
883 conn = post(conn, "/api/v1/accounts/#{other_user.id}/unmute")
885 assert %{"id" => _id, "muting" => false, "muting_notifications" => false} =
886 json_response_and_validate_schema(conn, 200)
889 test "without notifications", %{conn: conn} do
890 other_user = insert(:user)
894 |> put_req_header("content-type", "multipart/form-data")
895 |> post("/api/v1/accounts/#{other_user.id}/mute", %{"notifications" => "false"})
897 assert %{"id" => _id, "muting" => true, "muting_notifications" => false} =
898 json_response_and_validate_schema(ret_conn, 200)
900 conn = post(conn, "/api/v1/accounts/#{other_user.id}/unmute")
902 assert %{"id" => _id, "muting" => false, "muting_notifications" => false} =
903 json_response_and_validate_schema(conn, 200)
907 describe "pinned statuses" do
910 {:ok, activity} = CommonAPI.post(user, %{status: "HI!!!"})
911 %{conn: conn} = oauth_access(["read:statuses"], user: user)
913 [conn: conn, user: user, activity: activity]
916 test "returns pinned statuses", %{conn: conn, user: user, activity: %{id: activity_id}} do
917 {:ok, _} = CommonAPI.pin(activity_id, user)
919 assert [%{"id" => ^activity_id, "pinned" => true}] =
921 |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
922 |> json_response_and_validate_schema(200)
926 test "blocking / unblocking a user" do
927 %{conn: conn} = oauth_access(["follow"])
928 other_user = insert(:user)
930 ret_conn = post(conn, "/api/v1/accounts/#{other_user.id}/block")
932 assert %{"id" => _id, "blocking" => true} = json_response_and_validate_schema(ret_conn, 200)
934 conn = post(conn, "/api/v1/accounts/#{other_user.id}/unblock")
936 assert %{"id" => _id, "blocking" => false} = json_response_and_validate_schema(conn, 200)
939 describe "create account by app" do
943 email: "lain@example.org",
944 password: "PlzDontHackLain",
948 [valid_params: valid_params]
951 test "registers and logs in without :account_activation_required / :account_approval_required",
953 clear_config([:instance, :account_activation_required], false)
954 clear_config([:instance, :account_approval_required], false)
958 |> put_req_header("content-type", "application/json")
959 |> post("/api/v1/apps", %{
960 client_name: "client_name",
961 redirect_uris: "urn:ietf:wg:oauth:2.0:oob",
962 scopes: "read, write, follow"
966 "client_id" => client_id,
967 "client_secret" => client_secret,
969 "name" => "client_name",
970 "redirect_uri" => "urn:ietf:wg:oauth:2.0:oob",
973 } = json_response_and_validate_schema(conn, 200)
976 post(conn, "/oauth/token", %{
977 grant_type: "client_credentials",
978 client_id: client_id,
979 client_secret: client_secret
982 assert %{"access_token" => token, "refresh_token" => refresh, "scope" => scope} =
983 json_response(conn, 200)
986 token_from_db = Repo.get_by(Token, token: token)
989 assert scope == "read write follow"
991 clear_config([User, :email_blacklist], ["example.org"])
995 email: "lain@example.org",
996 password: "PlzDontHackLain",
1003 |> put_req_header("content-type", "multipart/form-data")
1004 |> put_req_header("authorization", "Bearer " <> token)
1005 |> post("/api/v1/accounts", params)
1007 assert %{"error" => "{\"email\":[\"Invalid email\"]}"} =
1008 json_response_and_validate_schema(conn, 400)
1010 Pleroma.Config.put([User, :email_blacklist], [])
1014 |> put_req_header("content-type", "multipart/form-data")
1015 |> put_req_header("authorization", "Bearer " <> token)
1016 |> post("/api/v1/accounts", params)
1019 "access_token" => token,
1020 "created_at" => _created_at,
1022 "token_type" => "Bearer"
1023 } = json_response_and_validate_schema(conn, 200)
1025 token_from_db = Repo.get_by(Token, token: token)
1026 assert token_from_db
1027 user = Repo.preload(token_from_db, :user).user
1030 refute user.confirmation_pending
1031 assert user.is_approved
1034 test "registers but does not log in with :account_activation_required", %{conn: conn} do
1035 clear_config([:instance, :account_activation_required], true)
1036 clear_config([:instance, :account_approval_required], false)
1040 |> put_req_header("content-type", "application/json")
1041 |> post("/api/v1/apps", %{
1042 client_name: "client_name",
1043 redirect_uris: "urn:ietf:wg:oauth:2.0:oob",
1044 scopes: "read, write, follow"
1048 "client_id" => client_id,
1049 "client_secret" => client_secret,
1051 "name" => "client_name",
1052 "redirect_uri" => "urn:ietf:wg:oauth:2.0:oob",
1055 } = json_response_and_validate_schema(conn, 200)
1058 post(conn, "/oauth/token", %{
1059 grant_type: "client_credentials",
1060 client_id: client_id,
1061 client_secret: client_secret
1064 assert %{"access_token" => token, "refresh_token" => refresh, "scope" => scope} =
1065 json_response(conn, 200)
1068 token_from_db = Repo.get_by(Token, token: token)
1069 assert token_from_db
1071 assert scope == "read write follow"
1075 |> put_req_header("content-type", "multipart/form-data")
1076 |> put_req_header("authorization", "Bearer " <> token)
1077 |> post("/api/v1/accounts", %{
1079 email: "lain@example.org",
1080 password: "PlzDontHackLain",
1085 response = json_response_and_validate_schema(conn, 200)
1086 assert %{"identifier" => "missing_confirmed_email"} = response
1087 refute response["access_token"]
1088 refute response["token_type"]
1090 user = Repo.get_by(User, email: "lain@example.org")
1091 assert user.confirmation_pending
1094 test "registers but does not log in with :account_approval_required", %{conn: conn} do
1095 clear_config([:instance, :account_approval_required], true)
1096 clear_config([:instance, :account_activation_required], false)
1100 |> put_req_header("content-type", "application/json")
1101 |> post("/api/v1/apps", %{
1102 client_name: "client_name",
1103 redirect_uris: "urn:ietf:wg:oauth:2.0:oob",
1104 scopes: "read, write, follow"
1108 "client_id" => client_id,
1109 "client_secret" => client_secret,
1111 "name" => "client_name",
1112 "redirect_uri" => "urn:ietf:wg:oauth:2.0:oob",
1115 } = json_response_and_validate_schema(conn, 200)
1118 post(conn, "/oauth/token", %{
1119 grant_type: "client_credentials",
1120 client_id: client_id,
1121 client_secret: client_secret
1124 assert %{"access_token" => token, "refresh_token" => refresh, "scope" => scope} =
1125 json_response(conn, 200)
1128 token_from_db = Repo.get_by(Token, token: token)
1129 assert token_from_db
1131 assert scope == "read write follow"
1135 |> put_req_header("content-type", "multipart/form-data")
1136 |> put_req_header("authorization", "Bearer " <> token)
1137 |> post("/api/v1/accounts", %{
1139 email: "lain@example.org",
1140 password: "PlzDontHackLain",
1143 reason: "I'm a cool dude, bro"
1146 response = json_response_and_validate_schema(conn, 200)
1147 assert %{"identifier" => "awaiting_approval"} = response
1148 refute response["access_token"]
1149 refute response["token_type"]
1151 user = Repo.get_by(User, email: "lain@example.org")
1153 refute user.is_approved
1154 assert user.registration_reason == "I'm a cool dude, bro"
1157 test "returns error when user already registred", %{conn: conn, valid_params: valid_params} do
1158 _user = insert(:user, email: "lain@example.org")
1159 app_token = insert(:oauth_token, user: nil)
1163 |> put_req_header("authorization", "Bearer " <> app_token.token)
1164 |> put_req_header("content-type", "application/json")
1165 |> post("/api/v1/accounts", valid_params)
1167 assert json_response_and_validate_schema(res, 400) == %{
1168 "error" => "{\"email\":[\"has already been taken\"]}"
1172 test "returns bad_request if missing required params", %{
1174 valid_params: valid_params
1176 app_token = insert(:oauth_token, user: nil)
1180 |> put_req_header("authorization", "Bearer " <> app_token.token)
1181 |> put_req_header("content-type", "application/json")
1183 res = post(conn, "/api/v1/accounts", valid_params)
1184 assert json_response_and_validate_schema(res, 200)
1186 [{127, 0, 0, 1}, {127, 0, 0, 2}, {127, 0, 0, 3}, {127, 0, 0, 4}]
1187 |> Stream.zip(Map.delete(valid_params, :email))
1188 |> Enum.each(fn {ip, {attr, _}} ->
1191 |> Map.put(:remote_ip, ip)
1192 |> post("/api/v1/accounts", Map.delete(valid_params, attr))
1193 |> json_response_and_validate_schema(400)
1196 "error" => "Missing field: #{attr}.",
1199 "message" => "Missing field: #{attr}",
1200 "source" => %{"pointer" => "/#{attr}"},
1201 "title" => "Invalid value"
1208 test "returns bad_request if missing email params when :account_activation_required is enabled",
1209 %{conn: conn, valid_params: valid_params} do
1210 clear_config([:instance, :account_activation_required], true)
1212 app_token = insert(:oauth_token, user: nil)
1216 |> put_req_header("authorization", "Bearer " <> app_token.token)
1217 |> put_req_header("content-type", "application/json")
1221 |> Map.put(:remote_ip, {127, 0, 0, 5})
1222 |> post("/api/v1/accounts", Map.delete(valid_params, :email))
1224 assert json_response_and_validate_schema(res, 400) ==
1225 %{"error" => "Missing parameter: email"}
1229 |> Map.put(:remote_ip, {127, 0, 0, 6})
1230 |> post("/api/v1/accounts", Map.put(valid_params, :email, ""))
1232 assert json_response_and_validate_schema(res, 400) == %{
1233 "error" => "{\"email\":[\"can't be blank\"]}"
1237 test "allow registration without an email", %{conn: conn, valid_params: valid_params} do
1238 app_token = insert(:oauth_token, user: nil)
1239 conn = put_req_header(conn, "authorization", "Bearer " <> app_token.token)
1243 |> put_req_header("content-type", "application/json")
1244 |> Map.put(:remote_ip, {127, 0, 0, 7})
1245 |> post("/api/v1/accounts", Map.delete(valid_params, :email))
1247 assert json_response_and_validate_schema(res, 200)
1250 test "allow registration with an empty email", %{conn: conn, valid_params: valid_params} do
1251 app_token = insert(:oauth_token, user: nil)
1252 conn = put_req_header(conn, "authorization", "Bearer " <> app_token.token)
1256 |> put_req_header("content-type", "application/json")
1257 |> Map.put(:remote_ip, {127, 0, 0, 8})
1258 |> post("/api/v1/accounts", Map.put(valid_params, :email, ""))
1260 assert json_response_and_validate_schema(res, 200)
1263 test "returns forbidden if token is invalid", %{conn: conn, valid_params: valid_params} do
1266 |> put_req_header("authorization", "Bearer " <> "invalid-token")
1267 |> put_req_header("content-type", "multipart/form-data")
1268 |> post("/api/v1/accounts", valid_params)
1270 assert json_response_and_validate_schema(res, 403) == %{"error" => "Invalid credentials"}
1273 test "registration from trusted app" do
1274 clear_config([Pleroma.Captcha, :enabled], true)
1275 app = insert(:oauth_app, trusted: true, scopes: ["read", "write", "follow", "push"])
1279 |> post("/oauth/token", %{
1280 "grant_type" => "client_credentials",
1281 "client_id" => app.client_id,
1282 "client_secret" => app.client_secret
1285 assert %{"access_token" => token, "token_type" => "Bearer"} = json_response(conn, 200)
1289 |> Plug.Conn.put_req_header("authorization", "Bearer " <> token)
1290 |> put_req_header("content-type", "multipart/form-data")
1291 |> post("/api/v1/accounts", %{
1292 nickname: "nickanme",
1294 email: "email@example.com",
1297 password: "some_password",
1298 confirm: "some_password"
1300 |> json_response_and_validate_schema(200)
1303 "access_token" => access_token,
1305 "scope" => "read write follow push",
1306 "token_type" => "Bearer"
1311 |> Plug.Conn.put_req_header("authorization", "Bearer " <> access_token)
1312 |> get("/api/v1/accounts/verify_credentials")
1313 |> json_response_and_validate_schema(200)
1318 "display_name" => "Lain",
1319 "follow_requests_count" => 0,
1320 "followers_count" => 0,
1321 "following_count" => 0,
1328 "actor_type" => "Person",
1329 "discoverable" => false,
1330 "no_rich_text" => false,
1333 "privacy" => "public",
1334 "sensitive" => false
1336 "statuses_count" => 0,
1337 "username" => "Lain"
1342 describe "create account by app / rate limit" do
1343 setup do: clear_config([:rate_limit, :app_account_creation], {10_000, 2})
1345 test "respects rate limit setting", %{conn: conn} do
1346 app_token = insert(:oauth_token, user: nil)
1350 |> put_req_header("authorization", "Bearer " <> app_token.token)
1351 |> Map.put(:remote_ip, {15, 15, 15, 15})
1352 |> put_req_header("content-type", "multipart/form-data")
1357 |> post("/api/v1/accounts", %{
1358 username: "#{i}lain",
1359 email: "#{i}lain@example.org",
1360 password: "PlzDontHackLain",
1365 "access_token" => token,
1366 "created_at" => _created_at,
1368 "token_type" => "Bearer"
1369 } = json_response_and_validate_schema(conn, 200)
1371 token_from_db = Repo.get_by(Token, token: token)
1372 assert token_from_db
1373 token_from_db = Repo.preload(token_from_db, :user)
1374 assert token_from_db.user
1378 post(conn, "/api/v1/accounts", %{
1380 email: "6lain@example.org",
1381 password: "PlzDontHackLain",
1385 assert json_response_and_validate_schema(conn, :too_many_requests) == %{
1386 "error" => "Throttled"
1391 describe "create account with enabled captcha" do
1392 setup %{conn: conn} do
1393 app_token = insert(:oauth_token, user: nil)
1397 |> put_req_header("authorization", "Bearer " <> app_token.token)
1398 |> put_req_header("content-type", "multipart/form-data")
1403 setup do: clear_config([Pleroma.Captcha, :enabled], true)
1405 test "creates an account and returns 200 if captcha is valid", %{conn: conn} do
1406 %{token: token, answer_data: answer_data} = Pleroma.Captcha.new()
1410 email: "lain@example.org",
1411 password: "PlzDontHackLain",
1413 captcha_solution: Pleroma.Captcha.Mock.solution(),
1414 captcha_token: token,
1415 captcha_answer_data: answer_data
1419 "access_token" => access_token,
1422 "token_type" => "Bearer"
1425 |> post("/api/v1/accounts", params)
1426 |> json_response_and_validate_schema(:ok)
1428 assert Token |> Repo.get_by(token: access_token) |> Repo.preload(:user) |> Map.get(:user)
1431 test "returns 400 if any captcha field is not provided", %{conn: conn} do
1432 captcha_fields = [:captcha_solution, :captcha_token, :captcha_answer_data]
1436 email: "lain@example.org",
1437 password: "PlzDontHackLain",
1439 captcha_solution: "xx",
1440 captcha_token: "xx",
1441 captcha_answer_data: "xx"
1444 for field <- captcha_fields do
1446 "error" => "{\"captcha\":[\"Invalid CAPTCHA (Missing parameter: #{field})\"]}"
1451 |> post("/api/v1/accounts", Map.delete(valid_params, field))
1452 |> json_response_and_validate_schema(:bad_request)
1456 test "returns an error if captcha is invalid", %{conn: conn} do
1459 email: "lain@example.org",
1460 password: "PlzDontHackLain",
1462 captcha_solution: "cofe",
1463 captcha_token: "cofe",
1464 captcha_answer_data: "cofe"
1467 assert %{"error" => "{\"captcha\":[\"Invalid answer data\"]}"} ==
1469 |> post("/api/v1/accounts", params)
1470 |> json_response_and_validate_schema(:bad_request)
1474 describe "GET /api/v1/accounts/:id/lists - account_lists" do
1475 test "returns lists to which the account belongs" do
1476 %{user: user, conn: conn} = oauth_access(["read:lists"])
1477 other_user = insert(:user)
1478 assert {:ok, %Pleroma.List{id: _list_id} = list} = Pleroma.List.create("Test List", user)
1479 {:ok, %{following: _following}} = Pleroma.List.follow(list, other_user)
1481 assert [%{"id" => _list_id, "title" => "Test List"}] =
1483 |> get("/api/v1/accounts/#{other_user.id}/lists")
1484 |> json_response_and_validate_schema(200)
1488 describe "verify_credentials" do
1489 test "verify_credentials" do
1490 %{user: user, conn: conn} = oauth_access(["read:accounts"])
1492 [notification | _] =
1493 insert_list(7, :notification, user: user, activity: insert(:note_activity))
1495 Pleroma.Notification.set_read_up_to(user, notification.id)
1496 conn = get(conn, "/api/v1/accounts/verify_credentials")
1498 response = json_response_and_validate_schema(conn, 200)
1500 assert %{"id" => id, "source" => %{"privacy" => "public"}} = response
1501 assert response["pleroma"]["chat_token"]
1502 assert response["pleroma"]["unread_notifications_count"] == 6
1503 assert id == to_string(user.id)
1506 test "verify_credentials default scope unlisted" do
1507 user = insert(:user, default_scope: "unlisted")
1508 %{conn: conn} = oauth_access(["read:accounts"], user: user)
1510 conn = get(conn, "/api/v1/accounts/verify_credentials")
1512 assert %{"id" => id, "source" => %{"privacy" => "unlisted"}} =
1513 json_response_and_validate_schema(conn, 200)
1515 assert id == to_string(user.id)
1518 test "locked accounts" do
1519 user = insert(:user, default_scope: "private")
1520 %{conn: conn} = oauth_access(["read:accounts"], user: user)
1522 conn = get(conn, "/api/v1/accounts/verify_credentials")
1524 assert %{"id" => id, "source" => %{"privacy" => "private"}} =
1525 json_response_and_validate_schema(conn, 200)
1527 assert id == to_string(user.id)
1531 describe "user relationships" do
1532 setup do: oauth_access(["read:follows"])
1534 test "returns the relationships for the current user", %{user: user, conn: conn} do
1535 %{id: other_user_id} = other_user = insert(:user)
1536 {:ok, _user, _other_user} = User.follow(user, other_user)
1538 assert [%{"id" => ^other_user_id}] =
1540 |> get("/api/v1/accounts/relationships?id=#{other_user.id}")
1541 |> json_response_and_validate_schema(200)
1543 assert [%{"id" => ^other_user_id}] =
1545 |> get("/api/v1/accounts/relationships?id[]=#{other_user.id}")
1546 |> json_response_and_validate_schema(200)
1549 test "returns an empty list on a bad request", %{conn: conn} do
1550 conn = get(conn, "/api/v1/accounts/relationships", %{})
1552 assert [] = json_response_and_validate_schema(conn, 200)
1556 test "getting a list of mutes" do
1557 %{user: user, conn: conn} = oauth_access(["read:mutes"])
1558 %{id: id1} = other_user1 = insert(:user)
1559 %{id: id2} = other_user2 = insert(:user)
1560 %{id: id3} = other_user3 = insert(:user)
1562 {:ok, _user_relationships} = User.mute(user, other_user1)
1563 {:ok, _user_relationships} = User.mute(user, other_user2)
1564 {:ok, _user_relationships} = User.mute(user, other_user3)
1568 |> assign(:user, user)
1569 |> get("/api/v1/mutes")
1570 |> json_response_and_validate_schema(200)
1572 assert [id1, id2, id3] == Enum.map(result, & &1["id"])
1576 |> assign(:user, user)
1577 |> get("/api/v1/mutes?limit=1")
1578 |> json_response_and_validate_schema(200)
1580 assert [%{"id" => ^id1}] = result
1584 |> assign(:user, user)
1585 |> get("/api/v1/mutes?since_id=#{id1}")
1586 |> json_response_and_validate_schema(200)
1588 assert [%{"id" => ^id2}, %{"id" => ^id3}] = result
1592 |> assign(:user, user)
1593 |> get("/api/v1/mutes?since_id=#{id1}&max_id=#{id3}")
1594 |> json_response_and_validate_schema(200)
1596 assert [%{"id" => ^id2}] = result
1600 |> assign(:user, user)
1601 |> get("/api/v1/mutes?since_id=#{id1}&limit=1")
1602 |> json_response_and_validate_schema(200)
1604 assert [%{"id" => ^id2}] = result
1607 test "getting a list of blocks" do
1608 %{user: user, conn: conn} = oauth_access(["read:blocks"])
1609 %{id: id1} = other_user1 = insert(:user)
1610 %{id: id2} = other_user2 = insert(:user)
1611 %{id: id3} = other_user3 = insert(:user)
1613 {:ok, _user_relationship} = User.block(user, other_user1)
1614 {:ok, _user_relationship} = User.block(user, other_user3)
1615 {:ok, _user_relationship} = User.block(user, other_user2)
1619 |> assign(:user, user)
1620 |> get("/api/v1/blocks")
1621 |> json_response_and_validate_schema(200)
1623 assert [id1, id2, id3] == Enum.map(result, & &1["id"])
1627 |> assign(:user, user)
1628 |> get("/api/v1/blocks?limit=1")
1629 |> json_response_and_validate_schema(200)
1631 assert [%{"id" => ^id1}] = result
1635 |> assign(:user, user)
1636 |> get("/api/v1/blocks?since_id=#{id1}")
1637 |> json_response_and_validate_schema(200)
1639 assert [%{"id" => ^id2}, %{"id" => ^id3}] = result
1643 |> assign(:user, user)
1644 |> get("/api/v1/blocks?since_id=#{id1}&max_id=#{id3}")
1645 |> json_response_and_validate_schema(200)
1647 assert [%{"id" => ^id2}] = result
1651 |> assign(:user, user)
1652 |> get("/api/v1/blocks?since_id=#{id1}&limit=1")
1653 |> json_response_and_validate_schema(200)
1655 assert [%{"id" => ^id2}] = result