1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MastodonAPI.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
23 |> get("/api/v1/accounts/#{user.id}")
25 assert %{"id" => id} = json_response(conn, 200)
26 assert id == to_string(user.id)
30 |> get("/api/v1/accounts/-1")
32 assert %{"error" => "Can't find user"} = json_response(conn, 404)
35 test "works by nickname" do
40 |> get("/api/v1/accounts/#{user.nickname}")
42 assert %{"id" => id} = json_response(conn, 200)
46 test "works by nickname for remote users" do
47 limit_to_local = Pleroma.Config.get([:instance, :limit_to_local_content])
48 Pleroma.Config.put([:instance, :limit_to_local_content], false)
49 user = insert(:user, nickname: "user@example.com", local: false)
53 |> get("/api/v1/accounts/#{user.nickname}")
55 Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local)
56 assert %{"id" => id} = json_response(conn, 200)
60 test "respects limit_to_local_content == :all for remote user nicknames" do
61 limit_to_local = Pleroma.Config.get([:instance, :limit_to_local_content])
62 Pleroma.Config.put([:instance, :limit_to_local_content], :all)
64 user = insert(:user, nickname: "user@example.com", local: false)
68 |> get("/api/v1/accounts/#{user.nickname}")
70 Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local)
71 assert json_response(conn, 404)
74 test "respects limit_to_local_content == :unauthenticated for remote user nicknames" do
75 limit_to_local = Pleroma.Config.get([:instance, :limit_to_local_content])
76 Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
78 user = insert(:user, nickname: "user@example.com", local: false)
79 reading_user = insert(:user)
83 |> get("/api/v1/accounts/#{user.nickname}")
85 assert json_response(conn, 404)
89 |> assign(:user, reading_user)
90 |> get("/api/v1/accounts/#{user.nickname}")
92 Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local)
93 assert %{"id" => id} = json_response(conn, 200)
97 test "accounts fetches correct account for nicknames beginning with numbers", %{conn: conn} do
98 # Need to set an old-style integer ID to reproduce the problem
99 # (these are no longer assigned to new accounts but were preserved
100 # for existing accounts during the migration to flakeIDs)
101 user_one = insert(:user, %{id: 1212})
102 user_two = insert(:user, %{nickname: "#{user_one.id}garbage"})
106 |> get("/api/v1/accounts/#{user_one.id}")
110 |> get("/api/v1/accounts/#{user_two.nickname}")
114 |> get("/api/v1/accounts/#{user_two.id}")
116 acc_one = json_response(resp_one, 200)
117 acc_two = json_response(resp_two, 200)
118 acc_three = json_response(resp_three, 200)
119 refute acc_one == acc_two
120 assert acc_two == acc_three
123 test "returns 404 when user is invisible", %{conn: conn} do
124 user = insert(:user, %{invisible: true})
128 |> get("/api/v1/accounts/#{user.nickname}")
129 |> json_response(404)
131 assert %{"error" => "Can't find user"} = resp
134 test "returns 404 for internal.fetch actor", %{conn: conn} do
135 %User{nickname: "internal.fetch"} = InternalFetchActor.get_actor()
139 |> get("/api/v1/accounts/internal.fetch")
140 |> json_response(404)
142 assert %{"error" => "Can't find user"} = resp
146 describe "user timelines" do
147 test "respects blocks", %{conn: conn} do
148 user_one = insert(:user)
149 user_two = insert(:user)
150 user_three = insert(:user)
152 User.block(user_one, user_two)
154 {:ok, activity} = CommonAPI.post(user_two, %{"status" => "User one sux0rz"})
155 {:ok, repeat, _} = CommonAPI.repeat(activity.id, user_three)
159 |> get("/api/v1/accounts/#{user_two.id}/statuses")
161 assert [%{"id" => id}] = json_response(resp, 200)
162 assert id == activity.id
164 # Even a blocked user will deliver the full user timeline, there would be
165 # no point in looking at a blocked users timeline otherwise
168 |> assign(:user, user_one)
169 |> get("/api/v1/accounts/#{user_two.id}/statuses")
171 assert [%{"id" => id}] = json_response(resp, 200)
172 assert id == activity.id
176 |> get("/api/v1/accounts/#{user_three.id}/statuses")
178 assert [%{"id" => id}] = json_response(resp, 200)
179 assert id == repeat.id
181 # When viewing a third user's timeline, the blocked users will NOT be
185 |> assign(:user, user_one)
186 |> get("/api/v1/accounts/#{user_three.id}/statuses")
188 assert [] = json_response(resp, 200)
191 test "gets a users statuses", %{conn: conn} do
192 user_one = insert(:user)
193 user_two = insert(:user)
194 user_three = insert(:user)
196 {:ok, user_three} = User.follow(user_three, user_one)
198 {:ok, activity} = CommonAPI.post(user_one, %{"status" => "HI!!!"})
200 {:ok, direct_activity} =
201 CommonAPI.post(user_one, %{
202 "status" => "Hi, @#{user_two.nickname}.",
203 "visibility" => "direct"
206 {:ok, private_activity} =
207 CommonAPI.post(user_one, %{"status" => "private", "visibility" => "private"})
211 |> get("/api/v1/accounts/#{user_one.id}/statuses")
213 assert [%{"id" => id}] = json_response(resp, 200)
214 assert id == to_string(activity.id)
218 |> assign(:user, user_two)
219 |> get("/api/v1/accounts/#{user_one.id}/statuses")
221 assert [%{"id" => id_one}, %{"id" => id_two}] = json_response(resp, 200)
222 assert id_one == to_string(direct_activity.id)
223 assert id_two == to_string(activity.id)
227 |> assign(:user, user_three)
228 |> get("/api/v1/accounts/#{user_one.id}/statuses")
230 assert [%{"id" => id_one}, %{"id" => id_two}] = json_response(resp, 200)
231 assert id_one == to_string(private_activity.id)
232 assert id_two == to_string(activity.id)
235 test "unimplemented pinned statuses feature", %{conn: conn} do
236 note = insert(:note_activity)
237 user = User.get_cached_by_ap_id(note.data["actor"])
241 |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
243 assert json_response(conn, 200) == []
246 test "gets an users media", %{conn: conn} do
247 note = insert(:note_activity)
248 user = User.get_cached_by_ap_id(note.data["actor"])
251 content_type: "image/jpg",
252 path: Path.absname("test/fixtures/image.jpg"),
253 filename: "an_image.jpg"
256 {:ok, %{id: media_id}} = ActivityPub.upload(file, actor: user.ap_id)
258 {:ok, image_post} = CommonAPI.post(user, %{"status" => "cofe", "media_ids" => [media_id]})
262 |> get("/api/v1/accounts/#{user.id}/statuses", %{"only_media" => "true"})
264 assert [%{"id" => id}] = json_response(conn, 200)
265 assert id == to_string(image_post.id)
269 |> get("/api/v1/accounts/#{user.id}/statuses", %{"only_media" => "1"})
271 assert [%{"id" => id}] = json_response(conn, 200)
272 assert id == to_string(image_post.id)
275 test "gets a user's statuses without reblogs", %{conn: conn} do
277 {:ok, post} = CommonAPI.post(user, %{"status" => "HI!!!"})
278 {:ok, _, _} = CommonAPI.repeat(post.id, user)
282 |> get("/api/v1/accounts/#{user.id}/statuses", %{"exclude_reblogs" => "true"})
284 assert [%{"id" => id}] = json_response(conn, 200)
285 assert id == to_string(post.id)
289 |> get("/api/v1/accounts/#{user.id}/statuses", %{"exclude_reblogs" => "1"})
291 assert [%{"id" => id}] = json_response(conn, 200)
292 assert id == to_string(post.id)
295 test "filters user's statuses by a hashtag", %{conn: conn} do
297 {:ok, post} = CommonAPI.post(user, %{"status" => "#hashtag"})
298 {:ok, _post} = CommonAPI.post(user, %{"status" => "hashtag"})
302 |> get("/api/v1/accounts/#{user.id}/statuses", %{"tagged" => "hashtag"})
304 assert [%{"id" => id}] = json_response(conn, 200)
305 assert id == to_string(post.id)
308 test "the user views their own timelines and excludes direct messages", %{conn: conn} do
310 {:ok, public_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "public"})
311 {:ok, _direct_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
315 |> assign(:user, user)
316 |> get("/api/v1/accounts/#{user.id}/statuses", %{"exclude_visibilities" => ["direct"]})
318 assert [%{"id" => id}] = json_response(conn, 200)
319 assert id == to_string(public_activity.id)
323 describe "followers" do
324 test "getting followers", %{conn: conn} do
326 other_user = insert(:user)
327 {:ok, user} = User.follow(user, other_user)
331 |> get("/api/v1/accounts/#{other_user.id}/followers")
333 assert [%{"id" => id}] = json_response(conn, 200)
334 assert id == to_string(user.id)
337 test "getting followers, hide_followers", %{conn: conn} do
339 other_user = insert(:user, hide_followers: true)
340 {:ok, _user} = User.follow(user, other_user)
344 |> get("/api/v1/accounts/#{other_user.id}/followers")
346 assert [] == json_response(conn, 200)
349 test "getting followers, hide_followers, same user requesting", %{conn: conn} do
351 other_user = insert(:user, hide_followers: true)
352 {:ok, _user} = User.follow(user, other_user)
356 |> assign(:user, other_user)
357 |> get("/api/v1/accounts/#{other_user.id}/followers")
359 refute [] == json_response(conn, 200)
362 test "getting followers, pagination", %{conn: conn} do
364 follower1 = insert(:user)
365 follower2 = insert(:user)
366 follower3 = insert(:user)
367 {:ok, _} = User.follow(follower1, user)
368 {:ok, _} = User.follow(follower2, user)
369 {:ok, _} = User.follow(follower3, user)
373 |> assign(:user, user)
377 |> get("/api/v1/accounts/#{user.id}/followers?since_id=#{follower1.id}")
379 assert [%{"id" => id3}, %{"id" => id2}] = json_response(res_conn, 200)
380 assert id3 == follower3.id
381 assert id2 == follower2.id
385 |> get("/api/v1/accounts/#{user.id}/followers?max_id=#{follower3.id}")
387 assert [%{"id" => id2}, %{"id" => id1}] = json_response(res_conn, 200)
388 assert id2 == follower2.id
389 assert id1 == follower1.id
393 |> get("/api/v1/accounts/#{user.id}/followers?limit=1&max_id=#{follower3.id}")
395 assert [%{"id" => id2}] = json_response(res_conn, 200)
396 assert id2 == follower2.id
398 assert [link_header] = get_resp_header(res_conn, "link")
399 assert link_header =~ ~r/min_id=#{follower2.id}/
400 assert link_header =~ ~r/max_id=#{follower2.id}/
404 describe "following" do
405 test "getting following", %{conn: conn} do
407 other_user = insert(:user)
408 {:ok, user} = User.follow(user, other_user)
412 |> get("/api/v1/accounts/#{user.id}/following")
414 assert [%{"id" => id}] = json_response(conn, 200)
415 assert id == to_string(other_user.id)
418 test "getting following, hide_follows", %{conn: conn} do
419 user = insert(:user, hide_follows: true)
420 other_user = insert(:user)
421 {:ok, user} = User.follow(user, other_user)
425 |> get("/api/v1/accounts/#{user.id}/following")
427 assert [] == json_response(conn, 200)
430 test "getting following, hide_follows, same user requesting", %{conn: conn} do
431 user = insert(:user, hide_follows: true)
432 other_user = insert(:user)
433 {:ok, user} = User.follow(user, other_user)
437 |> assign(:user, user)
438 |> get("/api/v1/accounts/#{user.id}/following")
440 refute [] == json_response(conn, 200)
443 test "getting following, pagination", %{conn: conn} do
445 following1 = insert(:user)
446 following2 = insert(:user)
447 following3 = insert(:user)
448 {:ok, _} = User.follow(user, following1)
449 {:ok, _} = User.follow(user, following2)
450 {:ok, _} = User.follow(user, following3)
454 |> assign(:user, user)
458 |> get("/api/v1/accounts/#{user.id}/following?since_id=#{following1.id}")
460 assert [%{"id" => id3}, %{"id" => id2}] = json_response(res_conn, 200)
461 assert id3 == following3.id
462 assert id2 == following2.id
466 |> get("/api/v1/accounts/#{user.id}/following?max_id=#{following3.id}")
468 assert [%{"id" => id2}, %{"id" => id1}] = json_response(res_conn, 200)
469 assert id2 == following2.id
470 assert id1 == following1.id
474 |> get("/api/v1/accounts/#{user.id}/following?limit=1&max_id=#{following3.id}")
476 assert [%{"id" => id2}] = json_response(res_conn, 200)
477 assert id2 == following2.id
479 assert [link_header] = get_resp_header(res_conn, "link")
480 assert link_header =~ ~r/min_id=#{following2.id}/
481 assert link_header =~ ~r/max_id=#{following2.id}/
485 describe "follow/unfollow" do
486 test "following / unfollowing a user", %{conn: conn} do
488 other_user = insert(:user)
492 |> assign(:user, user)
493 |> post("/api/v1/accounts/#{other_user.id}/follow")
495 assert %{"id" => _id, "following" => true} = json_response(conn, 200)
497 user = User.get_cached_by_id(user.id)
501 |> assign(:user, user)
502 |> post("/api/v1/accounts/#{other_user.id}/unfollow")
504 assert %{"id" => _id, "following" => false} = json_response(conn, 200)
506 user = User.get_cached_by_id(user.id)
510 |> assign(:user, user)
511 |> post("/api/v1/follows", %{"uri" => other_user.nickname})
513 assert %{"id" => id} = json_response(conn, 200)
514 assert id == to_string(other_user.id)
517 test "following without reblogs" do
518 follower = insert(:user)
519 followed = insert(:user)
520 other_user = insert(:user)
524 |> assign(:user, follower)
525 |> post("/api/v1/accounts/#{followed.id}/follow?reblogs=false")
527 assert %{"showing_reblogs" => false} = json_response(conn, 200)
529 {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hey"})
530 {:ok, reblog, _} = CommonAPI.repeat(activity.id, followed)
534 |> assign(:user, User.get_cached_by_id(follower.id))
535 |> get("/api/v1/timelines/home")
537 assert [] == json_response(conn, 200)
541 |> assign(:user, User.get_cached_by_id(follower.id))
542 |> post("/api/v1/accounts/#{followed.id}/follow?reblogs=true")
544 assert %{"showing_reblogs" => true} = json_response(conn, 200)
548 |> assign(:user, User.get_cached_by_id(follower.id))
549 |> get("/api/v1/timelines/home")
551 expected_activity_id = reblog.id
552 assert [%{"id" => ^expected_activity_id}] = json_response(conn, 200)
555 test "following / unfollowing errors" do
560 |> assign(:user, user)
563 conn_res = post(conn, "/api/v1/accounts/#{user.id}/follow")
564 assert %{"error" => "Record not found"} = json_response(conn_res, 404)
567 user = User.get_cached_by_id(user.id)
568 conn_res = post(conn, "/api/v1/accounts/#{user.id}/unfollow")
569 assert %{"error" => "Record not found"} = json_response(conn_res, 404)
571 # self follow via uri
572 user = User.get_cached_by_id(user.id)
573 conn_res = post(conn, "/api/v1/follows", %{"uri" => user.nickname})
574 assert %{"error" => "Record not found"} = json_response(conn_res, 404)
576 # follow non existing user
577 conn_res = post(conn, "/api/v1/accounts/doesntexist/follow")
578 assert %{"error" => "Record not found"} = json_response(conn_res, 404)
580 # follow non existing user via uri
581 conn_res = post(conn, "/api/v1/follows", %{"uri" => "doesntexist"})
582 assert %{"error" => "Record not found"} = json_response(conn_res, 404)
584 # unfollow non existing user
585 conn_res = post(conn, "/api/v1/accounts/doesntexist/unfollow")
586 assert %{"error" => "Record not found"} = json_response(conn_res, 404)
590 describe "mute/unmute" do
591 test "with notifications", %{conn: conn} do
593 other_user = insert(:user)
597 |> assign(:user, user)
598 |> post("/api/v1/accounts/#{other_user.id}/mute")
600 response = json_response(conn, 200)
602 assert %{"id" => _id, "muting" => true, "muting_notifications" => true} = response
603 user = User.get_cached_by_id(user.id)
607 |> assign(:user, user)
608 |> post("/api/v1/accounts/#{other_user.id}/unmute")
610 response = json_response(conn, 200)
611 assert %{"id" => _id, "muting" => false, "muting_notifications" => false} = response
614 test "without notifications", %{conn: conn} do
616 other_user = insert(:user)
620 |> assign(:user, user)
621 |> post("/api/v1/accounts/#{other_user.id}/mute", %{"notifications" => "false"})
623 response = json_response(conn, 200)
625 assert %{"id" => _id, "muting" => true, "muting_notifications" => false} = response
626 user = User.get_cached_by_id(user.id)
630 |> assign(:user, user)
631 |> post("/api/v1/accounts/#{other_user.id}/unmute")
633 response = json_response(conn, 200)
634 assert %{"id" => _id, "muting" => false, "muting_notifications" => false} = response
638 describe "pinned statuses" do
641 {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
643 [user: user, activity: activity]
646 test "returns pinned statuses", %{conn: conn, user: user, activity: activity} do
647 {:ok, _} = CommonAPI.pin(activity.id, user)
651 |> assign(:user, user)
652 |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
653 |> json_response(200)
655 id_str = to_string(activity.id)
657 assert [%{"id" => ^id_str, "pinned" => true}] = result
661 test "blocking / unblocking a user", %{conn: conn} do
663 other_user = insert(:user)
667 |> assign(:user, user)
668 |> post("/api/v1/accounts/#{other_user.id}/block")
670 assert %{"id" => _id, "blocking" => true} = json_response(conn, 200)
672 user = User.get_cached_by_id(user.id)
676 |> assign(:user, user)
677 |> post("/api/v1/accounts/#{other_user.id}/unblock")
679 assert %{"id" => _id, "blocking" => false} = json_response(conn, 200)
682 describe "create account by app" do
686 email: "lain@example.org",
687 password: "PlzDontHackLain",
691 [valid_params: valid_params]
694 test "Account registration via Application", %{conn: conn} do
697 |> post("/api/v1/apps", %{
698 client_name: "client_name",
699 redirect_uris: "urn:ietf:wg:oauth:2.0:oob",
700 scopes: "read, write, follow"
704 "client_id" => client_id,
705 "client_secret" => client_secret,
707 "name" => "client_name",
708 "redirect_uri" => "urn:ietf:wg:oauth:2.0:oob",
711 } = json_response(conn, 200)
715 |> post("/oauth/token", %{
716 grant_type: "client_credentials",
717 client_id: client_id,
718 client_secret: client_secret
721 assert %{"access_token" => token, "refresh_token" => refresh, "scope" => scope} =
722 json_response(conn, 200)
725 token_from_db = Repo.get_by(Token, token: token)
728 assert scope == "read write follow"
732 |> put_req_header("authorization", "Bearer " <> token)
733 |> post("/api/v1/accounts", %{
735 email: "lain@example.org",
736 password: "PlzDontHackLain",
742 "access_token" => token,
743 "created_at" => _created_at,
745 "token_type" => "Bearer"
746 } = json_response(conn, 200)
748 token_from_db = Repo.get_by(Token, token: token)
750 token_from_db = Repo.preload(token_from_db, :user)
751 assert token_from_db.user
753 assert token_from_db.user.confirmation_pending
756 test "returns error when user already registred", %{conn: conn, valid_params: valid_params} do
757 _user = insert(:user, email: "lain@example.org")
758 app_token = insert(:oauth_token, user: nil)
762 |> put_req_header("authorization", "Bearer " <> app_token.token)
764 res = post(conn, "/api/v1/accounts", valid_params)
765 assert json_response(res, 400) == %{"error" => "{\"email\":[\"has already been taken\"]}"}
768 test "rate limit", %{conn: conn} do
769 app_token = insert(:oauth_token, user: nil)
772 put_req_header(conn, "authorization", "Bearer " <> app_token.token)
773 |> Map.put(:remote_ip, {15, 15, 15, 15})
778 |> post("/api/v1/accounts", %{
779 username: "#{i}lain",
780 email: "#{i}lain@example.org",
781 password: "PlzDontHackLain",
786 "access_token" => token,
787 "created_at" => _created_at,
789 "token_type" => "Bearer"
790 } = json_response(conn, 200)
792 token_from_db = Repo.get_by(Token, token: token)
794 token_from_db = Repo.preload(token_from_db, :user)
795 assert token_from_db.user
797 assert token_from_db.user.confirmation_pending
802 |> post("/api/v1/accounts", %{
804 email: "6lain@example.org",
805 password: "PlzDontHackLain",
809 assert json_response(conn, :too_many_requests) == %{"error" => "Throttled"}
812 test "returns bad_request if missing required params", %{
814 valid_params: valid_params
816 app_token = insert(:oauth_token, user: nil)
820 |> put_req_header("authorization", "Bearer " <> app_token.token)
822 res = post(conn, "/api/v1/accounts", valid_params)
823 assert json_response(res, 200)
825 [{127, 0, 0, 1}, {127, 0, 0, 2}, {127, 0, 0, 3}, {127, 0, 0, 4}]
826 |> Stream.zip(valid_params)
827 |> Enum.each(fn {ip, {attr, _}} ->
830 |> Map.put(:remote_ip, ip)
831 |> post("/api/v1/accounts", Map.delete(valid_params, attr))
832 |> json_response(400)
834 assert res == %{"error" => "Missing parameters"}
838 test "returns forbidden if token is invalid", %{conn: conn, valid_params: valid_params} do
841 |> put_req_header("authorization", "Bearer " <> "invalid-token")
843 res = post(conn, "/api/v1/accounts", valid_params)
844 assert json_response(res, 403) == %{"error" => "Invalid credentials"}
848 describe "GET /api/v1/accounts/:id/lists - account_lists" do
849 test "returns lists to which the account belongs", %{conn: conn} do
851 other_user = insert(:user)
852 assert {:ok, %Pleroma.List{} = list} = Pleroma.List.create("Test List", user)
853 {:ok, %{following: _following}} = Pleroma.List.follow(list, other_user)
857 |> assign(:user, user)
858 |> get("/api/v1/accounts/#{other_user.id}/lists")
859 |> json_response(200)
861 assert res == [%{"id" => to_string(list.id), "title" => "Test List"}]
865 describe "verify_credentials" do
866 test "verify_credentials", %{conn: conn} do
871 |> assign(:user, user)
872 |> get("/api/v1/accounts/verify_credentials")
874 response = json_response(conn, 200)
876 assert %{"id" => id, "source" => %{"privacy" => "public"}} = response
877 assert response["pleroma"]["chat_token"]
878 assert id == to_string(user.id)
881 test "verify_credentials default scope unlisted", %{conn: conn} do
882 user = insert(:user, default_scope: "unlisted")
886 |> assign(:user, user)
887 |> get("/api/v1/accounts/verify_credentials")
889 assert %{"id" => id, "source" => %{"privacy" => "unlisted"}} = json_response(conn, 200)
890 assert id == to_string(user.id)
893 test "locked accounts", %{conn: conn} do
894 user = insert(:user, default_scope: "private")
898 |> assign(:user, user)
899 |> get("/api/v1/accounts/verify_credentials")
901 assert %{"id" => id, "source" => %{"privacy" => "private"}} = json_response(conn, 200)
902 assert id == to_string(user.id)
906 describe "user relationships" do
907 test "returns the relationships for the current user", %{conn: conn} do
909 other_user = insert(:user)
910 {:ok, user} = User.follow(user, other_user)
914 |> assign(:user, user)
915 |> get("/api/v1/accounts/relationships", %{"id" => [other_user.id]})
917 assert [relationship] = json_response(conn, 200)
919 assert to_string(other_user.id) == relationship["id"]
922 test "returns an empty list on a bad request", %{conn: conn} do
927 |> assign(:user, user)
928 |> get("/api/v1/accounts/relationships", %{})
930 assert [] = json_response(conn, 200)
934 test "getting a list of mutes", %{conn: conn} do
936 other_user = insert(:user)
938 {:ok, _user_relationships} = User.mute(user, other_user)
942 |> assign(:user, user)
943 |> get("/api/v1/mutes")
945 other_user_id = to_string(other_user.id)
946 assert [%{"id" => ^other_user_id}] = json_response(conn, 200)
949 test "getting a list of blocks", %{conn: conn} do
951 other_user = insert(:user)
953 {:ok, _user_relationship} = User.block(user, other_user)
957 |> assign(:user, user)
958 |> get("/api/v1/blocks")
960 other_user_id = to_string(other_user.id)
961 assert [%{"id" => ^other_user_id}] = json_response(conn, 200)