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 posts a chat message" do
54 author = insert(:user)
55 recipient = insert(:user)
58 CommonAPI.post_chat_message(
61 "a test message <script>alert('uuu')</script> :firefox:"
64 assert activity.data["type"] == "Create"
66 object = Object.normalize(activity)
68 assert object.data["type"] == "ChatMessage"
69 assert object.data["to"] == [recipient.ap_id]
71 assert object.data["content"] ==
72 "a test message <script>alert('uuu')</script> :firefox:"
74 assert object.data["emoji"] == %{
75 "firefox" => "http://localhost:4001/emoji/Firefox.gif"
78 assert Chat.get(author.id, recipient.ap_id)
79 assert Chat.get(recipient.id, author.ap_id)
81 assert :ok == Pleroma.Web.Federator.perform(:publish, activity)
84 test "it reject messages over the local limit" do
85 Pleroma.Config.put([:instance, :chat_limit], 2)
87 author = insert(:user)
88 recipient = insert(:user)
91 CommonAPI.post_chat_message(
97 assert message == :content_too_long
101 describe "unblocking" do
102 test "it works even without an existing block activity" do
103 blocked = insert(:user)
104 blocker = insert(:user)
105 User.block(blocker, blocked)
107 assert User.blocks?(blocker, blocked)
108 assert {:ok, :no_activity} == CommonAPI.unblock(blocker, blocked)
109 refute User.blocks?(blocker, blocked)
113 describe "deletion" do
114 test "it works with pruned objects" do
117 {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
119 clear_config([:instance, :federating], true)
121 Object.normalize(post, false)
124 with_mock Pleroma.Web.Federator,
125 publish: fn _ -> nil end do
126 assert {:ok, delete} = CommonAPI.delete(post.id, user)
128 assert called(Pleroma.Web.Federator.publish(delete))
131 refute Activity.get_by_id(post.id)
134 test "it allows users to delete their posts" do
137 {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
139 clear_config([:instance, :federating], true)
141 with_mock Pleroma.Web.Federator,
142 publish: fn _ -> nil end do
143 assert {:ok, delete} = CommonAPI.delete(post.id, user)
145 assert called(Pleroma.Web.Federator.publish(delete))
148 refute Activity.get_by_id(post.id)
151 test "it does not allow a user to delete their posts" do
153 other_user = insert(:user)
155 {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
157 assert {:error, "Could not delete"} = CommonAPI.delete(post.id, other_user)
158 assert Activity.get_by_id(post.id)
161 test "it allows moderators to delete other user's posts" do
163 moderator = insert(:user, is_moderator: true)
165 {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
167 assert {:ok, delete} = CommonAPI.delete(post.id, moderator)
170 refute Activity.get_by_id(post.id)
173 test "it allows admins to delete other user's posts" do
175 moderator = insert(:user, is_admin: true)
177 {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
179 assert {:ok, delete} = CommonAPI.delete(post.id, moderator)
182 refute Activity.get_by_id(post.id)
185 test "superusers deleting non-local posts won't federate the delete" do
186 # This is the user of the ingested activity
190 ap_id: "http://mastodon.example.org/users/admin",
191 last_refreshed_at: NaiveDateTime.utc_now()
194 moderator = insert(:user, is_admin: true)
197 File.read!("test/fixtures/mastodon-post-activity.json")
200 {:ok, post} = Transmogrifier.handle_incoming(data)
202 with_mock Pleroma.Web.Federator,
203 publish: fn _ -> nil end do
204 assert {:ok, delete} = CommonAPI.delete(post.id, moderator)
206 refute called(Pleroma.Web.Federator.publish(:_))
209 refute Activity.get_by_id(post.id)
213 test "favoriting race condition" do
215 users_serial = insert_list(10, :user)
216 users = insert_list(10, :user)
218 {:ok, activity} = CommonAPI.post(user, %{status: "."})
221 |> Enum.map(fn user ->
222 CommonAPI.favorite(user, activity.id)
225 object = Object.get_by_ap_id(activity.data["object"])
226 assert object.data["like_count"] == 10
229 |> Enum.map(fn user ->
231 CommonAPI.favorite(user, activity.id)
234 |> Enum.map(&Task.await/1)
236 object = Object.get_by_ap_id(activity.data["object"])
237 assert object.data["like_count"] == 20
240 test "repeating race condition" do
242 users_serial = insert_list(10, :user)
243 users = insert_list(10, :user)
245 {:ok, activity} = CommonAPI.post(user, %{status: "."})
248 |> Enum.map(fn user ->
249 CommonAPI.repeat(activity.id, user)
252 object = Object.get_by_ap_id(activity.data["object"])
253 assert object.data["announcement_count"] == 10
256 |> Enum.map(fn user ->
258 CommonAPI.repeat(activity.id, user)
261 |> Enum.map(&Task.await/1)
263 object = Object.get_by_ap_id(activity.data["object"])
264 assert object.data["announcement_count"] == 20
267 test "when replying to a conversation / participation, it will set the correct context id even if no explicit reply_to is given" do
269 {:ok, activity} = CommonAPI.post(user, %{status: ".", visibility: "direct"})
271 [participation] = Participation.for_user(user)
274 CommonAPI.post(user, %{status: ".", in_reply_to_conversation_id: participation.id})
276 assert Visibility.is_direct?(convo_reply)
278 assert activity.data["context"] == convo_reply.data["context"]
281 test "when replying to a conversation / participation, it only mentions the recipients explicitly declared in the participation" do
283 jafnhar = insert(:user)
284 tridi = insert(:user)
287 CommonAPI.post(har, %{
288 status: "@#{jafnhar.nickname} hey",
292 assert har.ap_id in activity.recipients
293 assert jafnhar.ap_id in activity.recipients
295 [participation] = Participation.for_user(har)
298 CommonAPI.post(har, %{
299 status: "I don't really like @#{tridi.nickname}",
300 visibility: "direct",
301 in_reply_to_status_id: activity.id,
302 in_reply_to_conversation_id: participation.id
305 assert har.ap_id in activity.recipients
306 assert jafnhar.ap_id in activity.recipients
307 refute tridi.ap_id in activity.recipients
310 test "with the safe_dm_mention option set, it does not mention people beyond the initial tags" do
312 jafnhar = insert(:user)
313 tridi = insert(:user)
315 Pleroma.Config.put([:instance, :safe_dm_mentions], true)
318 CommonAPI.post(har, %{
319 status: "@#{jafnhar.nickname} hey, i never want to see @#{tridi.nickname} again",
323 refute tridi.ap_id in activity.recipients
324 assert jafnhar.ap_id in activity.recipients
327 test "it de-duplicates tags" do
329 {:ok, activity} = CommonAPI.post(user, %{status: "#2hu #2HU"})
331 object = Object.normalize(activity)
333 assert object.data["tag"] == ["2hu"]
336 test "it adds emoji in the object" do
338 {:ok, activity} = CommonAPI.post(user, %{status: ":firefox:"})
340 assert Object.normalize(activity).data["emoji"]["firefox"]
343 describe "posting" do
344 test "it supports explicit addressing" do
346 user_two = insert(:user)
347 user_three = insert(:user)
348 user_four = insert(:user)
351 CommonAPI.post(user, %{
353 "Hey, I think @#{user_three.nickname} is ugly. @#{user_four.nickname} is alright though.",
354 to: [user_two.nickname, user_four.nickname, "nonexistent"]
357 assert user.ap_id in activity.recipients
358 assert user_two.ap_id in activity.recipients
359 assert user_four.ap_id in activity.recipients
360 refute user_three.ap_id in activity.recipients
363 test "it filters out obviously bad tags when accepting a post as HTML" do
366 post = "<p><b>2hu</b></p><script>alert('xss')</script>"
369 CommonAPI.post(user, %{
371 content_type: "text/html"
374 object = Object.normalize(activity)
376 assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
379 test "it filters out obviously bad tags when accepting a post as Markdown" do
382 post = "<p><b>2hu</b></p><script>alert('xss')</script>"
385 CommonAPI.post(user, %{
387 content_type: "text/markdown"
390 object = Object.normalize(activity)
392 assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
395 test "it does not allow replies to direct messages that are not direct messages themselves" do
398 {:ok, activity} = CommonAPI.post(user, %{status: "suya..", visibility: "direct"})
401 CommonAPI.post(user, %{
403 visibility: "direct",
404 in_reply_to_status_id: activity.id
407 Enum.each(["public", "private", "unlisted"], fn visibility ->
408 assert {:error, "The message visibility must be direct"} =
409 CommonAPI.post(user, %{
411 visibility: visibility,
412 in_reply_to_status_id: activity.id
417 test "replying with a direct message will NOT auto-add the author of the reply to the recipient list" do
419 other_user = insert(:user)
420 third_user = insert(:user)
422 {:ok, post} = CommonAPI.post(user, %{status: "I'm stupid"})
425 CommonAPI.post(other_user, %{status: "No ur smart", in_reply_to_status_id: post.id})
427 # The OP is implicitly added
428 assert user.ap_id in open_answer.recipients
430 {:ok, secret_answer} =
431 CommonAPI.post(other_user, %{
432 status: "lol, that guy really is stupid, right, @#{third_user.nickname}?",
433 in_reply_to_status_id: post.id,
437 assert third_user.ap_id in secret_answer.recipients
439 # The OP is not added
440 refute user.ap_id in secret_answer.recipients
443 test "it allows to address a list" do
445 {:ok, list} = Pleroma.List.create("foo", user)
447 {:ok, activity} = CommonAPI.post(user, %{status: "foobar", visibility: "list:#{list.id}"})
449 assert activity.data["bcc"] == [list.ap_id]
450 assert activity.recipients == [list.ap_id, user.ap_id]
451 assert activity.data["listMessage"] == list.ap_id
454 test "it returns error when status is empty and no attachments" do
457 assert {:error, "Cannot post an empty status without attachments"} =
458 CommonAPI.post(user, %{status: ""})
461 test "it validates character limits are correctly enforced" do
462 Pleroma.Config.put([:instance, :limit], 5)
466 assert {:error, "The status is over the character limit"} =
467 CommonAPI.post(user, %{status: "foobar"})
469 assert {:ok, activity} = CommonAPI.post(user, %{status: "12345"})
472 test "it can handle activities that expire" do
476 NaiveDateTime.utc_now()
477 |> NaiveDateTime.truncate(:second)
478 |> NaiveDateTime.add(1_000_000, :second)
480 assert {:ok, activity} = CommonAPI.post(user, %{status: "chai", expires_in: 1_000_000})
482 assert expiration = Pleroma.ActivityExpiration.get_by_activity_id(activity.id)
483 assert expiration.scheduled_at == expires_at
487 describe "reactions" do
488 test "reacting to a status with an emoji" do
490 other_user = insert(:user)
492 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
494 {:ok, reaction} = CommonAPI.react_with_emoji(activity.id, user, "👍")
496 assert reaction.data["actor"] == user.ap_id
497 assert reaction.data["content"] == "👍"
499 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
501 {:error, _} = CommonAPI.react_with_emoji(activity.id, user, ".")
504 test "unreacting to a status with an emoji" do
506 other_user = insert(:user)
508 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
509 {:ok, reaction} = CommonAPI.react_with_emoji(activity.id, user, "👍")
511 {:ok, unreaction} = CommonAPI.unreact_with_emoji(activity.id, user, "👍")
513 assert unreaction.data["type"] == "Undo"
514 assert unreaction.data["object"] == reaction.data["id"]
515 assert unreaction.local
518 test "repeating a status" do
520 other_user = insert(:user)
522 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
524 {:ok, %Activity{} = announce_activity} = CommonAPI.repeat(activity.id, user)
525 assert Visibility.is_public?(announce_activity)
528 test "can't repeat a repeat" do
530 other_user = insert(:user)
531 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
533 {:ok, %Activity{} = announce} = CommonAPI.repeat(activity.id, other_user)
535 refute match?({:ok, %Activity{}}, CommonAPI.repeat(announce.id, user))
538 test "repeating a status privately" do
540 other_user = insert(:user)
542 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
544 {:ok, %Activity{} = announce_activity} =
545 CommonAPI.repeat(activity.id, user, %{visibility: "private"})
547 assert Visibility.is_private?(announce_activity)
548 refute Visibility.visible_for_user?(announce_activity, nil)
551 test "favoriting a status" do
553 other_user = insert(:user)
555 {:ok, post_activity} = CommonAPI.post(other_user, %{status: "cofe"})
557 {:ok, %Activity{data: data}} = CommonAPI.favorite(user, post_activity.id)
558 assert data["type"] == "Like"
559 assert data["actor"] == user.ap_id
560 assert data["object"] == post_activity.data["object"]
563 test "retweeting a status twice returns the status" do
565 other_user = insert(:user)
567 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
568 {:ok, %Activity{} = announce} = CommonAPI.repeat(activity.id, user)
569 {:ok, ^announce} = CommonAPI.repeat(activity.id, user)
572 test "favoriting a status twice returns ok, but without the like activity" do
574 other_user = insert(:user)
576 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
577 {:ok, %Activity{}} = CommonAPI.favorite(user, activity.id)
578 assert {:ok, :already_liked} = CommonAPI.favorite(user, activity.id)
582 describe "pinned statuses" do
584 Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
587 {:ok, activity} = CommonAPI.post(user, %{status: "HI!!!"})
589 [user: user, activity: activity]
592 test "pin status", %{user: user, activity: activity} do
593 assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
596 user = refresh_record(user)
598 assert %User{pinned_activities: [^id]} = user
601 test "pin poll", %{user: user} do
603 CommonAPI.post(user, %{
604 status: "How is fediverse today?",
605 poll: %{options: ["Absolutely outstanding", "Not good"], expires_in: 20}
608 assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
611 user = refresh_record(user)
613 assert %User{pinned_activities: [^id]} = user
616 test "unlisted statuses can be pinned", %{user: user} do
617 {:ok, activity} = CommonAPI.post(user, %{status: "HI!!!", visibility: "unlisted"})
618 assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
621 test "only self-authored can be pinned", %{activity: activity} do
624 assert {:error, "Could not pin"} = CommonAPI.pin(activity.id, user)
627 test "max pinned statuses", %{user: user, activity: activity_one} do
628 {:ok, activity_two} = CommonAPI.post(user, %{status: "HI!!!"})
630 assert {:ok, ^activity_one} = CommonAPI.pin(activity_one.id, user)
632 user = refresh_record(user)
634 assert {:error, "You have already pinned the maximum number of statuses"} =
635 CommonAPI.pin(activity_two.id, user)
638 test "unpin status", %{user: user, activity: activity} do
639 {:ok, activity} = CommonAPI.pin(activity.id, user)
641 user = refresh_record(user)
645 assert match?({:ok, %{id: ^id}}, CommonAPI.unpin(activity.id, user))
647 user = refresh_record(user)
649 assert %User{pinned_activities: []} = user
652 test "should unpin when deleting a status", %{user: user, activity: activity} do
653 {:ok, activity} = CommonAPI.pin(activity.id, user)
655 user = refresh_record(user)
657 assert {:ok, _} = CommonAPI.delete(activity.id, user)
659 user = refresh_record(user)
661 assert %User{pinned_activities: []} = user
665 describe "mute tests" do
669 activity = insert(:note_activity)
671 [user: user, activity: activity]
674 test "add mute", %{user: user, activity: activity} do
675 {:ok, _} = CommonAPI.add_mute(user, activity)
676 assert CommonAPI.thread_muted?(user, activity)
679 test "remove mute", %{user: user, activity: activity} do
680 CommonAPI.add_mute(user, activity)
681 {:ok, _} = CommonAPI.remove_mute(user, activity)
682 refute CommonAPI.thread_muted?(user, activity)
685 test "check that mutes can't be duplicate", %{user: user, activity: activity} do
686 CommonAPI.add_mute(user, activity)
687 {:error, _} = CommonAPI.add_mute(user, activity)
691 describe "reports" do
692 test "creates a report" do
693 reporter = insert(:user)
694 target_user = insert(:user)
696 {:ok, activity} = CommonAPI.post(target_user, %{status: "foobar"})
698 reporter_ap_id = reporter.ap_id
699 target_ap_id = target_user.ap_id
700 activity_ap_id = activity.data["id"]
704 account_id: target_user.id,
706 status_ids: [activity.id]
711 "id" => activity_ap_id,
712 "content" => "foobar",
713 "published" => activity.object.data["published"],
714 "actor" => AccountView.render("show.json", %{user: target_user})
717 assert {:ok, flag_activity} = CommonAPI.report(reporter, report_data)
720 actor: ^reporter_ap_id,
723 "content" => ^comment,
724 "object" => [^target_ap_id, ^note_obj],
730 test "updates report state" do
731 [reporter, target_user] = insert_pair(:user)
732 activity = insert(:note_activity, user: target_user)
734 {:ok, %Activity{id: report_id}} =
735 CommonAPI.report(reporter, %{
736 account_id: target_user.id,
737 comment: "I feel offended",
738 status_ids: [activity.id]
741 {:ok, report} = CommonAPI.update_report_state(report_id, "resolved")
743 assert report.data["state"] == "resolved"
745 [reported_user, activity_id] = report.data["object"]
747 assert reported_user == target_user.ap_id
748 assert activity_id == activity.data["id"]
751 test "does not update report state when state is unsupported" do
752 [reporter, target_user] = insert_pair(:user)
753 activity = insert(:note_activity, user: target_user)
755 {:ok, %Activity{id: report_id}} =
756 CommonAPI.report(reporter, %{
757 account_id: target_user.id,
758 comment: "I feel offended",
759 status_ids: [activity.id]
762 assert CommonAPI.update_report_state(report_id, "test") == {:error, "Unsupported state"}
765 test "updates state of multiple reports" do
766 [reporter, target_user] = insert_pair(:user)
767 activity = insert(:note_activity, user: target_user)
769 {:ok, %Activity{id: first_report_id}} =
770 CommonAPI.report(reporter, %{
771 account_id: target_user.id,
772 comment: "I feel offended",
773 status_ids: [activity.id]
776 {:ok, %Activity{id: second_report_id}} =
777 CommonAPI.report(reporter, %{
778 account_id: target_user.id,
779 comment: "I feel very offended!",
780 status_ids: [activity.id]
784 CommonAPI.update_report_state([first_report_id, second_report_id], "resolved")
786 first_report = Activity.get_by_id(first_report_id)
787 second_report = Activity.get_by_id(second_report_id)
789 assert report_ids -- [first_report_id, second_report_id] == []
790 assert first_report.data["state"] == "resolved"
791 assert second_report.data["state"] == "resolved"
795 describe "reblog muting" do
797 muter = insert(:user)
799 muted = insert(:user)
801 [muter: muter, muted: muted]
804 test "add a reblog mute", %{muter: muter, muted: muted} do
805 {:ok, _reblog_mute} = CommonAPI.hide_reblogs(muter, muted)
807 assert User.showing_reblogs?(muter, muted) == false
810 test "remove a reblog mute", %{muter: muter, muted: muted} do
811 {:ok, _reblog_mute} = CommonAPI.hide_reblogs(muter, muted)
812 {:ok, _reblog_mute} = CommonAPI.show_reblogs(muter, muted)
814 assert User.showing_reblogs?(muter, muted) == true
818 describe "unfollow/2" do
819 test "also unsubscribes a user" do
820 [follower, followed] = insert_pair(:user)
821 {:ok, follower, followed, _} = CommonAPI.follow(follower, followed)
822 {:ok, _subscription} = User.subscribe(follower, followed)
824 assert User.subscribed_to?(follower, followed)
826 {:ok, follower} = CommonAPI.unfollow(follower, followed)
828 refute User.subscribed_to?(follower, followed)
831 test "cancels a pending follow for a local user" do
832 follower = insert(:user)
833 followed = insert(:user, locked: true)
835 assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} =
836 CommonAPI.follow(follower, followed)
838 assert User.get_follow_state(follower, followed) == :follow_pending
839 assert {:ok, follower} = CommonAPI.unfollow(follower, followed)
840 assert User.get_follow_state(follower, followed) == nil
842 assert %{id: ^activity_id, data: %{"state" => "cancelled"}} =
843 Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(follower, followed)
848 "object" => %{"type" => "Follow", "state" => "cancelled"}
850 } = Pleroma.Web.ActivityPub.Utils.fetch_latest_undo(follower)
853 test "cancels a pending follow for a remote user" do
854 follower = insert(:user)
855 followed = insert(:user, locked: true, local: false, ap_enabled: true)
857 assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} =
858 CommonAPI.follow(follower, followed)
860 assert User.get_follow_state(follower, followed) == :follow_pending
861 assert {:ok, follower} = CommonAPI.unfollow(follower, followed)
862 assert User.get_follow_state(follower, followed) == nil
864 assert %{id: ^activity_id, data: %{"state" => "cancelled"}} =
865 Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(follower, followed)
870 "object" => %{"type" => "Follow", "state" => "cancelled"}
872 } = Pleroma.Web.ActivityPub.Utils.fetch_latest_undo(follower)
876 describe "accept_follow_request/2" do
877 test "after acceptance, it sets all existing pending follow request states to 'accept'" do
878 user = insert(:user, locked: true)
879 follower = insert(:user)
880 follower_two = insert(:user)
882 {:ok, follow_activity} = ActivityPub.follow(follower, user)
883 {:ok, follow_activity_two} = ActivityPub.follow(follower, user)
884 {:ok, follow_activity_three} = ActivityPub.follow(follower_two, user)
886 assert follow_activity.data["state"] == "pending"
887 assert follow_activity_two.data["state"] == "pending"
888 assert follow_activity_three.data["state"] == "pending"
890 {:ok, _follower} = CommonAPI.accept_follow_request(follower, user)
892 assert Repo.get(Activity, follow_activity.id).data["state"] == "accept"
893 assert Repo.get(Activity, follow_activity_two.id).data["state"] == "accept"
894 assert Repo.get(Activity, follow_activity_three.id).data["state"] == "pending"
897 test "after rejection, it sets all existing pending follow request states to 'reject'" do
898 user = insert(:user, locked: true)
899 follower = insert(:user)
900 follower_two = insert(:user)
902 {:ok, follow_activity} = ActivityPub.follow(follower, user)
903 {:ok, follow_activity_two} = ActivityPub.follow(follower, user)
904 {:ok, follow_activity_three} = ActivityPub.follow(follower_two, user)
906 assert follow_activity.data["state"] == "pending"
907 assert follow_activity_two.data["state"] == "pending"
908 assert follow_activity_three.data["state"] == "pending"
910 {:ok, _follower} = CommonAPI.reject_follow_request(follower, user)
912 assert Repo.get(Activity, follow_activity.id).data["state"] == "reject"
913 assert Repo.get(Activity, follow_activity_two.id).data["state"] == "reject"
914 assert Repo.get(Activity, follow_activity_three.id).data["state"] == "pending"
917 test "doesn't create a following relationship if the corresponding follow request doesn't exist" do
918 user = insert(:user, locked: true)
919 not_follower = insert(:user)
920 CommonAPI.accept_follow_request(not_follower, user)
922 assert Pleroma.FollowingRelationship.following?(not_follower, user) == false
927 test "does not allow to vote twice" do
929 other_user = insert(:user)
932 CommonAPI.post(user, %{
933 status: "Am I cute?",
934 poll: %{options: ["Yes", "No"], expires_in: 20}
937 object = Object.normalize(activity)
939 {:ok, _, object} = CommonAPI.vote(other_user, object, [0])
941 assert {:error, "Already voted"} == CommonAPI.vote(other_user, object, [1])
945 describe "listen/2" do
946 test "returns a valid activity" do
950 CommonAPI.listen(user, %{
951 title: "lain radio episode 1",
957 object = Object.normalize(activity)
959 assert object.data["title"] == "lain radio episode 1"
961 assert Visibility.get_visibility(activity) == "public"
964 test "respects visibility=private" do
968 CommonAPI.listen(user, %{
969 title: "lain radio episode 1",
973 visibility: "private"
976 object = Object.normalize(activity)
978 assert object.data["title"] == "lain radio episode 1"
980 assert Visibility.get_visibility(activity) == "private"