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 Object.normalize(post, false)
122 with_mock Pleroma.Web.Federator,
123 publish: fn _ -> nil end do
124 assert {:ok, delete} = CommonAPI.delete(post.id, user)
126 assert called(Pleroma.Web.Federator.publish(delete))
129 refute Activity.get_by_id(post.id)
132 test "it allows users to delete their posts" do
135 {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
137 with_mock Pleroma.Web.Federator,
138 publish: fn _ -> nil end do
139 assert {:ok, delete} = CommonAPI.delete(post.id, user)
141 assert called(Pleroma.Web.Federator.publish(delete))
144 refute Activity.get_by_id(post.id)
147 test "it does not allow a user to delete their posts" do
149 other_user = insert(:user)
151 {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
153 assert {:error, "Could not delete"} = CommonAPI.delete(post.id, other_user)
154 assert Activity.get_by_id(post.id)
157 test "it allows moderators to delete other user's posts" do
159 moderator = insert(:user, is_moderator: true)
161 {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
163 assert {:ok, delete} = CommonAPI.delete(post.id, moderator)
166 refute Activity.get_by_id(post.id)
169 test "it allows admins to delete other user's posts" do
171 moderator = insert(:user, is_admin: true)
173 {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
175 assert {:ok, delete} = CommonAPI.delete(post.id, moderator)
178 refute Activity.get_by_id(post.id)
181 test "superusers deleting non-local posts won't federate the delete" do
182 # This is the user of the ingested activity
186 ap_id: "http://mastodon.example.org/users/admin",
187 last_refreshed_at: NaiveDateTime.utc_now()
190 moderator = insert(:user, is_admin: true)
193 File.read!("test/fixtures/mastodon-post-activity.json")
196 {:ok, post} = Transmogrifier.handle_incoming(data)
198 with_mock Pleroma.Web.Federator,
199 publish: fn _ -> nil end do
200 assert {:ok, delete} = CommonAPI.delete(post.id, moderator)
202 refute called(Pleroma.Web.Federator.publish(:_))
205 refute Activity.get_by_id(post.id)
209 test "favoriting race condition" do
211 users_serial = insert_list(10, :user)
212 users = insert_list(10, :user)
214 {:ok, activity} = CommonAPI.post(user, %{status: "."})
217 |> Enum.map(fn user ->
218 CommonAPI.favorite(user, activity.id)
221 object = Object.get_by_ap_id(activity.data["object"])
222 assert object.data["like_count"] == 10
225 |> Enum.map(fn user ->
227 CommonAPI.favorite(user, activity.id)
230 |> Enum.map(&Task.await/1)
232 object = Object.get_by_ap_id(activity.data["object"])
233 assert object.data["like_count"] == 20
236 test "repeating 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.repeat(activity.id, user)
248 object = Object.get_by_ap_id(activity.data["object"])
249 assert object.data["announcement_count"] == 10
252 |> Enum.map(fn user ->
254 CommonAPI.repeat(activity.id, user)
257 |> Enum.map(&Task.await/1)
259 object = Object.get_by_ap_id(activity.data["object"])
260 assert object.data["announcement_count"] == 20
263 test "when replying to a conversation / participation, it will set the correct context id even if no explicit reply_to is given" do
265 {:ok, activity} = CommonAPI.post(user, %{status: ".", visibility: "direct"})
267 [participation] = Participation.for_user(user)
270 CommonAPI.post(user, %{status: ".", in_reply_to_conversation_id: participation.id})
272 assert Visibility.is_direct?(convo_reply)
274 assert activity.data["context"] == convo_reply.data["context"]
277 test "when replying to a conversation / participation, it only mentions the recipients explicitly declared in the participation" do
279 jafnhar = insert(:user)
280 tridi = insert(:user)
283 CommonAPI.post(har, %{
284 status: "@#{jafnhar.nickname} hey",
288 assert har.ap_id in activity.recipients
289 assert jafnhar.ap_id in activity.recipients
291 [participation] = Participation.for_user(har)
294 CommonAPI.post(har, %{
295 status: "I don't really like @#{tridi.nickname}",
296 visibility: "direct",
297 in_reply_to_status_id: activity.id,
298 in_reply_to_conversation_id: participation.id
301 assert har.ap_id in activity.recipients
302 assert jafnhar.ap_id in activity.recipients
303 refute tridi.ap_id in activity.recipients
306 test "with the safe_dm_mention option set, it does not mention people beyond the initial tags" do
308 jafnhar = insert(:user)
309 tridi = insert(:user)
311 Pleroma.Config.put([:instance, :safe_dm_mentions], true)
314 CommonAPI.post(har, %{
315 status: "@#{jafnhar.nickname} hey, i never want to see @#{tridi.nickname} again",
319 refute tridi.ap_id in activity.recipients
320 assert jafnhar.ap_id in activity.recipients
323 test "it de-duplicates tags" do
325 {:ok, activity} = CommonAPI.post(user, %{status: "#2hu #2HU"})
327 object = Object.normalize(activity)
329 assert object.data["tag"] == ["2hu"]
332 test "it adds emoji in the object" do
334 {:ok, activity} = CommonAPI.post(user, %{status: ":firefox:"})
336 assert Object.normalize(activity).data["emoji"]["firefox"]
339 describe "posting" do
340 test "it supports explicit addressing" do
342 user_two = insert(:user)
343 user_three = insert(:user)
344 user_four = insert(:user)
347 CommonAPI.post(user, %{
349 "Hey, I think @#{user_three.nickname} is ugly. @#{user_four.nickname} is alright though.",
350 to: [user_two.nickname, user_four.nickname, "nonexistent"]
353 assert user.ap_id in activity.recipients
354 assert user_two.ap_id in activity.recipients
355 assert user_four.ap_id in activity.recipients
356 refute user_three.ap_id in activity.recipients
359 test "it filters out obviously bad tags when accepting a post as HTML" do
362 post = "<p><b>2hu</b></p><script>alert('xss')</script>"
365 CommonAPI.post(user, %{
367 content_type: "text/html"
370 object = Object.normalize(activity)
372 assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
375 test "it filters out obviously bad tags when accepting a post as Markdown" do
378 post = "<p><b>2hu</b></p><script>alert('xss')</script>"
381 CommonAPI.post(user, %{
383 content_type: "text/markdown"
386 object = Object.normalize(activity)
388 assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
391 test "it does not allow replies to direct messages that are not direct messages themselves" do
394 {:ok, activity} = CommonAPI.post(user, %{status: "suya..", visibility: "direct"})
397 CommonAPI.post(user, %{
399 visibility: "direct",
400 in_reply_to_status_id: activity.id
403 Enum.each(["public", "private", "unlisted"], fn visibility ->
404 assert {:error, "The message visibility must be direct"} =
405 CommonAPI.post(user, %{
407 visibility: visibility,
408 in_reply_to_status_id: activity.id
413 test "it allows to address a list" do
415 {:ok, list} = Pleroma.List.create("foo", user)
417 {:ok, activity} = CommonAPI.post(user, %{status: "foobar", visibility: "list:#{list.id}"})
419 assert activity.data["bcc"] == [list.ap_id]
420 assert activity.recipients == [list.ap_id, user.ap_id]
421 assert activity.data["listMessage"] == list.ap_id
424 test "it returns error when status is empty and no attachments" do
427 assert {:error, "Cannot post an empty status without attachments"} =
428 CommonAPI.post(user, %{status: ""})
431 test "it validates character limits are correctly enforced" do
432 Pleroma.Config.put([:instance, :limit], 5)
436 assert {:error, "The status is over the character limit"} =
437 CommonAPI.post(user, %{status: "foobar"})
439 assert {:ok, activity} = CommonAPI.post(user, %{status: "12345"})
442 test "it can handle activities that expire" do
446 NaiveDateTime.utc_now()
447 |> NaiveDateTime.truncate(:second)
448 |> NaiveDateTime.add(1_000_000, :second)
450 assert {:ok, activity} = CommonAPI.post(user, %{status: "chai", expires_in: 1_000_000})
452 assert expiration = Pleroma.ActivityExpiration.get_by_activity_id(activity.id)
453 assert expiration.scheduled_at == expires_at
457 describe "reactions" do
458 test "reacting to a status with an emoji" do
460 other_user = insert(:user)
462 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
464 {:ok, reaction} = CommonAPI.react_with_emoji(activity.id, user, "👍")
466 assert reaction.data["actor"] == user.ap_id
467 assert reaction.data["content"] == "👍"
469 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
471 {:error, _} = CommonAPI.react_with_emoji(activity.id, user, ".")
474 test "unreacting to a status with an emoji" do
476 other_user = insert(:user)
478 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
479 {:ok, reaction} = CommonAPI.react_with_emoji(activity.id, user, "👍")
481 {:ok, unreaction} = CommonAPI.unreact_with_emoji(activity.id, user, "👍")
483 assert unreaction.data["type"] == "Undo"
484 assert unreaction.data["object"] == reaction.data["id"]
485 assert unreaction.local
488 test "repeating a status" do
490 other_user = insert(:user)
492 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
494 {:ok, %Activity{}, _} = CommonAPI.repeat(activity.id, user)
497 test "can't repeat a repeat" do
499 other_user = insert(:user)
500 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
502 {:ok, %Activity{} = announce, _} = CommonAPI.repeat(activity.id, other_user)
504 refute match?({:ok, %Activity{}, _}, CommonAPI.repeat(announce.id, user))
507 test "repeating a status privately" do
509 other_user = insert(:user)
511 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
513 {:ok, %Activity{} = announce_activity, _} =
514 CommonAPI.repeat(activity.id, user, %{visibility: "private"})
516 assert Visibility.is_private?(announce_activity)
519 test "favoriting a status" do
521 other_user = insert(:user)
523 {:ok, post_activity} = CommonAPI.post(other_user, %{status: "cofe"})
525 {:ok, %Activity{data: data}} = CommonAPI.favorite(user, post_activity.id)
526 assert data["type"] == "Like"
527 assert data["actor"] == user.ap_id
528 assert data["object"] == post_activity.data["object"]
531 test "retweeting a status twice returns the status" do
533 other_user = insert(:user)
535 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
536 {:ok, %Activity{} = announce, object} = CommonAPI.repeat(activity.id, user)
537 {:ok, ^announce, ^object} = CommonAPI.repeat(activity.id, user)
540 test "favoriting a status twice returns ok, but without the like activity" do
542 other_user = insert(:user)
544 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
545 {:ok, %Activity{}} = CommonAPI.favorite(user, activity.id)
546 assert {:ok, :already_liked} = CommonAPI.favorite(user, activity.id)
550 describe "pinned statuses" do
552 Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
555 {:ok, activity} = CommonAPI.post(user, %{status: "HI!!!"})
557 [user: user, activity: activity]
560 test "pin status", %{user: user, activity: activity} do
561 assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
564 user = refresh_record(user)
566 assert %User{pinned_activities: [^id]} = user
569 test "pin poll", %{user: user} do
571 CommonAPI.post(user, %{
572 status: "How is fediverse today?",
573 poll: %{options: ["Absolutely outstanding", "Not good"], expires_in: 20}
576 assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
579 user = refresh_record(user)
581 assert %User{pinned_activities: [^id]} = user
584 test "unlisted statuses can be pinned", %{user: user} do
585 {:ok, activity} = CommonAPI.post(user, %{status: "HI!!!", visibility: "unlisted"})
586 assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
589 test "only self-authored can be pinned", %{activity: activity} do
592 assert {:error, "Could not pin"} = CommonAPI.pin(activity.id, user)
595 test "max pinned statuses", %{user: user, activity: activity_one} do
596 {:ok, activity_two} = CommonAPI.post(user, %{status: "HI!!!"})
598 assert {:ok, ^activity_one} = CommonAPI.pin(activity_one.id, user)
600 user = refresh_record(user)
602 assert {:error, "You have already pinned the maximum number of statuses"} =
603 CommonAPI.pin(activity_two.id, user)
606 test "unpin status", %{user: user, activity: activity} do
607 {:ok, activity} = CommonAPI.pin(activity.id, user)
609 user = refresh_record(user)
613 assert match?({:ok, %{id: ^id}}, CommonAPI.unpin(activity.id, user))
615 user = refresh_record(user)
617 assert %User{pinned_activities: []} = user
620 test "should unpin when deleting a status", %{user: user, activity: activity} do
621 {:ok, activity} = CommonAPI.pin(activity.id, user)
623 user = refresh_record(user)
625 assert {:ok, _} = CommonAPI.delete(activity.id, user)
627 user = refresh_record(user)
629 assert %User{pinned_activities: []} = user
633 describe "mute tests" do
637 activity = insert(:note_activity)
639 [user: user, activity: activity]
642 test "add mute", %{user: user, activity: activity} do
643 {:ok, _} = CommonAPI.add_mute(user, activity)
644 assert CommonAPI.thread_muted?(user, activity)
647 test "remove mute", %{user: user, activity: activity} do
648 CommonAPI.add_mute(user, activity)
649 {:ok, _} = CommonAPI.remove_mute(user, activity)
650 refute CommonAPI.thread_muted?(user, activity)
653 test "check that mutes can't be duplicate", %{user: user, activity: activity} do
654 CommonAPI.add_mute(user, activity)
655 {:error, _} = CommonAPI.add_mute(user, activity)
659 describe "reports" do
660 test "creates a report" do
661 reporter = insert(:user)
662 target_user = insert(:user)
664 {:ok, activity} = CommonAPI.post(target_user, %{status: "foobar"})
666 reporter_ap_id = reporter.ap_id
667 target_ap_id = target_user.ap_id
668 activity_ap_id = activity.data["id"]
672 account_id: target_user.id,
674 status_ids: [activity.id]
679 "id" => activity_ap_id,
680 "content" => "foobar",
681 "published" => activity.object.data["published"],
682 "actor" => AccountView.render("show.json", %{user: target_user})
685 assert {:ok, flag_activity} = CommonAPI.report(reporter, report_data)
688 actor: ^reporter_ap_id,
691 "content" => ^comment,
692 "object" => [^target_ap_id, ^note_obj],
698 test "updates report state" do
699 [reporter, target_user] = insert_pair(:user)
700 activity = insert(:note_activity, user: target_user)
702 {:ok, %Activity{id: report_id}} =
703 CommonAPI.report(reporter, %{
704 account_id: target_user.id,
705 comment: "I feel offended",
706 status_ids: [activity.id]
709 {:ok, report} = CommonAPI.update_report_state(report_id, "resolved")
711 assert report.data["state"] == "resolved"
713 [reported_user, activity_id] = report.data["object"]
715 assert reported_user == target_user.ap_id
716 assert activity_id == activity.data["id"]
719 test "does not update report state when state is unsupported" do
720 [reporter, target_user] = insert_pair(:user)
721 activity = insert(:note_activity, user: target_user)
723 {:ok, %Activity{id: report_id}} =
724 CommonAPI.report(reporter, %{
725 account_id: target_user.id,
726 comment: "I feel offended",
727 status_ids: [activity.id]
730 assert CommonAPI.update_report_state(report_id, "test") == {:error, "Unsupported state"}
733 test "updates state of multiple reports" do
734 [reporter, target_user] = insert_pair(:user)
735 activity = insert(:note_activity, user: target_user)
737 {:ok, %Activity{id: first_report_id}} =
738 CommonAPI.report(reporter, %{
739 account_id: target_user.id,
740 comment: "I feel offended",
741 status_ids: [activity.id]
744 {:ok, %Activity{id: second_report_id}} =
745 CommonAPI.report(reporter, %{
746 account_id: target_user.id,
747 comment: "I feel very offended!",
748 status_ids: [activity.id]
752 CommonAPI.update_report_state([first_report_id, second_report_id], "resolved")
754 first_report = Activity.get_by_id(first_report_id)
755 second_report = Activity.get_by_id(second_report_id)
757 assert report_ids -- [first_report_id, second_report_id] == []
758 assert first_report.data["state"] == "resolved"
759 assert second_report.data["state"] == "resolved"
763 describe "reblog muting" do
765 muter = insert(:user)
767 muted = insert(:user)
769 [muter: muter, muted: muted]
772 test "add a reblog mute", %{muter: muter, muted: muted} do
773 {:ok, _reblog_mute} = CommonAPI.hide_reblogs(muter, muted)
775 assert User.showing_reblogs?(muter, muted) == false
778 test "remove a reblog mute", %{muter: muter, muted: muted} do
779 {:ok, _reblog_mute} = CommonAPI.hide_reblogs(muter, muted)
780 {:ok, _reblog_mute} = CommonAPI.show_reblogs(muter, muted)
782 assert User.showing_reblogs?(muter, muted) == true
786 describe "unfollow/2" do
787 test "also unsubscribes a user" do
788 [follower, followed] = insert_pair(:user)
789 {:ok, follower, followed, _} = CommonAPI.follow(follower, followed)
790 {:ok, _subscription} = User.subscribe(follower, followed)
792 assert User.subscribed_to?(follower, followed)
794 {:ok, follower} = CommonAPI.unfollow(follower, followed)
796 refute User.subscribed_to?(follower, followed)
799 test "cancels a pending follow for a local user" do
800 follower = insert(:user)
801 followed = insert(:user, locked: true)
803 assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} =
804 CommonAPI.follow(follower, followed)
806 assert User.get_follow_state(follower, followed) == :follow_pending
807 assert {:ok, follower} = CommonAPI.unfollow(follower, followed)
808 assert User.get_follow_state(follower, followed) == nil
810 assert %{id: ^activity_id, data: %{"state" => "cancelled"}} =
811 Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(follower, followed)
816 "object" => %{"type" => "Follow", "state" => "cancelled"}
818 } = Pleroma.Web.ActivityPub.Utils.fetch_latest_undo(follower)
821 test "cancels a pending follow for a remote user" do
822 follower = insert(:user)
823 followed = insert(:user, locked: true, local: false, ap_enabled: true)
825 assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} =
826 CommonAPI.follow(follower, followed)
828 assert User.get_follow_state(follower, followed) == :follow_pending
829 assert {:ok, follower} = CommonAPI.unfollow(follower, followed)
830 assert User.get_follow_state(follower, followed) == nil
832 assert %{id: ^activity_id, data: %{"state" => "cancelled"}} =
833 Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(follower, followed)
838 "object" => %{"type" => "Follow", "state" => "cancelled"}
840 } = Pleroma.Web.ActivityPub.Utils.fetch_latest_undo(follower)
844 describe "accept_follow_request/2" do
845 test "after acceptance, it sets all existing pending follow request states to 'accept'" do
846 user = insert(:user, locked: true)
847 follower = insert(:user)
848 follower_two = insert(:user)
850 {:ok, follow_activity} = ActivityPub.follow(follower, user)
851 {:ok, follow_activity_two} = ActivityPub.follow(follower, user)
852 {:ok, follow_activity_three} = ActivityPub.follow(follower_two, user)
854 assert follow_activity.data["state"] == "pending"
855 assert follow_activity_two.data["state"] == "pending"
856 assert follow_activity_three.data["state"] == "pending"
858 {:ok, _follower} = CommonAPI.accept_follow_request(follower, user)
860 assert Repo.get(Activity, follow_activity.id).data["state"] == "accept"
861 assert Repo.get(Activity, follow_activity_two.id).data["state"] == "accept"
862 assert Repo.get(Activity, follow_activity_three.id).data["state"] == "pending"
865 test "after rejection, it sets all existing pending follow request states to 'reject'" do
866 user = insert(:user, locked: true)
867 follower = insert(:user)
868 follower_two = insert(:user)
870 {:ok, follow_activity} = ActivityPub.follow(follower, user)
871 {:ok, follow_activity_two} = ActivityPub.follow(follower, user)
872 {:ok, follow_activity_three} = ActivityPub.follow(follower_two, user)
874 assert follow_activity.data["state"] == "pending"
875 assert follow_activity_two.data["state"] == "pending"
876 assert follow_activity_three.data["state"] == "pending"
878 {:ok, _follower} = CommonAPI.reject_follow_request(follower, user)
880 assert Repo.get(Activity, follow_activity.id).data["state"] == "reject"
881 assert Repo.get(Activity, follow_activity_two.id).data["state"] == "reject"
882 assert Repo.get(Activity, follow_activity_three.id).data["state"] == "pending"
885 test "doesn't create a following relationship if the corresponding follow request doesn't exist" do
886 user = insert(:user, locked: true)
887 not_follower = insert(:user)
888 CommonAPI.accept_follow_request(not_follower, user)
890 assert Pleroma.FollowingRelationship.following?(not_follower, user) == false
895 test "does not allow to vote twice" do
897 other_user = insert(:user)
900 CommonAPI.post(user, %{
901 status: "Am I cute?",
902 poll: %{options: ["Yes", "No"], expires_in: 20}
905 object = Object.normalize(activity)
907 {:ok, _, object} = CommonAPI.vote(other_user, object, [0])
909 assert {:error, "Already voted"} == CommonAPI.vote(other_user, object, [1])
913 describe "listen/2" do
914 test "returns a valid activity" do
918 CommonAPI.listen(user, %{
919 title: "lain radio episode 1",
925 object = Object.normalize(activity)
927 assert object.data["title"] == "lain radio episode 1"
929 assert Visibility.get_visibility(activity) == "public"
932 test "respects visibility=private" do
936 CommonAPI.listen(user, %{
937 title: "lain radio episode 1",
941 visibility: "private"
944 object = Object.normalize(activity)
946 assert object.data["title"] == "lain radio episode 1"
948 assert Visibility.get_visibility(activity) == "private"