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.CommonAPITest do
9 alias Pleroma.Conversation.Participation
12 alias Pleroma.Web.ActivityPub.ActivityPub
13 alias Pleroma.Web.ActivityPub.Transmogrifier
14 alias Pleroma.Web.ActivityPub.Visibility
15 alias Pleroma.Web.AdminAPI.AccountView
16 alias Pleroma.Web.CommonAPI
18 import Pleroma.Factory
21 require Pleroma.Constants
23 setup do: clear_config([:instance, :safe_dm_mentions])
24 setup do: clear_config([:instance, :limit])
25 setup do: clear_config([:instance, :max_pinned_statuses])
27 describe "posting chat messages" do
28 setup do: clear_config([:instance, :chat_limit])
30 test "it posts a chat message without content but with an attachment" do
31 author = insert(:user)
32 recipient = insert(:user)
35 content_type: "image/jpg",
36 path: Path.absname("test/fixtures/image.jpg"),
37 filename: "an_image.jpg"
40 {:ok, upload} = ActivityPub.upload(file, actor: author.ap_id)
43 CommonAPI.post_chat_message(
53 test "it linkifies" do
54 author = insert(:user)
55 recipient = insert(:user)
57 other_user = insert(:user)
60 CommonAPI.post_chat_message(
63 "https://example.org is the site of @#{other_user.nickname} #2hu"
66 assert other_user.ap_id not in activity.recipients
68 object = Object.normalize(activity, false)
70 assert object.data["content"] ==
71 "<a href=\"https://example.org\" rel=\"ugc\">https://example.org</a> is the site of <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{
73 }\" href=\"#{other_user.ap_id}\" rel=\"ugc\">@<span>#{other_user.nickname}</span></a></span> <a class=\"hashtag\" data-tag=\"2hu\" href=\"http://localhost:4001/tag/2hu\">#2hu</a>"
76 test "it posts a chat message" do
77 author = insert(:user)
78 recipient = insert(:user)
81 CommonAPI.post_chat_message(
84 "a test message <script>alert('uuu')</script> :firefox:"
87 assert activity.data["type"] == "Create"
89 object = Object.normalize(activity)
91 assert object.data["type"] == "ChatMessage"
92 assert object.data["to"] == [recipient.ap_id]
94 assert object.data["content"] ==
95 "a test message <script>alert('uuu')</script> :firefox:"
97 assert object.data["emoji"] == %{
98 "firefox" => "http://localhost:4001/emoji/Firefox.gif"
101 assert Chat.get(author.id, recipient.ap_id)
102 assert Chat.get(recipient.id, author.ap_id)
104 assert :ok == Pleroma.Web.Federator.perform(:publish, activity)
107 test "it reject messages over the local limit" do
108 Pleroma.Config.put([:instance, :chat_limit], 2)
110 author = insert(:user)
111 recipient = insert(:user)
114 CommonAPI.post_chat_message(
120 assert message == :content_too_long
124 describe "unblocking" do
125 test "it works even without an existing block activity" do
126 blocked = insert(:user)
127 blocker = insert(:user)
128 User.block(blocker, blocked)
130 assert User.blocks?(blocker, blocked)
131 assert {:ok, :no_activity} == CommonAPI.unblock(blocker, blocked)
132 refute User.blocks?(blocker, blocked)
136 describe "deletion" do
137 test "it works with pruned objects" do
140 {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
142 clear_config([:instance, :federating], true)
144 Object.normalize(post, false)
147 with_mock Pleroma.Web.Federator,
148 publish: fn _ -> nil end do
149 assert {:ok, delete} = CommonAPI.delete(post.id, user)
151 assert called(Pleroma.Web.Federator.publish(delete))
154 refute Activity.get_by_id(post.id)
157 test "it allows users to delete their posts" do
160 {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
162 clear_config([:instance, :federating], true)
164 with_mock Pleroma.Web.Federator,
165 publish: fn _ -> nil end do
166 assert {:ok, delete} = CommonAPI.delete(post.id, user)
168 assert called(Pleroma.Web.Federator.publish(delete))
171 refute Activity.get_by_id(post.id)
174 test "it does not allow a user to delete their posts" do
176 other_user = insert(:user)
178 {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
180 assert {:error, "Could not delete"} = CommonAPI.delete(post.id, other_user)
181 assert Activity.get_by_id(post.id)
184 test "it allows moderators to delete other user's posts" do
186 moderator = insert(:user, is_moderator: true)
188 {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
190 assert {:ok, delete} = CommonAPI.delete(post.id, moderator)
193 refute Activity.get_by_id(post.id)
196 test "it allows admins to delete other user's posts" do
198 moderator = insert(:user, is_admin: true)
200 {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
202 assert {:ok, delete} = CommonAPI.delete(post.id, moderator)
205 refute Activity.get_by_id(post.id)
208 test "superusers deleting non-local posts won't federate the delete" do
209 # This is the user of the ingested activity
213 ap_id: "http://mastodon.example.org/users/admin",
214 last_refreshed_at: NaiveDateTime.utc_now()
217 moderator = insert(:user, is_admin: true)
220 File.read!("test/fixtures/mastodon-post-activity.json")
223 {:ok, post} = Transmogrifier.handle_incoming(data)
225 with_mock Pleroma.Web.Federator,
226 publish: fn _ -> nil end do
227 assert {:ok, delete} = CommonAPI.delete(post.id, moderator)
229 refute called(Pleroma.Web.Federator.publish(:_))
232 refute Activity.get_by_id(post.id)
236 test "favoriting race condition" do
238 users_serial = insert_list(10, :user)
239 users = insert_list(10, :user)
241 {:ok, activity} = CommonAPI.post(user, %{status: "."})
244 |> Enum.map(fn user ->
245 CommonAPI.favorite(user, activity.id)
248 object = Object.get_by_ap_id(activity.data["object"])
249 assert object.data["like_count"] == 10
252 |> Enum.map(fn user ->
254 CommonAPI.favorite(user, activity.id)
257 |> Enum.map(&Task.await/1)
259 object = Object.get_by_ap_id(activity.data["object"])
260 assert object.data["like_count"] == 20
263 test "repeating race condition" do
265 users_serial = insert_list(10, :user)
266 users = insert_list(10, :user)
268 {:ok, activity} = CommonAPI.post(user, %{status: "."})
271 |> Enum.map(fn user ->
272 CommonAPI.repeat(activity.id, user)
275 object = Object.get_by_ap_id(activity.data["object"])
276 assert object.data["announcement_count"] == 10
279 |> Enum.map(fn user ->
281 CommonAPI.repeat(activity.id, user)
284 |> Enum.map(&Task.await/1)
286 object = Object.get_by_ap_id(activity.data["object"])
287 assert object.data["announcement_count"] == 20
290 test "when replying to a conversation / participation, it will set the correct context id even if no explicit reply_to is given" do
292 {:ok, activity} = CommonAPI.post(user, %{status: ".", visibility: "direct"})
294 [participation] = Participation.for_user(user)
297 CommonAPI.post(user, %{status: ".", in_reply_to_conversation_id: participation.id})
299 assert Visibility.is_direct?(convo_reply)
301 assert activity.data["context"] == convo_reply.data["context"]
304 test "when replying to a conversation / participation, it only mentions the recipients explicitly declared in the participation" do
306 jafnhar = insert(:user)
307 tridi = insert(:user)
310 CommonAPI.post(har, %{
311 status: "@#{jafnhar.nickname} hey",
315 assert har.ap_id in activity.recipients
316 assert jafnhar.ap_id in activity.recipients
318 [participation] = Participation.for_user(har)
321 CommonAPI.post(har, %{
322 status: "I don't really like @#{tridi.nickname}",
323 visibility: "direct",
324 in_reply_to_status_id: activity.id,
325 in_reply_to_conversation_id: participation.id
328 assert har.ap_id in activity.recipients
329 assert jafnhar.ap_id in activity.recipients
330 refute tridi.ap_id in activity.recipients
333 test "with the safe_dm_mention option set, it does not mention people beyond the initial tags" do
335 jafnhar = insert(:user)
336 tridi = insert(:user)
338 Pleroma.Config.put([:instance, :safe_dm_mentions], true)
341 CommonAPI.post(har, %{
342 status: "@#{jafnhar.nickname} hey, i never want to see @#{tridi.nickname} again",
346 refute tridi.ap_id in activity.recipients
347 assert jafnhar.ap_id in activity.recipients
350 test "it de-duplicates tags" do
352 {:ok, activity} = CommonAPI.post(user, %{status: "#2hu #2HU"})
354 object = Object.normalize(activity)
356 assert object.data["tag"] == ["2hu"]
359 test "it adds emoji in the object" do
361 {:ok, activity} = CommonAPI.post(user, %{status: ":firefox:"})
363 assert Object.normalize(activity).data["emoji"]["firefox"]
366 describe "posting" do
367 test "it supports explicit addressing" do
369 user_two = insert(:user)
370 user_three = insert(:user)
371 user_four = insert(:user)
374 CommonAPI.post(user, %{
376 "Hey, I think @#{user_three.nickname} is ugly. @#{user_four.nickname} is alright though.",
377 to: [user_two.nickname, user_four.nickname, "nonexistent"]
380 assert user.ap_id in activity.recipients
381 assert user_two.ap_id in activity.recipients
382 assert user_four.ap_id in activity.recipients
383 refute user_three.ap_id in activity.recipients
386 test "it filters out obviously bad tags when accepting a post as HTML" do
389 post = "<p><b>2hu</b></p><script>alert('xss')</script>"
392 CommonAPI.post(user, %{
394 content_type: "text/html"
397 object = Object.normalize(activity)
399 assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
402 test "it filters out obviously bad tags when accepting a post as Markdown" do
405 post = "<p><b>2hu</b></p><script>alert('xss')</script>"
408 CommonAPI.post(user, %{
410 content_type: "text/markdown"
413 object = Object.normalize(activity)
415 assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
418 test "it does not allow replies to direct messages that are not direct messages themselves" do
421 {:ok, activity} = CommonAPI.post(user, %{status: "suya..", visibility: "direct"})
424 CommonAPI.post(user, %{
426 visibility: "direct",
427 in_reply_to_status_id: activity.id
430 Enum.each(["public", "private", "unlisted"], fn visibility ->
431 assert {:error, "The message visibility must be direct"} =
432 CommonAPI.post(user, %{
434 visibility: visibility,
435 in_reply_to_status_id: activity.id
440 test "replying with a direct message will NOT auto-add the author of the reply to the recipient list" do
442 other_user = insert(:user)
443 third_user = insert(:user)
445 {:ok, post} = CommonAPI.post(user, %{status: "I'm stupid"})
448 CommonAPI.post(other_user, %{status: "No ur smart", in_reply_to_status_id: post.id})
450 # The OP is implicitly added
451 assert user.ap_id in open_answer.recipients
453 {:ok, secret_answer} =
454 CommonAPI.post(other_user, %{
455 status: "lol, that guy really is stupid, right, @#{third_user.nickname}?",
456 in_reply_to_status_id: post.id,
460 assert third_user.ap_id in secret_answer.recipients
462 # The OP is not added
463 refute user.ap_id in secret_answer.recipients
466 test "it allows to address a list" do
468 {:ok, list} = Pleroma.List.create("foo", user)
470 {:ok, activity} = CommonAPI.post(user, %{status: "foobar", visibility: "list:#{list.id}"})
472 assert activity.data["bcc"] == [list.ap_id]
473 assert activity.recipients == [list.ap_id, user.ap_id]
474 assert activity.data["listMessage"] == list.ap_id
477 test "it returns error when status is empty and no attachments" do
480 assert {:error, "Cannot post an empty status without attachments"} =
481 CommonAPI.post(user, %{status: ""})
484 test "it validates character limits are correctly enforced" do
485 Pleroma.Config.put([:instance, :limit], 5)
489 assert {:error, "The status is over the character limit"} =
490 CommonAPI.post(user, %{status: "foobar"})
492 assert {:ok, activity} = CommonAPI.post(user, %{status: "12345"})
495 test "it can handle activities that expire" do
499 NaiveDateTime.utc_now()
500 |> NaiveDateTime.truncate(:second)
501 |> NaiveDateTime.add(1_000_000, :second)
503 assert {:ok, activity} = CommonAPI.post(user, %{status: "chai", expires_in: 1_000_000})
505 assert expiration = Pleroma.ActivityExpiration.get_by_activity_id(activity.id)
506 assert expiration.scheduled_at == expires_at
510 describe "reactions" do
511 test "reacting to a status with an emoji" do
513 other_user = insert(:user)
515 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
517 {:ok, reaction} = CommonAPI.react_with_emoji(activity.id, user, "👍")
519 assert reaction.data["actor"] == user.ap_id
520 assert reaction.data["content"] == "👍"
522 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
524 {:error, _} = CommonAPI.react_with_emoji(activity.id, user, ".")
527 test "unreacting to a status with an emoji" do
529 other_user = insert(:user)
531 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
532 {:ok, reaction} = CommonAPI.react_with_emoji(activity.id, user, "👍")
534 {:ok, unreaction} = CommonAPI.unreact_with_emoji(activity.id, user, "👍")
536 assert unreaction.data["type"] == "Undo"
537 assert unreaction.data["object"] == reaction.data["id"]
538 assert unreaction.local
541 test "repeating a status" do
543 other_user = insert(:user)
545 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
547 {:ok, %Activity{} = announce_activity} = CommonAPI.repeat(activity.id, user)
548 assert Visibility.is_public?(announce_activity)
551 test "can't repeat a repeat" do
553 other_user = insert(:user)
554 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
556 {:ok, %Activity{} = announce} = CommonAPI.repeat(activity.id, other_user)
558 refute match?({:ok, %Activity{}}, CommonAPI.repeat(announce.id, user))
561 test "repeating a status privately" do
563 other_user = insert(:user)
565 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
567 {:ok, %Activity{} = announce_activity} =
568 CommonAPI.repeat(activity.id, user, %{visibility: "private"})
570 assert Visibility.is_private?(announce_activity)
571 refute Visibility.visible_for_user?(announce_activity, nil)
574 test "favoriting a status" do
576 other_user = insert(:user)
578 {:ok, post_activity} = CommonAPI.post(other_user, %{status: "cofe"})
580 {:ok, %Activity{data: data}} = CommonAPI.favorite(user, post_activity.id)
581 assert data["type"] == "Like"
582 assert data["actor"] == user.ap_id
583 assert data["object"] == post_activity.data["object"]
586 test "retweeting a status twice returns the status" do
588 other_user = insert(:user)
590 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
591 {:ok, %Activity{} = announce} = CommonAPI.repeat(activity.id, user)
592 {:ok, ^announce} = CommonAPI.repeat(activity.id, user)
595 test "favoriting a status twice returns ok, but without the like activity" do
597 other_user = insert(:user)
599 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
600 {:ok, %Activity{}} = CommonAPI.favorite(user, activity.id)
601 assert {:ok, :already_liked} = CommonAPI.favorite(user, activity.id)
605 describe "pinned statuses" do
607 Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
610 {:ok, activity} = CommonAPI.post(user, %{status: "HI!!!"})
612 [user: user, activity: activity]
615 test "pin status", %{user: user, activity: activity} do
616 assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
619 user = refresh_record(user)
621 assert %User{pinned_activities: [^id]} = user
624 test "pin poll", %{user: user} do
626 CommonAPI.post(user, %{
627 status: "How is fediverse today?",
628 poll: %{options: ["Absolutely outstanding", "Not good"], expires_in: 20}
631 assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
634 user = refresh_record(user)
636 assert %User{pinned_activities: [^id]} = user
639 test "unlisted statuses can be pinned", %{user: user} do
640 {:ok, activity} = CommonAPI.post(user, %{status: "HI!!!", visibility: "unlisted"})
641 assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
644 test "only self-authored can be pinned", %{activity: activity} do
647 assert {:error, "Could not pin"} = CommonAPI.pin(activity.id, user)
650 test "max pinned statuses", %{user: user, activity: activity_one} do
651 {:ok, activity_two} = CommonAPI.post(user, %{status: "HI!!!"})
653 assert {:ok, ^activity_one} = CommonAPI.pin(activity_one.id, user)
655 user = refresh_record(user)
657 assert {:error, "You have already pinned the maximum number of statuses"} =
658 CommonAPI.pin(activity_two.id, user)
661 test "unpin status", %{user: user, activity: activity} do
662 {:ok, activity} = CommonAPI.pin(activity.id, user)
664 user = refresh_record(user)
668 assert match?({:ok, %{id: ^id}}, CommonAPI.unpin(activity.id, user))
670 user = refresh_record(user)
672 assert %User{pinned_activities: []} = user
675 test "should unpin when deleting a status", %{user: user, activity: activity} do
676 {:ok, activity} = CommonAPI.pin(activity.id, user)
678 user = refresh_record(user)
680 assert {:ok, _} = CommonAPI.delete(activity.id, user)
682 user = refresh_record(user)
684 assert %User{pinned_activities: []} = user
688 describe "mute tests" do
692 activity = insert(:note_activity)
694 [user: user, activity: activity]
697 test "add mute", %{user: user, activity: activity} do
698 {:ok, _} = CommonAPI.add_mute(user, activity)
699 assert CommonAPI.thread_muted?(user, activity)
702 test "remove mute", %{user: user, activity: activity} do
703 CommonAPI.add_mute(user, activity)
704 {:ok, _} = CommonAPI.remove_mute(user, activity)
705 refute CommonAPI.thread_muted?(user, activity)
708 test "check that mutes can't be duplicate", %{user: user, activity: activity} do
709 CommonAPI.add_mute(user, activity)
710 {:error, _} = CommonAPI.add_mute(user, activity)
714 describe "reports" do
715 test "creates a report" do
716 reporter = insert(:user)
717 target_user = insert(:user)
719 {:ok, activity} = CommonAPI.post(target_user, %{status: "foobar"})
721 reporter_ap_id = reporter.ap_id
722 target_ap_id = target_user.ap_id
723 activity_ap_id = activity.data["id"]
727 account_id: target_user.id,
729 status_ids: [activity.id]
734 "id" => activity_ap_id,
735 "content" => "foobar",
736 "published" => activity.object.data["published"],
737 "actor" => AccountView.render("show.json", %{user: target_user})
740 assert {:ok, flag_activity} = CommonAPI.report(reporter, report_data)
743 actor: ^reporter_ap_id,
746 "content" => ^comment,
747 "object" => [^target_ap_id, ^note_obj],
753 test "updates report state" do
754 [reporter, target_user] = insert_pair(:user)
755 activity = insert(:note_activity, user: target_user)
757 {:ok, %Activity{id: report_id}} =
758 CommonAPI.report(reporter, %{
759 account_id: target_user.id,
760 comment: "I feel offended",
761 status_ids: [activity.id]
764 {:ok, report} = CommonAPI.update_report_state(report_id, "resolved")
766 assert report.data["state"] == "resolved"
768 [reported_user, activity_id] = report.data["object"]
770 assert reported_user == target_user.ap_id
771 assert activity_id == activity.data["id"]
774 test "does not update report state when state is unsupported" do
775 [reporter, target_user] = insert_pair(:user)
776 activity = insert(:note_activity, user: target_user)
778 {:ok, %Activity{id: report_id}} =
779 CommonAPI.report(reporter, %{
780 account_id: target_user.id,
781 comment: "I feel offended",
782 status_ids: [activity.id]
785 assert CommonAPI.update_report_state(report_id, "test") == {:error, "Unsupported state"}
788 test "updates state of multiple reports" do
789 [reporter, target_user] = insert_pair(:user)
790 activity = insert(:note_activity, user: target_user)
792 {:ok, %Activity{id: first_report_id}} =
793 CommonAPI.report(reporter, %{
794 account_id: target_user.id,
795 comment: "I feel offended",
796 status_ids: [activity.id]
799 {:ok, %Activity{id: second_report_id}} =
800 CommonAPI.report(reporter, %{
801 account_id: target_user.id,
802 comment: "I feel very offended!",
803 status_ids: [activity.id]
807 CommonAPI.update_report_state([first_report_id, second_report_id], "resolved")
809 first_report = Activity.get_by_id(first_report_id)
810 second_report = Activity.get_by_id(second_report_id)
812 assert report_ids -- [first_report_id, second_report_id] == []
813 assert first_report.data["state"] == "resolved"
814 assert second_report.data["state"] == "resolved"
818 describe "reblog muting" do
820 muter = insert(:user)
822 muted = insert(:user)
824 [muter: muter, muted: muted]
827 test "add a reblog mute", %{muter: muter, muted: muted} do
828 {:ok, _reblog_mute} = CommonAPI.hide_reblogs(muter, muted)
830 assert User.showing_reblogs?(muter, muted) == false
833 test "remove a reblog mute", %{muter: muter, muted: muted} do
834 {:ok, _reblog_mute} = CommonAPI.hide_reblogs(muter, muted)
835 {:ok, _reblog_mute} = CommonAPI.show_reblogs(muter, muted)
837 assert User.showing_reblogs?(muter, muted) == true
841 describe "unfollow/2" do
842 test "also unsubscribes a user" do
843 [follower, followed] = insert_pair(:user)
844 {:ok, follower, followed, _} = CommonAPI.follow(follower, followed)
845 {:ok, _subscription} = User.subscribe(follower, followed)
847 assert User.subscribed_to?(follower, followed)
849 {:ok, follower} = CommonAPI.unfollow(follower, followed)
851 refute User.subscribed_to?(follower, followed)
854 test "cancels a pending follow for a local user" do
855 follower = insert(:user)
856 followed = insert(:user, locked: true)
858 assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} =
859 CommonAPI.follow(follower, followed)
861 assert User.get_follow_state(follower, followed) == :follow_pending
862 assert {:ok, follower} = CommonAPI.unfollow(follower, followed)
863 assert User.get_follow_state(follower, followed) == nil
865 assert %{id: ^activity_id, data: %{"state" => "cancelled"}} =
866 Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(follower, followed)
871 "object" => %{"type" => "Follow", "state" => "cancelled"}
873 } = Pleroma.Web.ActivityPub.Utils.fetch_latest_undo(follower)
876 test "cancels a pending follow for a remote user" do
877 follower = insert(:user)
878 followed = insert(:user, locked: true, local: false, ap_enabled: true)
880 assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} =
881 CommonAPI.follow(follower, followed)
883 assert User.get_follow_state(follower, followed) == :follow_pending
884 assert {:ok, follower} = CommonAPI.unfollow(follower, followed)
885 assert User.get_follow_state(follower, followed) == nil
887 assert %{id: ^activity_id, data: %{"state" => "cancelled"}} =
888 Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(follower, followed)
893 "object" => %{"type" => "Follow", "state" => "cancelled"}
895 } = Pleroma.Web.ActivityPub.Utils.fetch_latest_undo(follower)
899 describe "accept_follow_request/2" do
900 test "after acceptance, it sets all existing pending follow request states to 'accept'" do
901 user = insert(:user, locked: true)
902 follower = insert(:user)
903 follower_two = insert(:user)
905 {:ok, follow_activity} = ActivityPub.follow(follower, user)
906 {:ok, follow_activity_two} = ActivityPub.follow(follower, user)
907 {:ok, follow_activity_three} = ActivityPub.follow(follower_two, user)
909 assert follow_activity.data["state"] == "pending"
910 assert follow_activity_two.data["state"] == "pending"
911 assert follow_activity_three.data["state"] == "pending"
913 {:ok, _follower} = CommonAPI.accept_follow_request(follower, user)
915 assert Repo.get(Activity, follow_activity.id).data["state"] == "accept"
916 assert Repo.get(Activity, follow_activity_two.id).data["state"] == "accept"
917 assert Repo.get(Activity, follow_activity_three.id).data["state"] == "pending"
920 test "after rejection, it sets all existing pending follow request states to 'reject'" do
921 user = insert(:user, locked: true)
922 follower = insert(:user)
923 follower_two = insert(:user)
925 {:ok, follow_activity} = ActivityPub.follow(follower, user)
926 {:ok, follow_activity_two} = ActivityPub.follow(follower, user)
927 {:ok, follow_activity_three} = ActivityPub.follow(follower_two, user)
929 assert follow_activity.data["state"] == "pending"
930 assert follow_activity_two.data["state"] == "pending"
931 assert follow_activity_three.data["state"] == "pending"
933 {:ok, _follower} = CommonAPI.reject_follow_request(follower, user)
935 assert Repo.get(Activity, follow_activity.id).data["state"] == "reject"
936 assert Repo.get(Activity, follow_activity_two.id).data["state"] == "reject"
937 assert Repo.get(Activity, follow_activity_three.id).data["state"] == "pending"
940 test "doesn't create a following relationship if the corresponding follow request doesn't exist" do
941 user = insert(:user, locked: true)
942 not_follower = insert(:user)
943 CommonAPI.accept_follow_request(not_follower, user)
945 assert Pleroma.FollowingRelationship.following?(not_follower, user) == false
950 test "does not allow to vote twice" do
952 other_user = insert(:user)
955 CommonAPI.post(user, %{
956 status: "Am I cute?",
957 poll: %{options: ["Yes", "No"], expires_in: 20}
960 object = Object.normalize(activity)
962 {:ok, _, object} = CommonAPI.vote(other_user, object, [0])
964 assert {:error, "Already voted"} == CommonAPI.vote(other_user, object, [1])
968 describe "listen/2" do
969 test "returns a valid activity" do
973 CommonAPI.listen(user, %{
974 title: "lain radio episode 1",
980 object = Object.normalize(activity)
982 assert object.data["title"] == "lain radio episode 1"
984 assert Visibility.get_visibility(activity) == "public"
987 test "respects visibility=private" do
991 CommonAPI.listen(user, %{
992 title: "lain radio episode 1",
996 visibility: "private"
999 object = Object.normalize(activity)
1001 assert object.data["title"] == "lain radio episode 1"
1003 assert Visibility.get_visibility(activity) == "private"