1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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" => "🎅"}]
474 defp local_and_remote_activities(%{local: local, remote: remote}) do
475 insert(:note_activity, user: local)
476 insert(:note_activity, user: remote, local: false)
481 describe "statuses with restrict unauthenticated profiles for local and remote" do
482 setup do: local_and_remote_users()
483 setup :local_and_remote_activities
485 setup do: clear_config([:restrict_unauthenticated, :profiles, :local], true)
487 setup do: clear_config([:restrict_unauthenticated, :profiles, :remote], true)
489 test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
490 assert %{"error" => "This API requires an authenticated user"} ==
492 |> get("/api/v1/accounts/#{local.id}/statuses")
493 |> json_response_and_validate_schema(:unauthorized)
495 assert %{"error" => "This API requires an authenticated user"} ==
497 |> get("/api/v1/accounts/#{remote.id}/statuses")
498 |> json_response_and_validate_schema(:unauthorized)
501 test "if user is authenticated", %{local: local, remote: remote} do
502 %{conn: conn} = oauth_access(["read"])
504 res_conn = get(conn, "/api/v1/accounts/#{local.id}/statuses")
505 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
507 res_conn = get(conn, "/api/v1/accounts/#{remote.id}/statuses")
508 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
512 describe "statuses with restrict unauthenticated profiles for local" do
513 setup do: local_and_remote_users()
514 setup :local_and_remote_activities
516 setup do: clear_config([:restrict_unauthenticated, :profiles, :local], true)
518 test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
519 assert %{"error" => "This API requires an authenticated user"} ==
521 |> get("/api/v1/accounts/#{local.id}/statuses")
522 |> json_response_and_validate_schema(:unauthorized)
524 res_conn = get(conn, "/api/v1/accounts/#{remote.id}/statuses")
525 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
528 test "if user is authenticated", %{local: local, remote: remote} do
529 %{conn: conn} = oauth_access(["read"])
531 res_conn = get(conn, "/api/v1/accounts/#{local.id}/statuses")
532 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
534 res_conn = get(conn, "/api/v1/accounts/#{remote.id}/statuses")
535 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
539 describe "statuses with restrict unauthenticated profiles for remote" do
540 setup do: local_and_remote_users()
541 setup :local_and_remote_activities
543 setup do: clear_config([:restrict_unauthenticated, :profiles, :remote], true)
545 test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
546 res_conn = get(conn, "/api/v1/accounts/#{local.id}/statuses")
547 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
549 assert %{"error" => "This API requires an authenticated user"} ==
551 |> get("/api/v1/accounts/#{remote.id}/statuses")
552 |> json_response_and_validate_schema(:unauthorized)
555 test "if user is authenticated", %{local: local, remote: remote} do
556 %{conn: conn} = oauth_access(["read"])
558 res_conn = get(conn, "/api/v1/accounts/#{local.id}/statuses")
559 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
561 res_conn = get(conn, "/api/v1/accounts/#{remote.id}/statuses")
562 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
566 describe "followers" do
567 setup do: oauth_access(["read:accounts"])
569 test "getting followers", %{user: user, conn: conn} do
570 other_user = insert(:user)
571 {:ok, %{id: user_id}, other_user} = User.follow(user, other_user)
573 conn = get(conn, "/api/v1/accounts/#{other_user.id}/followers")
575 assert [%{"id" => ^user_id}] = json_response_and_validate_schema(conn, 200)
578 test "getting followers, hide_followers", %{user: user, conn: conn} do
579 other_user = insert(:user, hide_followers: true)
580 {:ok, _user, _other_user} = User.follow(user, other_user)
582 conn = get(conn, "/api/v1/accounts/#{other_user.id}/followers")
584 assert [] == json_response_and_validate_schema(conn, 200)
587 test "getting followers, hide_followers, same user requesting" do
589 other_user = insert(:user, hide_followers: true)
590 {:ok, _user, _other_user} = User.follow(user, other_user)
594 |> assign(:user, other_user)
595 |> assign(:token, insert(:oauth_token, user: other_user, scopes: ["read:accounts"]))
596 |> get("/api/v1/accounts/#{other_user.id}/followers")
598 refute [] == json_response_and_validate_schema(conn, 200)
601 test "getting followers, pagination", %{user: user, conn: conn} do
602 {:ok, %User{id: follower1_id}, _user} = :user |> insert() |> User.follow(user)
603 {:ok, %User{id: follower2_id}, _user} = :user |> insert() |> User.follow(user)
604 {:ok, %User{id: follower3_id}, _user} = :user |> insert() |> User.follow(user)
606 assert [%{"id" => ^follower3_id}, %{"id" => ^follower2_id}] =
608 |> get("/api/v1/accounts/#{user.id}/followers?since_id=#{follower1_id}")
609 |> json_response_and_validate_schema(200)
611 assert [%{"id" => ^follower2_id}, %{"id" => ^follower1_id}] =
613 |> get("/api/v1/accounts/#{user.id}/followers?max_id=#{follower3_id}")
614 |> json_response_and_validate_schema(200)
616 assert [%{"id" => ^follower2_id}, %{"id" => ^follower1_id}] =
619 "/api/v1/accounts/#{user.id}/followers?id=#{user.id}&limit=20&max_id=#{
623 |> json_response_and_validate_schema(200)
625 res_conn = get(conn, "/api/v1/accounts/#{user.id}/followers?limit=1&max_id=#{follower3_id}")
627 assert [%{"id" => ^follower2_id}] = json_response_and_validate_schema(res_conn, 200)
629 assert [link_header] = get_resp_header(res_conn, "link")
630 assert link_header =~ ~r/min_id=#{follower2_id}/
631 assert link_header =~ ~r/max_id=#{follower2_id}/
635 describe "following" do
636 setup do: oauth_access(["read:accounts"])
638 test "getting following", %{user: user, conn: conn} do
639 other_user = insert(:user)
640 {:ok, user, other_user} = User.follow(user, other_user)
642 conn = get(conn, "/api/v1/accounts/#{user.id}/following")
644 assert [%{"id" => id}] = json_response_and_validate_schema(conn, 200)
645 assert id == to_string(other_user.id)
648 test "getting following, hide_follows, other user requesting" do
649 user = insert(:user, hide_follows: true)
650 other_user = insert(:user)
651 {:ok, user, other_user} = User.follow(user, other_user)
655 |> assign(:user, other_user)
656 |> assign(:token, insert(:oauth_token, user: other_user, scopes: ["read:accounts"]))
657 |> get("/api/v1/accounts/#{user.id}/following")
659 assert [] == json_response_and_validate_schema(conn, 200)
662 test "getting following, hide_follows, same user requesting" do
663 user = insert(:user, hide_follows: true)
664 other_user = insert(:user)
665 {:ok, user, _other_user} = User.follow(user, other_user)
669 |> assign(:user, user)
670 |> assign(:token, insert(:oauth_token, user: user, scopes: ["read:accounts"]))
671 |> get("/api/v1/accounts/#{user.id}/following")
673 refute [] == json_response_and_validate_schema(conn, 200)
676 test "getting following, pagination", %{user: user, conn: conn} do
677 following1 = insert(:user)
678 following2 = insert(:user)
679 following3 = insert(:user)
680 {:ok, _, _} = User.follow(user, following1)
681 {:ok, _, _} = User.follow(user, following2)
682 {:ok, _, _} = User.follow(user, following3)
684 res_conn = get(conn, "/api/v1/accounts/#{user.id}/following?since_id=#{following1.id}")
686 assert [%{"id" => id3}, %{"id" => id2}] = json_response_and_validate_schema(res_conn, 200)
687 assert id3 == following3.id
688 assert id2 == following2.id
690 res_conn = get(conn, "/api/v1/accounts/#{user.id}/following?max_id=#{following3.id}")
692 assert [%{"id" => id2}, %{"id" => id1}] = json_response_and_validate_schema(res_conn, 200)
693 assert id2 == following2.id
694 assert id1 == following1.id
699 "/api/v1/accounts/#{user.id}/following?id=#{user.id}&limit=20&max_id=#{following3.id}"
702 assert [%{"id" => id2}, %{"id" => id1}] = json_response_and_validate_schema(res_conn, 200)
703 assert id2 == following2.id
704 assert id1 == following1.id
707 get(conn, "/api/v1/accounts/#{user.id}/following?limit=1&max_id=#{following3.id}")
709 assert [%{"id" => id2}] = json_response_and_validate_schema(res_conn, 200)
710 assert id2 == following2.id
712 assert [link_header] = get_resp_header(res_conn, "link")
713 assert link_header =~ ~r/min_id=#{following2.id}/
714 assert link_header =~ ~r/max_id=#{following2.id}/
718 describe "follow/unfollow" do
719 setup do: oauth_access(["follow"])
721 test "following / unfollowing a user", %{conn: conn} do
722 %{id: other_user_id, nickname: other_user_nickname} = insert(:user)
724 assert %{"id" => _id, "following" => true} =
726 |> post("/api/v1/accounts/#{other_user_id}/follow")
727 |> json_response_and_validate_schema(200)
729 assert %{"id" => _id, "following" => false} =
731 |> post("/api/v1/accounts/#{other_user_id}/unfollow")
732 |> json_response_and_validate_schema(200)
734 assert %{"id" => ^other_user_id} =
736 |> put_req_header("content-type", "application/json")
737 |> post("/api/v1/follows", %{"uri" => other_user_nickname})
738 |> json_response_and_validate_schema(200)
741 test "cancelling follow request", %{conn: conn} do
742 %{id: other_user_id} = insert(:user, %{is_locked: true})
744 assert %{"id" => ^other_user_id, "following" => false, "requested" => true} =
746 |> post("/api/v1/accounts/#{other_user_id}/follow")
747 |> json_response_and_validate_schema(:ok)
749 assert %{"id" => ^other_user_id, "following" => false, "requested" => false} =
751 |> post("/api/v1/accounts/#{other_user_id}/unfollow")
752 |> json_response_and_validate_schema(:ok)
755 test "following without reblogs" do
756 %{conn: conn} = oauth_access(["follow", "read:statuses"])
757 followed = insert(:user)
758 other_user = insert(:user)
762 |> put_req_header("content-type", "application/json")
763 |> post("/api/v1/accounts/#{followed.id}/follow", %{reblogs: false})
765 assert %{"showing_reblogs" => false} = json_response_and_validate_schema(ret_conn, 200)
767 {:ok, activity} = CommonAPI.post(other_user, %{status: "hey"})
768 {:ok, %{id: reblog_id}} = CommonAPI.repeat(activity.id, followed)
772 |> get("/api/v1/timelines/home")
773 |> json_response(200)
775 assert %{"showing_reblogs" => true} =
777 |> put_req_header("content-type", "application/json")
778 |> post("/api/v1/accounts/#{followed.id}/follow", %{reblogs: true})
779 |> json_response_and_validate_schema(200)
781 assert [%{"id" => ^reblog_id}] =
783 |> get("/api/v1/timelines/home")
784 |> json_response(200)
787 test "following with reblogs" do
788 %{conn: conn} = oauth_access(["follow", "read:statuses"])
789 followed = insert(:user)
790 other_user = insert(:user)
792 ret_conn = post(conn, "/api/v1/accounts/#{followed.id}/follow")
794 assert %{"showing_reblogs" => true} = json_response_and_validate_schema(ret_conn, 200)
796 {:ok, activity} = CommonAPI.post(other_user, %{status: "hey"})
797 {:ok, %{id: reblog_id}} = CommonAPI.repeat(activity.id, followed)
799 assert [%{"id" => ^reblog_id}] =
801 |> get("/api/v1/timelines/home")
802 |> json_response(200)
804 assert %{"showing_reblogs" => false} =
806 |> put_req_header("content-type", "application/json")
807 |> post("/api/v1/accounts/#{followed.id}/follow", %{reblogs: false})
808 |> json_response_and_validate_schema(200)
812 |> get("/api/v1/timelines/home")
813 |> json_response(200)
816 test "following / unfollowing errors", %{user: user, conn: conn} do
818 conn_res = post(conn, "/api/v1/accounts/#{user.id}/follow")
820 assert %{"error" => "Can not follow yourself"} =
821 json_response_and_validate_schema(conn_res, 400)
824 user = User.get_cached_by_id(user.id)
825 conn_res = post(conn, "/api/v1/accounts/#{user.id}/unfollow")
827 assert %{"error" => "Can not unfollow yourself"} =
828 json_response_and_validate_schema(conn_res, 400)
830 # self follow via uri
831 user = User.get_cached_by_id(user.id)
833 assert %{"error" => "Can not follow yourself"} =
835 |> put_req_header("content-type", "multipart/form-data")
836 |> post("/api/v1/follows", %{"uri" => user.nickname})
837 |> json_response_and_validate_schema(400)
839 # follow non existing user
840 conn_res = post(conn, "/api/v1/accounts/doesntexist/follow")
841 assert %{"error" => "Record not found"} = json_response_and_validate_schema(conn_res, 404)
843 # follow non existing user via uri
846 |> put_req_header("content-type", "multipart/form-data")
847 |> post("/api/v1/follows", %{"uri" => "doesntexist"})
849 assert %{"error" => "Record not found"} = json_response_and_validate_schema(conn_res, 404)
851 # unfollow non existing user
852 conn_res = post(conn, "/api/v1/accounts/doesntexist/unfollow")
853 assert %{"error" => "Record not found"} = json_response_and_validate_schema(conn_res, 404)
857 describe "mute/unmute" do
858 setup do: oauth_access(["write:mutes"])
860 test "with notifications", %{conn: conn} do
861 other_user = insert(:user)
863 assert %{"id" => _id, "muting" => true, "muting_notifications" => true} =
865 |> post("/api/v1/accounts/#{other_user.id}/mute")
866 |> json_response_and_validate_schema(200)
868 conn = post(conn, "/api/v1/accounts/#{other_user.id}/unmute")
870 assert %{"id" => _id, "muting" => false, "muting_notifications" => false} =
871 json_response_and_validate_schema(conn, 200)
874 test "without notifications", %{conn: conn} do
875 other_user = insert(:user)
879 |> put_req_header("content-type", "multipart/form-data")
880 |> post("/api/v1/accounts/#{other_user.id}/mute", %{"notifications" => "false"})
882 assert %{"id" => _id, "muting" => true, "muting_notifications" => false} =
883 json_response_and_validate_schema(ret_conn, 200)
885 conn = post(conn, "/api/v1/accounts/#{other_user.id}/unmute")
887 assert %{"id" => _id, "muting" => false, "muting_notifications" => false} =
888 json_response_and_validate_schema(conn, 200)
892 describe "pinned statuses" do
895 {:ok, activity} = CommonAPI.post(user, %{status: "HI!!!"})
896 %{conn: conn} = oauth_access(["read:statuses"], user: user)
898 [conn: conn, user: user, activity: activity]
901 test "returns pinned statuses", %{conn: conn, user: user, activity: %{id: activity_id}} do
902 {:ok, _} = CommonAPI.pin(activity_id, user)
904 assert [%{"id" => ^activity_id, "pinned" => true}] =
906 |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
907 |> json_response_and_validate_schema(200)
911 test "blocking / unblocking a user" do
912 %{conn: conn} = oauth_access(["follow"])
913 other_user = insert(:user)
915 ret_conn = post(conn, "/api/v1/accounts/#{other_user.id}/block")
917 assert %{"id" => _id, "blocking" => true} = json_response_and_validate_schema(ret_conn, 200)
919 conn = post(conn, "/api/v1/accounts/#{other_user.id}/unblock")
921 assert %{"id" => _id, "blocking" => false} = json_response_and_validate_schema(conn, 200)
924 describe "create account by app" do
928 email: "lain@example.org",
929 password: "PlzDontHackLain",
933 [valid_params: valid_params]
936 test "registers and logs in without :account_activation_required / :account_approval_required",
938 clear_config([:instance, :account_activation_required], false)
939 clear_config([:instance, :account_approval_required], false)
943 |> put_req_header("content-type", "application/json")
944 |> post("/api/v1/apps", %{
945 client_name: "client_name",
946 redirect_uris: "urn:ietf:wg:oauth:2.0:oob",
947 scopes: "read, write, follow"
951 "client_id" => client_id,
952 "client_secret" => client_secret,
954 "name" => "client_name",
955 "redirect_uri" => "urn:ietf:wg:oauth:2.0:oob",
958 } = json_response_and_validate_schema(conn, 200)
961 post(conn, "/oauth/token", %{
962 grant_type: "client_credentials",
963 client_id: client_id,
964 client_secret: client_secret
967 assert %{"access_token" => token, "refresh_token" => refresh, "scope" => scope} =
968 json_response(conn, 200)
971 token_from_db = Repo.get_by(Token, token: token)
974 assert scope == "read write follow"
976 clear_config([User, :email_blacklist], ["example.org"])
980 email: "lain@example.org",
981 password: "PlzDontHackLain",
988 |> put_req_header("content-type", "multipart/form-data")
989 |> put_req_header("authorization", "Bearer " <> token)
990 |> post("/api/v1/accounts", params)
992 assert %{"error" => "{\"email\":[\"Invalid email\"]}"} =
993 json_response_and_validate_schema(conn, 400)
995 Pleroma.Config.put([User, :email_blacklist], [])
999 |> put_req_header("content-type", "multipart/form-data")
1000 |> put_req_header("authorization", "Bearer " <> token)
1001 |> post("/api/v1/accounts", params)
1004 "access_token" => token,
1005 "created_at" => _created_at,
1007 "token_type" => "Bearer"
1008 } = json_response_and_validate_schema(conn, 200)
1010 token_from_db = Repo.get_by(Token, token: token)
1011 assert token_from_db
1012 user = Repo.preload(token_from_db, :user).user
1015 refute user.confirmation_pending
1016 refute user.approval_pending
1019 test "registers but does not log in with :account_activation_required", %{conn: conn} do
1020 clear_config([:instance, :account_activation_required], true)
1021 clear_config([:instance, :account_approval_required], false)
1025 |> put_req_header("content-type", "application/json")
1026 |> post("/api/v1/apps", %{
1027 client_name: "client_name",
1028 redirect_uris: "urn:ietf:wg:oauth:2.0:oob",
1029 scopes: "read, write, follow"
1033 "client_id" => client_id,
1034 "client_secret" => client_secret,
1036 "name" => "client_name",
1037 "redirect_uri" => "urn:ietf:wg:oauth:2.0:oob",
1040 } = json_response_and_validate_schema(conn, 200)
1043 post(conn, "/oauth/token", %{
1044 grant_type: "client_credentials",
1045 client_id: client_id,
1046 client_secret: client_secret
1049 assert %{"access_token" => token, "refresh_token" => refresh, "scope" => scope} =
1050 json_response(conn, 200)
1053 token_from_db = Repo.get_by(Token, token: token)
1054 assert token_from_db
1056 assert scope == "read write follow"
1060 |> put_req_header("content-type", "multipart/form-data")
1061 |> put_req_header("authorization", "Bearer " <> token)
1062 |> post("/api/v1/accounts", %{
1064 email: "lain@example.org",
1065 password: "PlzDontHackLain",
1070 response = json_response_and_validate_schema(conn, 200)
1071 assert %{"identifier" => "missing_confirmed_email"} = response
1072 refute response["access_token"]
1073 refute response["token_type"]
1075 user = Repo.get_by(User, email: "lain@example.org")
1076 assert user.confirmation_pending
1079 test "registers but does not log in with :account_approval_required", %{conn: conn} do
1080 clear_config([:instance, :account_approval_required], true)
1081 clear_config([:instance, :account_activation_required], false)
1085 |> put_req_header("content-type", "application/json")
1086 |> post("/api/v1/apps", %{
1087 client_name: "client_name",
1088 redirect_uris: "urn:ietf:wg:oauth:2.0:oob",
1089 scopes: "read, write, follow"
1093 "client_id" => client_id,
1094 "client_secret" => client_secret,
1096 "name" => "client_name",
1097 "redirect_uri" => "urn:ietf:wg:oauth:2.0:oob",
1100 } = json_response_and_validate_schema(conn, 200)
1103 post(conn, "/oauth/token", %{
1104 grant_type: "client_credentials",
1105 client_id: client_id,
1106 client_secret: client_secret
1109 assert %{"access_token" => token, "refresh_token" => refresh, "scope" => scope} =
1110 json_response(conn, 200)
1113 token_from_db = Repo.get_by(Token, token: token)
1114 assert token_from_db
1116 assert scope == "read write follow"
1120 |> put_req_header("content-type", "multipart/form-data")
1121 |> put_req_header("authorization", "Bearer " <> token)
1122 |> post("/api/v1/accounts", %{
1124 email: "lain@example.org",
1125 password: "PlzDontHackLain",
1128 reason: "I'm a cool dude, bro"
1131 response = json_response_and_validate_schema(conn, 200)
1132 assert %{"identifier" => "awaiting_approval"} = response
1133 refute response["access_token"]
1134 refute response["token_type"]
1136 user = Repo.get_by(User, email: "lain@example.org")
1138 assert user.approval_pending
1139 assert user.registration_reason == "I'm a cool dude, bro"
1142 test "returns error when user already registred", %{conn: conn, valid_params: valid_params} do
1143 _user = insert(:user, email: "lain@example.org")
1144 app_token = insert(:oauth_token, user: nil)
1148 |> put_req_header("authorization", "Bearer " <> app_token.token)
1149 |> put_req_header("content-type", "application/json")
1150 |> post("/api/v1/accounts", valid_params)
1152 assert json_response_and_validate_schema(res, 400) == %{
1153 "error" => "{\"email\":[\"has already been taken\"]}"
1157 test "returns bad_request if missing required params", %{
1159 valid_params: valid_params
1161 app_token = insert(:oauth_token, user: nil)
1165 |> put_req_header("authorization", "Bearer " <> app_token.token)
1166 |> put_req_header("content-type", "application/json")
1168 res = post(conn, "/api/v1/accounts", valid_params)
1169 assert json_response_and_validate_schema(res, 200)
1171 [{127, 0, 0, 1}, {127, 0, 0, 2}, {127, 0, 0, 3}, {127, 0, 0, 4}]
1172 |> Stream.zip(Map.delete(valid_params, :email))
1173 |> Enum.each(fn {ip, {attr, _}} ->
1176 |> Map.put(:remote_ip, ip)
1177 |> post("/api/v1/accounts", Map.delete(valid_params, attr))
1178 |> json_response_and_validate_schema(400)
1181 "error" => "Missing field: #{attr}.",
1184 "message" => "Missing field: #{attr}",
1185 "source" => %{"pointer" => "/#{attr}"},
1186 "title" => "Invalid value"
1193 test "returns bad_request if missing email params when :account_activation_required is enabled",
1194 %{conn: conn, valid_params: valid_params} do
1195 clear_config([:instance, :account_activation_required], true)
1197 app_token = insert(:oauth_token, user: nil)
1201 |> put_req_header("authorization", "Bearer " <> app_token.token)
1202 |> put_req_header("content-type", "application/json")
1206 |> Map.put(:remote_ip, {127, 0, 0, 5})
1207 |> post("/api/v1/accounts", Map.delete(valid_params, :email))
1209 assert json_response_and_validate_schema(res, 400) ==
1210 %{"error" => "Missing parameter: email"}
1214 |> Map.put(:remote_ip, {127, 0, 0, 6})
1215 |> post("/api/v1/accounts", Map.put(valid_params, :email, ""))
1217 assert json_response_and_validate_schema(res, 400) == %{
1218 "error" => "{\"email\":[\"can't be blank\"]}"
1222 test "allow registration without an email", %{conn: conn, valid_params: valid_params} do
1223 app_token = insert(:oauth_token, user: nil)
1224 conn = put_req_header(conn, "authorization", "Bearer " <> app_token.token)
1228 |> put_req_header("content-type", "application/json")
1229 |> Map.put(:remote_ip, {127, 0, 0, 7})
1230 |> post("/api/v1/accounts", Map.delete(valid_params, :email))
1232 assert json_response_and_validate_schema(res, 200)
1235 test "allow registration with an empty email", %{conn: conn, valid_params: valid_params} do
1236 app_token = insert(:oauth_token, user: nil)
1237 conn = put_req_header(conn, "authorization", "Bearer " <> app_token.token)
1241 |> put_req_header("content-type", "application/json")
1242 |> Map.put(:remote_ip, {127, 0, 0, 8})
1243 |> post("/api/v1/accounts", Map.put(valid_params, :email, ""))
1245 assert json_response_and_validate_schema(res, 200)
1248 test "returns forbidden if token is invalid", %{conn: conn, valid_params: valid_params} do
1251 |> put_req_header("authorization", "Bearer " <> "invalid-token")
1252 |> put_req_header("content-type", "multipart/form-data")
1253 |> post("/api/v1/accounts", valid_params)
1255 assert json_response_and_validate_schema(res, 403) == %{"error" => "Invalid credentials"}
1258 test "registration from trusted app" do
1259 clear_config([Pleroma.Captcha, :enabled], true)
1260 app = insert(:oauth_app, trusted: true, scopes: ["read", "write", "follow", "push"])
1264 |> post("/oauth/token", %{
1265 "grant_type" => "client_credentials",
1266 "client_id" => app.client_id,
1267 "client_secret" => app.client_secret
1270 assert %{"access_token" => token, "token_type" => "Bearer"} = json_response(conn, 200)
1274 |> Plug.Conn.put_req_header("authorization", "Bearer " <> token)
1275 |> put_req_header("content-type", "multipart/form-data")
1276 |> post("/api/v1/accounts", %{
1277 nickname: "nickanme",
1279 email: "email@example.com",
1282 password: "some_password",
1283 confirm: "some_password"
1285 |> json_response_and_validate_schema(200)
1288 "access_token" => access_token,
1290 "scope" => "read write follow push",
1291 "token_type" => "Bearer"
1296 |> Plug.Conn.put_req_header("authorization", "Bearer " <> access_token)
1297 |> get("/api/v1/accounts/verify_credentials")
1298 |> json_response_and_validate_schema(200)
1303 "display_name" => "Lain",
1304 "follow_requests_count" => 0,
1305 "followers_count" => 0,
1306 "following_count" => 0,
1313 "actor_type" => "Person",
1314 "discoverable" => false,
1315 "no_rich_text" => false,
1318 "privacy" => "public",
1319 "sensitive" => false
1321 "statuses_count" => 0,
1322 "username" => "Lain"
1327 describe "create account by app / rate limit" do
1328 setup do: clear_config([:rate_limit, :app_account_creation], {10_000, 2})
1330 test "respects rate limit setting", %{conn: conn} do
1331 app_token = insert(:oauth_token, user: nil)
1335 |> put_req_header("authorization", "Bearer " <> app_token.token)
1336 |> Map.put(:remote_ip, {15, 15, 15, 15})
1337 |> put_req_header("content-type", "multipart/form-data")
1342 |> post("/api/v1/accounts", %{
1343 username: "#{i}lain",
1344 email: "#{i}lain@example.org",
1345 password: "PlzDontHackLain",
1350 "access_token" => token,
1351 "created_at" => _created_at,
1353 "token_type" => "Bearer"
1354 } = json_response_and_validate_schema(conn, 200)
1356 token_from_db = Repo.get_by(Token, token: token)
1357 assert token_from_db
1358 token_from_db = Repo.preload(token_from_db, :user)
1359 assert token_from_db.user
1363 post(conn, "/api/v1/accounts", %{
1365 email: "6lain@example.org",
1366 password: "PlzDontHackLain",
1370 assert json_response_and_validate_schema(conn, :too_many_requests) == %{
1371 "error" => "Throttled"
1376 describe "create account with enabled captcha" do
1377 setup %{conn: conn} do
1378 app_token = insert(:oauth_token, user: nil)
1382 |> put_req_header("authorization", "Bearer " <> app_token.token)
1383 |> put_req_header("content-type", "multipart/form-data")
1388 setup do: clear_config([Pleroma.Captcha, :enabled], true)
1390 test "creates an account and returns 200 if captcha is valid", %{conn: conn} do
1391 %{token: token, answer_data: answer_data} = Pleroma.Captcha.new()
1395 email: "lain@example.org",
1396 password: "PlzDontHackLain",
1398 captcha_solution: Pleroma.Captcha.Mock.solution(),
1399 captcha_token: token,
1400 captcha_answer_data: answer_data
1404 "access_token" => access_token,
1407 "token_type" => "Bearer"
1410 |> post("/api/v1/accounts", params)
1411 |> json_response_and_validate_schema(:ok)
1413 assert Token |> Repo.get_by(token: access_token) |> Repo.preload(:user) |> Map.get(:user)
1416 test "returns 400 if any captcha field is not provided", %{conn: conn} do
1417 captcha_fields = [:captcha_solution, :captcha_token, :captcha_answer_data]
1421 email: "lain@example.org",
1422 password: "PlzDontHackLain",
1424 captcha_solution: "xx",
1425 captcha_token: "xx",
1426 captcha_answer_data: "xx"
1429 for field <- captcha_fields do
1431 "error" => "{\"captcha\":[\"Invalid CAPTCHA (Missing parameter: #{field})\"]}"
1436 |> post("/api/v1/accounts", Map.delete(valid_params, field))
1437 |> json_response_and_validate_schema(:bad_request)
1441 test "returns an error if captcha is invalid", %{conn: conn} do
1444 email: "lain@example.org",
1445 password: "PlzDontHackLain",
1447 captcha_solution: "cofe",
1448 captcha_token: "cofe",
1449 captcha_answer_data: "cofe"
1452 assert %{"error" => "{\"captcha\":[\"Invalid answer data\"]}"} ==
1454 |> post("/api/v1/accounts", params)
1455 |> json_response_and_validate_schema(:bad_request)
1459 describe "GET /api/v1/accounts/:id/lists - account_lists" do
1460 test "returns lists to which the account belongs" do
1461 %{user: user, conn: conn} = oauth_access(["read:lists"])
1462 other_user = insert(:user)
1463 assert {:ok, %Pleroma.List{id: _list_id} = list} = Pleroma.List.create("Test List", user)
1464 {:ok, %{following: _following}} = Pleroma.List.follow(list, other_user)
1466 assert [%{"id" => _list_id, "title" => "Test List"}] =
1468 |> get("/api/v1/accounts/#{other_user.id}/lists")
1469 |> json_response_and_validate_schema(200)
1473 describe "verify_credentials" do
1474 test "verify_credentials" do
1475 %{user: user, conn: conn} = oauth_access(["read:accounts"])
1477 [notification | _] =
1478 insert_list(7, :notification, user: user, activity: insert(:note_activity))
1480 Pleroma.Notification.set_read_up_to(user, notification.id)
1481 conn = get(conn, "/api/v1/accounts/verify_credentials")
1483 response = json_response_and_validate_schema(conn, 200)
1485 assert %{"id" => id, "source" => %{"privacy" => "public"}} = response
1486 assert response["pleroma"]["chat_token"]
1487 assert response["pleroma"]["unread_notifications_count"] == 6
1488 assert id == to_string(user.id)
1491 test "verify_credentials default scope unlisted" do
1492 user = insert(:user, default_scope: "unlisted")
1493 %{conn: conn} = oauth_access(["read:accounts"], user: user)
1495 conn = get(conn, "/api/v1/accounts/verify_credentials")
1497 assert %{"id" => id, "source" => %{"privacy" => "unlisted"}} =
1498 json_response_and_validate_schema(conn, 200)
1500 assert id == to_string(user.id)
1503 test "locked accounts" do
1504 user = insert(:user, default_scope: "private")
1505 %{conn: conn} = oauth_access(["read:accounts"], user: user)
1507 conn = get(conn, "/api/v1/accounts/verify_credentials")
1509 assert %{"id" => id, "source" => %{"privacy" => "private"}} =
1510 json_response_and_validate_schema(conn, 200)
1512 assert id == to_string(user.id)
1516 describe "user relationships" do
1517 setup do: oauth_access(["read:follows"])
1519 test "returns the relationships for the current user", %{user: user, conn: conn} do
1520 %{id: other_user_id} = other_user = insert(:user)
1521 {:ok, _user, _other_user} = User.follow(user, other_user)
1523 assert [%{"id" => ^other_user_id}] =
1525 |> get("/api/v1/accounts/relationships?id=#{other_user.id}")
1526 |> json_response_and_validate_schema(200)
1528 assert [%{"id" => ^other_user_id}] =
1530 |> get("/api/v1/accounts/relationships?id[]=#{other_user.id}")
1531 |> json_response_and_validate_schema(200)
1534 test "returns an empty list on a bad request", %{conn: conn} do
1535 conn = get(conn, "/api/v1/accounts/relationships", %{})
1537 assert [] = json_response_and_validate_schema(conn, 200)
1541 test "getting a list of mutes" do
1542 %{user: user, conn: conn} = oauth_access(["read:mutes"])
1543 %{id: id1} = other_user1 = insert(:user)
1544 %{id: id2} = other_user2 = insert(:user)
1545 %{id: id3} = other_user3 = insert(:user)
1547 {:ok, _user_relationships} = User.mute(user, other_user1)
1548 {:ok, _user_relationships} = User.mute(user, other_user2)
1549 {:ok, _user_relationships} = User.mute(user, other_user3)
1553 |> assign(:user, user)
1554 |> get("/api/v1/mutes")
1555 |> json_response_and_validate_schema(200)
1557 assert [id1, id2, id3] == Enum.map(result, & &1["id"])
1561 |> assign(:user, user)
1562 |> get("/api/v1/mutes?limit=1")
1563 |> json_response_and_validate_schema(200)
1565 assert [%{"id" => ^id1}] = result
1569 |> assign(:user, user)
1570 |> get("/api/v1/mutes?since_id=#{id1}")
1571 |> json_response_and_validate_schema(200)
1573 assert [%{"id" => ^id2}, %{"id" => ^id3}] = result
1577 |> assign(:user, user)
1578 |> get("/api/v1/mutes?since_id=#{id1}&max_id=#{id3}")
1579 |> json_response_and_validate_schema(200)
1581 assert [%{"id" => ^id2}] = result
1585 |> assign(:user, user)
1586 |> get("/api/v1/mutes?since_id=#{id1}&limit=1")
1587 |> json_response_and_validate_schema(200)
1589 assert [%{"id" => ^id2}] = result
1592 test "getting a list of blocks" do
1593 %{user: user, conn: conn} = oauth_access(["read:blocks"])
1594 %{id: id1} = other_user1 = insert(:user)
1595 %{id: id2} = other_user2 = insert(:user)
1596 %{id: id3} = other_user3 = insert(:user)
1598 {:ok, _user_relationship} = User.block(user, other_user1)
1599 {:ok, _user_relationship} = User.block(user, other_user3)
1600 {:ok, _user_relationship} = User.block(user, other_user2)
1604 |> assign(:user, user)
1605 |> get("/api/v1/blocks")
1606 |> json_response_and_validate_schema(200)
1608 assert [id1, id2, id3] == Enum.map(result, & &1["id"])
1612 |> assign(:user, user)
1613 |> get("/api/v1/blocks?limit=1")
1614 |> json_response_and_validate_schema(200)
1616 assert [%{"id" => ^id1}] = result
1620 |> assign(:user, user)
1621 |> get("/api/v1/blocks?since_id=#{id1}")
1622 |> json_response_and_validate_schema(200)
1624 assert [%{"id" => ^id2}, %{"id" => ^id3}] = result
1628 |> assign(:user, user)
1629 |> get("/api/v1/blocks?since_id=#{id1}&max_id=#{id3}")
1630 |> json_response_and_validate_schema(200)
1632 assert [%{"id" => ^id2}] = result
1636 |> assign(:user, user)
1637 |> get("/api/v1/blocks?since_id=#{id1}&limit=1")
1638 |> json_response_and_validate_schema(200)
1640 assert [%{"id" => ^id2}] = result