Fix merge
[akkoma] / test / web / mastodon_api / controllers / account_controller_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
6 use Pleroma.Web.ConnCase
7
8 alias Pleroma.User
9 alias Pleroma.Web.ActivityPub.ActivityPub
10 alias Pleroma.Web.CommonAPI
11
12 import Pleroma.Factory
13
14 describe "account fetching" do
15 test "works by id" do
16 user = insert(:user)
17
18 conn =
19 build_conn()
20 |> get("/api/v1/accounts/#{user.id}")
21
22 assert %{"id" => id} = json_response(conn, 200)
23 assert id == to_string(user.id)
24
25 conn =
26 build_conn()
27 |> get("/api/v1/accounts/-1")
28
29 assert %{"error" => "Can't find user"} = json_response(conn, 404)
30 end
31
32 test "works by nickname" do
33 user = insert(:user)
34
35 conn =
36 build_conn()
37 |> get("/api/v1/accounts/#{user.nickname}")
38
39 assert %{"id" => id} = json_response(conn, 200)
40 assert id == user.id
41 end
42
43 test "works by nickname for remote users" do
44 limit_to_local = Pleroma.Config.get([:instance, :limit_to_local_content])
45 Pleroma.Config.put([:instance, :limit_to_local_content], false)
46 user = insert(:user, nickname: "user@example.com", local: false)
47
48 conn =
49 build_conn()
50 |> get("/api/v1/accounts/#{user.nickname}")
51
52 Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local)
53 assert %{"id" => id} = json_response(conn, 200)
54 assert id == user.id
55 end
56
57 test "respects limit_to_local_content == :all for remote user nicknames" do
58 limit_to_local = Pleroma.Config.get([:instance, :limit_to_local_content])
59 Pleroma.Config.put([:instance, :limit_to_local_content], :all)
60
61 user = insert(:user, nickname: "user@example.com", local: false)
62
63 conn =
64 build_conn()
65 |> get("/api/v1/accounts/#{user.nickname}")
66
67 Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local)
68 assert json_response(conn, 404)
69 end
70
71 test "respects limit_to_local_content == :unauthenticated for remote user nicknames" do
72 limit_to_local = Pleroma.Config.get([:instance, :limit_to_local_content])
73 Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
74
75 user = insert(:user, nickname: "user@example.com", local: false)
76 reading_user = insert(:user)
77
78 conn =
79 build_conn()
80 |> get("/api/v1/accounts/#{user.nickname}")
81
82 assert json_response(conn, 404)
83
84 conn =
85 build_conn()
86 |> assign(:user, reading_user)
87 |> get("/api/v1/accounts/#{user.nickname}")
88
89 Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local)
90 assert %{"id" => id} = json_response(conn, 200)
91 assert id == user.id
92 end
93
94 test "accounts fetches correct account for nicknames beginning with numbers", %{conn: conn} do
95 # Need to set an old-style integer ID to reproduce the problem
96 # (these are no longer assigned to new accounts but were preserved
97 # for existing accounts during the migration to flakeIDs)
98 user_one = insert(:user, %{id: 1212})
99 user_two = insert(:user, %{nickname: "#{user_one.id}garbage"})
100
101 resp_one =
102 conn
103 |> get("/api/v1/accounts/#{user_one.id}")
104
105 resp_two =
106 conn
107 |> get("/api/v1/accounts/#{user_two.nickname}")
108
109 resp_three =
110 conn
111 |> get("/api/v1/accounts/#{user_two.id}")
112
113 acc_one = json_response(resp_one, 200)
114 acc_two = json_response(resp_two, 200)
115 acc_three = json_response(resp_three, 200)
116 refute acc_one == acc_two
117 assert acc_two == acc_three
118 end
119 end
120
121 describe "user timelines" do
122 test "gets a users statuses", %{conn: conn} do
123 user_one = insert(:user)
124 user_two = insert(:user)
125 user_three = insert(:user)
126
127 {:ok, user_three} = User.follow(user_three, user_one)
128
129 {:ok, activity} = CommonAPI.post(user_one, %{"status" => "HI!!!"})
130
131 {:ok, direct_activity} =
132 CommonAPI.post(user_one, %{
133 "status" => "Hi, @#{user_two.nickname}.",
134 "visibility" => "direct"
135 })
136
137 {:ok, private_activity} =
138 CommonAPI.post(user_one, %{"status" => "private", "visibility" => "private"})
139
140 resp =
141 conn
142 |> get("/api/v1/accounts/#{user_one.id}/statuses")
143
144 assert [%{"id" => id}] = json_response(resp, 200)
145 assert id == to_string(activity.id)
146
147 resp =
148 conn
149 |> assign(:user, user_two)
150 |> get("/api/v1/accounts/#{user_one.id}/statuses")
151
152 assert [%{"id" => id_one}, %{"id" => id_two}] = json_response(resp, 200)
153 assert id_one == to_string(direct_activity.id)
154 assert id_two == to_string(activity.id)
155
156 resp =
157 conn
158 |> assign(:user, user_three)
159 |> get("/api/v1/accounts/#{user_one.id}/statuses")
160
161 assert [%{"id" => id_one}, %{"id" => id_two}] = json_response(resp, 200)
162 assert id_one == to_string(private_activity.id)
163 assert id_two == to_string(activity.id)
164 end
165
166 test "unimplemented pinned statuses feature", %{conn: conn} do
167 note = insert(:note_activity)
168 user = User.get_cached_by_ap_id(note.data["actor"])
169
170 conn =
171 conn
172 |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
173
174 assert json_response(conn, 200) == []
175 end
176
177 test "gets an users media", %{conn: conn} do
178 note = insert(:note_activity)
179 user = User.get_cached_by_ap_id(note.data["actor"])
180
181 file = %Plug.Upload{
182 content_type: "image/jpg",
183 path: Path.absname("test/fixtures/image.jpg"),
184 filename: "an_image.jpg"
185 }
186
187 {:ok, %{id: media_id}} = ActivityPub.upload(file, actor: user.ap_id)
188
189 {:ok, image_post} = CommonAPI.post(user, %{"status" => "cofe", "media_ids" => [media_id]})
190
191 conn =
192 conn
193 |> get("/api/v1/accounts/#{user.id}/statuses", %{"only_media" => "true"})
194
195 assert [%{"id" => id}] = json_response(conn, 200)
196 assert id == to_string(image_post.id)
197
198 conn =
199 build_conn()
200 |> get("/api/v1/accounts/#{user.id}/statuses", %{"only_media" => "1"})
201
202 assert [%{"id" => id}] = json_response(conn, 200)
203 assert id == to_string(image_post.id)
204 end
205
206 test "gets a user's statuses without reblogs", %{conn: conn} do
207 user = insert(:user)
208 {:ok, post} = CommonAPI.post(user, %{"status" => "HI!!!"})
209 {:ok, _, _} = CommonAPI.repeat(post.id, user)
210
211 conn =
212 conn
213 |> get("/api/v1/accounts/#{user.id}/statuses", %{"exclude_reblogs" => "true"})
214
215 assert [%{"id" => id}] = json_response(conn, 200)
216 assert id == to_string(post.id)
217
218 conn =
219 conn
220 |> get("/api/v1/accounts/#{user.id}/statuses", %{"exclude_reblogs" => "1"})
221
222 assert [%{"id" => id}] = json_response(conn, 200)
223 assert id == to_string(post.id)
224 end
225
226 test "filters user's statuses by a hashtag", %{conn: conn} do
227 user = insert(:user)
228 {:ok, post} = CommonAPI.post(user, %{"status" => "#hashtag"})
229 {:ok, _post} = CommonAPI.post(user, %{"status" => "hashtag"})
230
231 conn =
232 conn
233 |> get("/api/v1/accounts/#{user.id}/statuses", %{"tagged" => "hashtag"})
234
235 assert [%{"id" => id}] = json_response(conn, 200)
236 assert id == to_string(post.id)
237 end
238 end
239
240 describe "followers" do
241 test "getting followers", %{conn: conn} do
242 user = insert(:user)
243 other_user = insert(:user)
244 {:ok, user} = User.follow(user, other_user)
245
246 conn =
247 conn
248 |> get("/api/v1/accounts/#{other_user.id}/followers")
249
250 assert [%{"id" => id}] = json_response(conn, 200)
251 assert id == to_string(user.id)
252 end
253
254 test "getting followers, hide_followers", %{conn: conn} do
255 user = insert(:user)
256 other_user = insert(:user, %{info: %{hide_followers: true}})
257 {:ok, _user} = User.follow(user, other_user)
258
259 conn =
260 conn
261 |> get("/api/v1/accounts/#{other_user.id}/followers")
262
263 assert [] == json_response(conn, 200)
264 end
265
266 test "getting followers, hide_followers, same user requesting", %{conn: conn} do
267 user = insert(:user)
268 other_user = insert(:user, %{info: %{hide_followers: true}})
269 {:ok, _user} = User.follow(user, other_user)
270
271 conn =
272 conn
273 |> assign(:user, other_user)
274 |> get("/api/v1/accounts/#{other_user.id}/followers")
275
276 refute [] == json_response(conn, 200)
277 end
278
279 test "getting followers, pagination", %{conn: conn} do
280 user = insert(:user)
281 follower1 = insert(:user)
282 follower2 = insert(:user)
283 follower3 = insert(:user)
284 {:ok, _} = User.follow(follower1, user)
285 {:ok, _} = User.follow(follower2, user)
286 {:ok, _} = User.follow(follower3, user)
287
288 conn =
289 conn
290 |> assign(:user, user)
291
292 res_conn =
293 conn
294 |> get("/api/v1/accounts/#{user.id}/followers?since_id=#{follower1.id}")
295
296 assert [%{"id" => id3}, %{"id" => id2}] = json_response(res_conn, 200)
297 assert id3 == follower3.id
298 assert id2 == follower2.id
299
300 res_conn =
301 conn
302 |> get("/api/v1/accounts/#{user.id}/followers?max_id=#{follower3.id}")
303
304 assert [%{"id" => id2}, %{"id" => id1}] = json_response(res_conn, 200)
305 assert id2 == follower2.id
306 assert id1 == follower1.id
307
308 res_conn =
309 conn
310 |> get("/api/v1/accounts/#{user.id}/followers?limit=1&max_id=#{follower3.id}")
311
312 assert [%{"id" => id2}] = json_response(res_conn, 200)
313 assert id2 == follower2.id
314
315 assert [link_header] = get_resp_header(res_conn, "link")
316 assert link_header =~ ~r/min_id=#{follower2.id}/
317 assert link_header =~ ~r/max_id=#{follower2.id}/
318 end
319 end
320
321 describe "following" do
322 test "getting following", %{conn: conn} do
323 user = insert(:user)
324 other_user = insert(:user)
325 {:ok, user} = User.follow(user, other_user)
326
327 conn =
328 conn
329 |> get("/api/v1/accounts/#{user.id}/following")
330
331 assert [%{"id" => id}] = json_response(conn, 200)
332 assert id == to_string(other_user.id)
333 end
334
335 test "getting following, hide_follows", %{conn: conn} do
336 user = insert(:user, %{info: %{hide_follows: true}})
337 other_user = insert(:user)
338 {:ok, user} = User.follow(user, other_user)
339
340 conn =
341 conn
342 |> get("/api/v1/accounts/#{user.id}/following")
343
344 assert [] == json_response(conn, 200)
345 end
346
347 test "getting following, hide_follows, same user requesting", %{conn: conn} do
348 user = insert(:user, %{info: %{hide_follows: true}})
349 other_user = insert(:user)
350 {:ok, user} = User.follow(user, other_user)
351
352 conn =
353 conn
354 |> assign(:user, user)
355 |> get("/api/v1/accounts/#{user.id}/following")
356
357 refute [] == json_response(conn, 200)
358 end
359
360 test "getting following, pagination", %{conn: conn} do
361 user = insert(:user)
362 following1 = insert(:user)
363 following2 = insert(:user)
364 following3 = insert(:user)
365 {:ok, _} = User.follow(user, following1)
366 {:ok, _} = User.follow(user, following2)
367 {:ok, _} = User.follow(user, following3)
368
369 conn =
370 conn
371 |> assign(:user, user)
372
373 res_conn =
374 conn
375 |> get("/api/v1/accounts/#{user.id}/following?since_id=#{following1.id}")
376
377 assert [%{"id" => id3}, %{"id" => id2}] = json_response(res_conn, 200)
378 assert id3 == following3.id
379 assert id2 == following2.id
380
381 res_conn =
382 conn
383 |> get("/api/v1/accounts/#{user.id}/following?max_id=#{following3.id}")
384
385 assert [%{"id" => id2}, %{"id" => id1}] = json_response(res_conn, 200)
386 assert id2 == following2.id
387 assert id1 == following1.id
388
389 res_conn =
390 conn
391 |> get("/api/v1/accounts/#{user.id}/following?limit=1&max_id=#{following3.id}")
392
393 assert [%{"id" => id2}] = json_response(res_conn, 200)
394 assert id2 == following2.id
395
396 assert [link_header] = get_resp_header(res_conn, "link")
397 assert link_header =~ ~r/min_id=#{following2.id}/
398 assert link_header =~ ~r/max_id=#{following2.id}/
399 end
400 end
401
402 describe "follow/unfollow" do
403 test "following / unfollowing a user", %{conn: conn} do
404 user = insert(:user)
405 other_user = insert(:user)
406
407 conn =
408 conn
409 |> assign(:user, user)
410 |> post("/api/v1/accounts/#{other_user.id}/follow")
411
412 assert %{"id" => _id, "following" => true} = json_response(conn, 200)
413
414 user = User.get_cached_by_id(user.id)
415
416 conn =
417 build_conn()
418 |> assign(:user, user)
419 |> post("/api/v1/accounts/#{other_user.id}/unfollow")
420
421 assert %{"id" => _id, "following" => false} = json_response(conn, 200)
422
423 user = User.get_cached_by_id(user.id)
424
425 conn =
426 build_conn()
427 |> assign(:user, user)
428 |> post("/api/v1/follows", %{"uri" => other_user.nickname})
429
430 assert %{"id" => id} = json_response(conn, 200)
431 assert id == to_string(other_user.id)
432 end
433
434 test "following without reblogs" do
435 follower = insert(:user)
436 followed = insert(:user)
437 other_user = insert(:user)
438
439 conn =
440 build_conn()
441 |> assign(:user, follower)
442 |> post("/api/v1/accounts/#{followed.id}/follow?reblogs=false")
443
444 assert %{"showing_reblogs" => false} = json_response(conn, 200)
445
446 {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hey"})
447 {:ok, reblog, _} = CommonAPI.repeat(activity.id, followed)
448
449 conn =
450 build_conn()
451 |> assign(:user, User.get_cached_by_id(follower.id))
452 |> get("/api/v1/timelines/home")
453
454 assert [] == json_response(conn, 200)
455
456 conn =
457 build_conn()
458 |> assign(:user, follower)
459 |> post("/api/v1/accounts/#{followed.id}/follow?reblogs=true")
460
461 assert %{"showing_reblogs" => true} = json_response(conn, 200)
462
463 conn =
464 build_conn()
465 |> assign(:user, User.get_cached_by_id(follower.id))
466 |> get("/api/v1/timelines/home")
467
468 expected_activity_id = reblog.id
469 assert [%{"id" => ^expected_activity_id}] = json_response(conn, 200)
470 end
471
472 test "following / unfollowing errors" do
473 user = insert(:user)
474
475 conn =
476 build_conn()
477 |> assign(:user, user)
478
479 # self follow
480 conn_res = post(conn, "/api/v1/accounts/#{user.id}/follow")
481 assert %{"error" => "Record not found"} = json_response(conn_res, 404)
482
483 # self unfollow
484 user = User.get_cached_by_id(user.id)
485 conn_res = post(conn, "/api/v1/accounts/#{user.id}/unfollow")
486 assert %{"error" => "Record not found"} = json_response(conn_res, 404)
487
488 # self follow via uri
489 user = User.get_cached_by_id(user.id)
490 conn_res = post(conn, "/api/v1/follows", %{"uri" => user.nickname})
491 assert %{"error" => "Record not found"} = json_response(conn_res, 404)
492
493 # follow non existing user
494 conn_res = post(conn, "/api/v1/accounts/doesntexist/follow")
495 assert %{"error" => "Record not found"} = json_response(conn_res, 404)
496
497 # follow non existing user via uri
498 conn_res = post(conn, "/api/v1/follows", %{"uri" => "doesntexist"})
499 assert %{"error" => "Record not found"} = json_response(conn_res, 404)
500
501 # unfollow non existing user
502 conn_res = post(conn, "/api/v1/accounts/doesntexist/unfollow")
503 assert %{"error" => "Record not found"} = json_response(conn_res, 404)
504 end
505 end
506
507 describe "mute/unmute" do
508 test "with notifications", %{conn: conn} do
509 user = insert(:user)
510 other_user = insert(:user)
511
512 conn =
513 conn
514 |> assign(:user, user)
515 |> post("/api/v1/accounts/#{other_user.id}/mute")
516
517 response = json_response(conn, 200)
518
519 assert %{"id" => _id, "muting" => true, "muting_notifications" => true} = response
520 user = User.get_cached_by_id(user.id)
521
522 conn =
523 build_conn()
524 |> assign(:user, user)
525 |> post("/api/v1/accounts/#{other_user.id}/unmute")
526
527 response = json_response(conn, 200)
528 assert %{"id" => _id, "muting" => false, "muting_notifications" => false} = response
529 end
530
531 test "without notifications", %{conn: conn} do
532 user = insert(:user)
533 other_user = insert(:user)
534
535 conn =
536 conn
537 |> assign(:user, user)
538 |> post("/api/v1/accounts/#{other_user.id}/mute", %{"notifications" => "false"})
539
540 response = json_response(conn, 200)
541
542 assert %{"id" => _id, "muting" => true, "muting_notifications" => false} = response
543 user = User.get_cached_by_id(user.id)
544
545 conn =
546 build_conn()
547 |> assign(:user, user)
548 |> post("/api/v1/accounts/#{other_user.id}/unmute")
549
550 response = json_response(conn, 200)
551 assert %{"id" => _id, "muting" => false, "muting_notifications" => false} = response
552 end
553 end
554
555 describe "getting favorites timeline of specified user" do
556 setup do
557 [current_user, user] = insert_pair(:user, %{info: %{hide_favorites: false}})
558 [current_user: current_user, user: user]
559 end
560
561 test "returns list of statuses favorited by specified user", %{
562 conn: conn,
563 current_user: current_user,
564 user: user
565 } do
566 [activity | _] = insert_pair(:note_activity)
567 CommonAPI.favorite(activity.id, user)
568
569 response =
570 conn
571 |> assign(:user, current_user)
572 |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
573 |> json_response(:ok)
574
575 [like] = response
576
577 assert length(response) == 1
578 assert like["id"] == activity.id
579 end
580
581 test "returns favorites for specified user_id when user is not logged in", %{
582 conn: conn,
583 user: user
584 } do
585 activity = insert(:note_activity)
586 CommonAPI.favorite(activity.id, user)
587
588 response =
589 conn
590 |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
591 |> json_response(:ok)
592
593 assert length(response) == 1
594 end
595
596 test "returns favorited DM only when user is logged in and he is one of recipients", %{
597 conn: conn,
598 current_user: current_user,
599 user: user
600 } do
601 {:ok, direct} =
602 CommonAPI.post(current_user, %{
603 "status" => "Hi @#{user.nickname}!",
604 "visibility" => "direct"
605 })
606
607 CommonAPI.favorite(direct.id, user)
608
609 response =
610 conn
611 |> assign(:user, current_user)
612 |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
613 |> json_response(:ok)
614
615 assert length(response) == 1
616
617 anonymous_response =
618 conn
619 |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
620 |> json_response(:ok)
621
622 assert Enum.empty?(anonymous_response)
623 end
624
625 test "does not return others' favorited DM when user is not one of recipients", %{
626 conn: conn,
627 current_user: current_user,
628 user: user
629 } do
630 user_two = insert(:user)
631
632 {:ok, direct} =
633 CommonAPI.post(user_two, %{
634 "status" => "Hi @#{user.nickname}!",
635 "visibility" => "direct"
636 })
637
638 CommonAPI.favorite(direct.id, user)
639
640 response =
641 conn
642 |> assign(:user, current_user)
643 |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
644 |> json_response(:ok)
645
646 assert Enum.empty?(response)
647 end
648
649 test "paginates favorites using since_id and max_id", %{
650 conn: conn,
651 current_user: current_user,
652 user: user
653 } do
654 activities = insert_list(10, :note_activity)
655
656 Enum.each(activities, fn activity ->
657 CommonAPI.favorite(activity.id, user)
658 end)
659
660 third_activity = Enum.at(activities, 2)
661 seventh_activity = Enum.at(activities, 6)
662
663 response =
664 conn
665 |> assign(:user, current_user)
666 |> get("/api/v1/pleroma/accounts/#{user.id}/favourites", %{
667 since_id: third_activity.id,
668 max_id: seventh_activity.id
669 })
670 |> json_response(:ok)
671
672 assert length(response) == 3
673 refute third_activity in response
674 refute seventh_activity in response
675 end
676
677 test "limits favorites using limit parameter", %{
678 conn: conn,
679 current_user: current_user,
680 user: user
681 } do
682 7
683 |> insert_list(:note_activity)
684 |> Enum.each(fn activity ->
685 CommonAPI.favorite(activity.id, user)
686 end)
687
688 response =
689 conn
690 |> assign(:user, current_user)
691 |> get("/api/v1/pleroma/accounts/#{user.id}/favourites", %{limit: "3"})
692 |> json_response(:ok)
693
694 assert length(response) == 3
695 end
696
697 test "returns empty response when user does not have any favorited statuses", %{
698 conn: conn,
699 current_user: current_user,
700 user: user
701 } do
702 response =
703 conn
704 |> assign(:user, current_user)
705 |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
706 |> json_response(:ok)
707
708 assert Enum.empty?(response)
709 end
710
711 test "returns 404 error when specified user is not exist", %{conn: conn} do
712 conn = get(conn, "/api/v1/pleroma/accounts/test/favourites")
713
714 assert json_response(conn, 404) == %{"error" => "Record not found"}
715 end
716
717 test "returns 403 error when user has hidden own favorites", %{
718 conn: conn,
719 current_user: current_user
720 } do
721 user = insert(:user, %{info: %{hide_favorites: true}})
722 activity = insert(:note_activity)
723 CommonAPI.favorite(activity.id, user)
724
725 conn =
726 conn
727 |> assign(:user, current_user)
728 |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
729
730 assert json_response(conn, 403) == %{"error" => "Can't get favorites"}
731 end
732
733 test "hides favorites for new users by default", %{conn: conn, current_user: current_user} do
734 user = insert(:user)
735 activity = insert(:note_activity)
736 CommonAPI.favorite(activity.id, user)
737
738 conn =
739 conn
740 |> assign(:user, current_user)
741 |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
742
743 assert user.info.hide_favorites
744 assert json_response(conn, 403) == %{"error" => "Can't get favorites"}
745 end
746 end
747
748 describe "pinned statuses" do
749 setup do
750 user = insert(:user)
751 {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
752
753 [user: user, activity: activity]
754 end
755
756 test "returns pinned statuses", %{conn: conn, user: user, activity: activity} do
757 {:ok, _} = CommonAPI.pin(activity.id, user)
758
759 result =
760 conn
761 |> assign(:user, user)
762 |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
763 |> json_response(200)
764
765 id_str = to_string(activity.id)
766
767 assert [%{"id" => ^id_str, "pinned" => true}] = result
768 end
769 end
770
771 test "subscribing / unsubscribing to a user", %{conn: conn} do
772 user = insert(:user)
773 subscription_target = insert(:user)
774
775 conn =
776 conn
777 |> assign(:user, user)
778 |> post("/api/v1/pleroma/accounts/#{subscription_target.id}/subscribe")
779
780 assert %{"id" => _id, "subscribing" => true} = json_response(conn, 200)
781
782 conn =
783 build_conn()
784 |> assign(:user, user)
785 |> post("/api/v1/pleroma/accounts/#{subscription_target.id}/unsubscribe")
786
787 assert %{"id" => _id, "subscribing" => false} = json_response(conn, 200)
788 end
789
790 test "blocking / unblocking a user", %{conn: conn} do
791 user = insert(:user)
792 other_user = insert(:user)
793
794 conn =
795 conn
796 |> assign(:user, user)
797 |> post("/api/v1/accounts/#{other_user.id}/block")
798
799 assert %{"id" => _id, "blocking" => true} = json_response(conn, 200)
800
801 user = User.get_cached_by_id(user.id)
802
803 conn =
804 build_conn()
805 |> assign(:user, user)
806 |> post("/api/v1/accounts/#{other_user.id}/unblock")
807
808 assert %{"id" => _id, "blocking" => false} = json_response(conn, 200)
809 end
810 end