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" do
31 author = insert(:user)
32 recipient = insert(:user)
35 CommonAPI.post_chat_message(
38 "a test message <script>alert('uuu')</script> :firefox:"
41 assert activity.data["type"] == "Create"
43 object = Object.normalize(activity)
45 assert object.data["type"] == "ChatMessage"
46 assert object.data["to"] == [recipient.ap_id]
48 assert object.data["content"] ==
49 "a test message <script>alert('uuu')</script> :firefox:"
51 assert object.data["emoji"] == %{
52 "firefox" => "http://localhost:4001/emoji/Firefox.gif"
55 assert Chat.get(author.id, recipient.ap_id)
56 assert Chat.get(recipient.id, author.ap_id)
58 assert :ok == Pleroma.Web.Federator.perform(:publish, activity)
61 test "it reject messages over the local limit" do
62 Pleroma.Config.put([:instance, :chat_limit], 2)
64 author = insert(:user)
65 recipient = insert(:user)
68 CommonAPI.post_chat_message(
74 assert message == :content_too_long
78 describe "deletion" do
79 test "it works with pruned objects" do
82 {:ok, post} = CommonAPI.post(user, %{"status" => "namu amida butsu"})
84 Object.normalize(post, false)
87 with_mock Pleroma.Web.Federator,
88 publish: fn _ -> nil end do
89 assert {:ok, delete} = CommonAPI.delete(post.id, user)
91 assert called(Pleroma.Web.Federator.publish(delete))
94 refute Activity.get_by_id(post.id)
97 test "it allows users to delete their posts" do
100 {:ok, post} = CommonAPI.post(user, %{"status" => "namu amida butsu"})
102 with_mock Pleroma.Web.Federator,
103 publish: fn _ -> nil end do
104 assert {:ok, delete} = CommonAPI.delete(post.id, user)
106 assert called(Pleroma.Web.Federator.publish(delete))
109 refute Activity.get_by_id(post.id)
112 test "it does not allow a user to delete their posts" do
114 other_user = insert(:user)
116 {:ok, post} = CommonAPI.post(user, %{"status" => "namu amida butsu"})
118 assert {:error, "Could not delete"} = CommonAPI.delete(post.id, other_user)
119 assert Activity.get_by_id(post.id)
122 test "it allows moderators to delete other user's posts" do
124 moderator = insert(:user, is_moderator: true)
126 {:ok, post} = CommonAPI.post(user, %{"status" => "namu amida butsu"})
128 assert {:ok, delete} = CommonAPI.delete(post.id, moderator)
131 refute Activity.get_by_id(post.id)
134 test "it allows admins to delete other user's posts" do
136 moderator = insert(:user, is_admin: true)
138 {:ok, post} = CommonAPI.post(user, %{"status" => "namu amida butsu"})
140 assert {:ok, delete} = CommonAPI.delete(post.id, moderator)
143 refute Activity.get_by_id(post.id)
146 test "superusers deleting non-local posts won't federate the delete" do
147 # This is the user of the ingested activity
151 ap_id: "http://mastodon.example.org/users/admin",
152 last_refreshed_at: NaiveDateTime.utc_now()
155 moderator = insert(:user, is_admin: true)
158 File.read!("test/fixtures/mastodon-post-activity.json")
161 {:ok, post} = Transmogrifier.handle_incoming(data)
163 with_mock Pleroma.Web.Federator,
164 publish: fn _ -> nil end do
165 assert {:ok, delete} = CommonAPI.delete(post.id, moderator)
167 refute called(Pleroma.Web.Federator.publish(:_))
170 refute Activity.get_by_id(post.id)
174 test "favoriting race condition" do
176 users_serial = insert_list(10, :user)
177 users = insert_list(10, :user)
179 {:ok, activity} = CommonAPI.post(user, %{"status" => "."})
182 |> Enum.map(fn user ->
183 CommonAPI.favorite(user, activity.id)
186 object = Object.get_by_ap_id(activity.data["object"])
187 assert object.data["like_count"] == 10
190 |> Enum.map(fn user ->
192 CommonAPI.favorite(user, activity.id)
195 |> Enum.map(&Task.await/1)
197 object = Object.get_by_ap_id(activity.data["object"])
198 assert object.data["like_count"] == 20
201 test "repeating race condition" do
203 users_serial = insert_list(10, :user)
204 users = insert_list(10, :user)
206 {:ok, activity} = CommonAPI.post(user, %{"status" => "."})
209 |> Enum.map(fn user ->
210 CommonAPI.repeat(activity.id, user)
213 object = Object.get_by_ap_id(activity.data["object"])
214 assert object.data["announcement_count"] == 10
217 |> Enum.map(fn user ->
219 CommonAPI.repeat(activity.id, user)
222 |> Enum.map(&Task.await/1)
224 object = Object.get_by_ap_id(activity.data["object"])
225 assert object.data["announcement_count"] == 20
228 test "when replying to a conversation / participation, it will set the correct context id even if no explicit reply_to is given" do
230 {:ok, activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
232 [participation] = Participation.for_user(user)
235 CommonAPI.post(user, %{"status" => ".", "in_reply_to_conversation_id" => participation.id})
237 assert Visibility.is_direct?(convo_reply)
239 assert activity.data["context"] == convo_reply.data["context"]
242 test "when replying to a conversation / participation, it only mentions the recipients explicitly declared in the participation" do
244 jafnhar = insert(:user)
245 tridi = insert(:user)
248 CommonAPI.post(har, %{
249 "status" => "@#{jafnhar.nickname} hey",
250 "visibility" => "direct"
253 assert har.ap_id in activity.recipients
254 assert jafnhar.ap_id in activity.recipients
256 [participation] = Participation.for_user(har)
259 CommonAPI.post(har, %{
260 "status" => "I don't really like @#{tridi.nickname}",
261 "visibility" => "direct",
262 "in_reply_to_status_id" => activity.id,
263 "in_reply_to_conversation_id" => participation.id
266 assert har.ap_id in activity.recipients
267 assert jafnhar.ap_id in activity.recipients
268 refute tridi.ap_id in activity.recipients
271 test "with the safe_dm_mention option set, it does not mention people beyond the initial tags" do
273 jafnhar = insert(:user)
274 tridi = insert(:user)
276 Pleroma.Config.put([:instance, :safe_dm_mentions], true)
279 CommonAPI.post(har, %{
280 "status" => "@#{jafnhar.nickname} hey, i never want to see @#{tridi.nickname} again",
281 "visibility" => "direct"
284 refute tridi.ap_id in activity.recipients
285 assert jafnhar.ap_id in activity.recipients
288 test "it de-duplicates tags" do
290 {:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu #2HU"})
292 object = Object.normalize(activity)
294 assert object.data["tag"] == ["2hu"]
297 test "it adds emoji in the object" do
299 {:ok, activity} = CommonAPI.post(user, %{"status" => ":firefox:"})
301 assert Object.normalize(activity).data["emoji"]["firefox"]
304 describe "posting" do
305 test "it supports explicit addressing" do
307 user_two = insert(:user)
308 user_three = insert(:user)
309 user_four = insert(:user)
312 CommonAPI.post(user, %{
314 "Hey, I think @#{user_three.nickname} is ugly. @#{user_four.nickname} is alright though.",
315 "to" => [user_two.nickname, user_four.nickname, "nonexistent"]
318 assert user.ap_id in activity.recipients
319 assert user_two.ap_id in activity.recipients
320 assert user_four.ap_id in activity.recipients
321 refute user_three.ap_id in activity.recipients
324 test "it filters out obviously bad tags when accepting a post as HTML" do
327 post = "<p><b>2hu</b></p><script>alert('xss')</script>"
330 CommonAPI.post(user, %{
332 "content_type" => "text/html"
335 object = Object.normalize(activity)
337 assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
340 test "it filters out obviously bad tags when accepting a post as Markdown" do
343 post = "<p><b>2hu</b></p><script>alert('xss')</script>"
346 CommonAPI.post(user, %{
348 "content_type" => "text/markdown"
351 object = Object.normalize(activity)
353 assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
356 test "it does not allow replies to direct messages that are not direct messages themselves" do
359 {:ok, activity} = CommonAPI.post(user, %{"status" => "suya..", "visibility" => "direct"})
362 CommonAPI.post(user, %{
363 "status" => "suya..",
364 "visibility" => "direct",
365 "in_reply_to_status_id" => activity.id
368 Enum.each(["public", "private", "unlisted"], fn visibility ->
369 assert {:error, "The message visibility must be direct"} =
370 CommonAPI.post(user, %{
371 "status" => "suya..",
372 "visibility" => visibility,
373 "in_reply_to_status_id" => activity.id
378 test "it allows to address a list" do
380 {:ok, list} = Pleroma.List.create("foo", user)
383 CommonAPI.post(user, %{"status" => "foobar", "visibility" => "list:#{list.id}"})
385 assert activity.data["bcc"] == [list.ap_id]
386 assert activity.recipients == [list.ap_id, user.ap_id]
387 assert activity.data["listMessage"] == list.ap_id
390 test "it returns error when status is empty and no attachments" do
393 assert {:error, "Cannot post an empty status without attachments"} =
394 CommonAPI.post(user, %{"status" => ""})
397 test "it validates character limits are correctly enforced" do
398 Pleroma.Config.put([:instance, :limit], 5)
402 assert {:error, "The status is over the character limit"} =
403 CommonAPI.post(user, %{"status" => "foobar"})
405 assert {:ok, activity} = CommonAPI.post(user, %{"status" => "12345"})
408 test "it can handle activities that expire" do
412 NaiveDateTime.utc_now()
413 |> NaiveDateTime.truncate(:second)
414 |> NaiveDateTime.add(1_000_000, :second)
416 assert {:ok, activity} =
417 CommonAPI.post(user, %{"status" => "chai", "expires_in" => 1_000_000})
419 assert expiration = Pleroma.ActivityExpiration.get_by_activity_id(activity.id)
420 assert expiration.scheduled_at == expires_at
424 describe "reactions" do
425 test "reacting to a status with an emoji" do
427 other_user = insert(:user)
429 {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
431 {:ok, reaction} = CommonAPI.react_with_emoji(activity.id, user, "👍")
433 assert reaction.data["actor"] == user.ap_id
434 assert reaction.data["content"] == "👍"
436 {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
438 {:error, _} = CommonAPI.react_with_emoji(activity.id, user, ".")
441 test "unreacting to a status with an emoji" do
443 other_user = insert(:user)
445 {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
446 {:ok, reaction} = CommonAPI.react_with_emoji(activity.id, user, "👍")
448 {:ok, unreaction} = CommonAPI.unreact_with_emoji(activity.id, user, "👍")
450 assert unreaction.data["type"] == "Undo"
451 assert unreaction.data["object"] == reaction.data["id"]
452 assert unreaction.local
455 test "repeating a status" do
457 other_user = insert(:user)
459 {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
461 {:ok, %Activity{}, _} = CommonAPI.repeat(activity.id, user)
464 test "can't repeat a repeat" do
466 other_user = insert(:user)
467 {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
469 {:ok, %Activity{} = announce, _} = CommonAPI.repeat(activity.id, other_user)
471 refute match?({:ok, %Activity{}, _}, CommonAPI.repeat(announce.id, user))
474 test "repeating a status privately" do
476 other_user = insert(:user)
478 {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
480 {:ok, %Activity{} = announce_activity, _} =
481 CommonAPI.repeat(activity.id, user, %{"visibility" => "private"})
483 assert Visibility.is_private?(announce_activity)
486 test "favoriting a status" do
488 other_user = insert(:user)
490 {:ok, post_activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
492 {:ok, %Activity{data: data}} = CommonAPI.favorite(user, post_activity.id)
493 assert data["type"] == "Like"
494 assert data["actor"] == user.ap_id
495 assert data["object"] == post_activity.data["object"]
498 test "retweeting a status twice returns the status" do
500 other_user = insert(:user)
502 {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
503 {:ok, %Activity{} = announce, object} = CommonAPI.repeat(activity.id, user)
504 {:ok, ^announce, ^object} = CommonAPI.repeat(activity.id, user)
507 test "favoriting a status twice returns ok, but without the like activity" do
509 other_user = insert(:user)
511 {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
512 {:ok, %Activity{}} = CommonAPI.favorite(user, activity.id)
513 assert {:ok, :already_liked} = CommonAPI.favorite(user, activity.id)
517 describe "pinned statuses" do
519 Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
522 {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
524 [user: user, activity: activity]
527 test "pin status", %{user: user, activity: activity} do
528 assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
531 user = refresh_record(user)
533 assert %User{pinned_activities: [^id]} = user
536 test "pin poll", %{user: user} do
538 CommonAPI.post(user, %{
539 "status" => "How is fediverse today?",
540 "poll" => %{"options" => ["Absolutely outstanding", "Not good"], "expires_in" => 20}
543 assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
546 user = refresh_record(user)
548 assert %User{pinned_activities: [^id]} = user
551 test "unlisted statuses can be pinned", %{user: user} do
552 {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!", "visibility" => "unlisted"})
553 assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
556 test "only self-authored can be pinned", %{activity: activity} do
559 assert {:error, "Could not pin"} = CommonAPI.pin(activity.id, user)
562 test "max pinned statuses", %{user: user, activity: activity_one} do
563 {:ok, activity_two} = CommonAPI.post(user, %{"status" => "HI!!!"})
565 assert {:ok, ^activity_one} = CommonAPI.pin(activity_one.id, user)
567 user = refresh_record(user)
569 assert {:error, "You have already pinned the maximum number of statuses"} =
570 CommonAPI.pin(activity_two.id, user)
573 test "unpin status", %{user: user, activity: activity} do
574 {:ok, activity} = CommonAPI.pin(activity.id, user)
576 user = refresh_record(user)
580 assert match?({:ok, %{id: ^id}}, CommonAPI.unpin(activity.id, user))
582 user = refresh_record(user)
584 assert %User{pinned_activities: []} = user
587 test "should unpin when deleting a status", %{user: user, activity: activity} do
588 {:ok, activity} = CommonAPI.pin(activity.id, user)
590 user = refresh_record(user)
592 assert {:ok, _} = CommonAPI.delete(activity.id, user)
594 user = refresh_record(user)
596 assert %User{pinned_activities: []} = user
600 describe "mute tests" do
604 activity = insert(:note_activity)
606 [user: user, activity: activity]
609 test "add mute", %{user: user, activity: activity} do
610 {:ok, _} = CommonAPI.add_mute(user, activity)
611 assert CommonAPI.thread_muted?(user, activity)
614 test "remove mute", %{user: user, activity: activity} do
615 CommonAPI.add_mute(user, activity)
616 {:ok, _} = CommonAPI.remove_mute(user, activity)
617 refute CommonAPI.thread_muted?(user, activity)
620 test "check that mutes can't be duplicate", %{user: user, activity: activity} do
621 CommonAPI.add_mute(user, activity)
622 {:error, _} = CommonAPI.add_mute(user, activity)
626 describe "reports" do
627 test "creates a report" do
628 reporter = insert(:user)
629 target_user = insert(:user)
631 {:ok, activity} = CommonAPI.post(target_user, %{"status" => "foobar"})
633 reporter_ap_id = reporter.ap_id
634 target_ap_id = target_user.ap_id
635 activity_ap_id = activity.data["id"]
639 account_id: target_user.id,
641 status_ids: [activity.id]
646 "id" => activity_ap_id,
647 "content" => "foobar",
648 "published" => activity.object.data["published"],
649 "actor" => AccountView.render("show.json", %{user: target_user})
652 assert {:ok, flag_activity} = CommonAPI.report(reporter, report_data)
655 actor: ^reporter_ap_id,
658 "content" => ^comment,
659 "object" => [^target_ap_id, ^note_obj],
665 test "updates report state" do
666 [reporter, target_user] = insert_pair(:user)
667 activity = insert(:note_activity, user: target_user)
669 {:ok, %Activity{id: report_id}} =
670 CommonAPI.report(reporter, %{
671 account_id: target_user.id,
672 comment: "I feel offended",
673 status_ids: [activity.id]
676 {:ok, report} = CommonAPI.update_report_state(report_id, "resolved")
678 assert report.data["state"] == "resolved"
680 [reported_user, activity_id] = report.data["object"]
682 assert reported_user == target_user.ap_id
683 assert activity_id == activity.data["id"]
686 test "does not update report state when state is unsupported" do
687 [reporter, target_user] = insert_pair(:user)
688 activity = insert(:note_activity, user: target_user)
690 {:ok, %Activity{id: report_id}} =
691 CommonAPI.report(reporter, %{
692 account_id: target_user.id,
693 comment: "I feel offended",
694 status_ids: [activity.id]
697 assert CommonAPI.update_report_state(report_id, "test") == {:error, "Unsupported state"}
700 test "updates state of multiple reports" do
701 [reporter, target_user] = insert_pair(:user)
702 activity = insert(:note_activity, user: target_user)
704 {:ok, %Activity{id: first_report_id}} =
705 CommonAPI.report(reporter, %{
706 account_id: target_user.id,
707 comment: "I feel offended",
708 status_ids: [activity.id]
711 {:ok, %Activity{id: second_report_id}} =
712 CommonAPI.report(reporter, %{
713 account_id: target_user.id,
714 comment: "I feel very offended!",
715 status_ids: [activity.id]
719 CommonAPI.update_report_state([first_report_id, second_report_id], "resolved")
721 first_report = Activity.get_by_id(first_report_id)
722 second_report = Activity.get_by_id(second_report_id)
724 assert report_ids -- [first_report_id, second_report_id] == []
725 assert first_report.data["state"] == "resolved"
726 assert second_report.data["state"] == "resolved"
730 describe "reblog muting" do
732 muter = insert(:user)
734 muted = insert(:user)
736 [muter: muter, muted: muted]
739 test "add a reblog mute", %{muter: muter, muted: muted} do
740 {:ok, _reblog_mute} = CommonAPI.hide_reblogs(muter, muted)
742 assert User.showing_reblogs?(muter, muted) == false
745 test "remove a reblog mute", %{muter: muter, muted: muted} do
746 {:ok, _reblog_mute} = CommonAPI.hide_reblogs(muter, muted)
747 {:ok, _reblog_mute} = CommonAPI.show_reblogs(muter, muted)
749 assert User.showing_reblogs?(muter, muted) == true
753 describe "unfollow/2" do
754 test "also unsubscribes a user" do
755 [follower, followed] = insert_pair(:user)
756 {:ok, follower, followed, _} = CommonAPI.follow(follower, followed)
757 {:ok, _subscription} = User.subscribe(follower, followed)
759 assert User.subscribed_to?(follower, followed)
761 {:ok, follower} = CommonAPI.unfollow(follower, followed)
763 refute User.subscribed_to?(follower, followed)
766 test "cancels a pending follow for a local user" do
767 follower = insert(:user)
768 followed = insert(:user, locked: true)
770 assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} =
771 CommonAPI.follow(follower, followed)
773 assert User.get_follow_state(follower, followed) == :follow_pending
774 assert {:ok, follower} = CommonAPI.unfollow(follower, followed)
775 assert User.get_follow_state(follower, followed) == nil
777 assert %{id: ^activity_id, data: %{"state" => "cancelled"}} =
778 Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(follower, followed)
783 "object" => %{"type" => "Follow", "state" => "cancelled"}
785 } = Pleroma.Web.ActivityPub.Utils.fetch_latest_undo(follower)
788 test "cancels a pending follow for a remote user" do
789 follower = insert(:user)
790 followed = insert(:user, locked: true, local: false, ap_enabled: true)
792 assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} =
793 CommonAPI.follow(follower, followed)
795 assert User.get_follow_state(follower, followed) == :follow_pending
796 assert {:ok, follower} = CommonAPI.unfollow(follower, followed)
797 assert User.get_follow_state(follower, followed) == nil
799 assert %{id: ^activity_id, data: %{"state" => "cancelled"}} =
800 Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(follower, followed)
805 "object" => %{"type" => "Follow", "state" => "cancelled"}
807 } = Pleroma.Web.ActivityPub.Utils.fetch_latest_undo(follower)
811 describe "accept_follow_request/2" do
812 test "after acceptance, it sets all existing pending follow request states to 'accept'" do
813 user = insert(:user, locked: true)
814 follower = insert(:user)
815 follower_two = insert(:user)
817 {:ok, follow_activity} = ActivityPub.follow(follower, user)
818 {:ok, follow_activity_two} = ActivityPub.follow(follower, user)
819 {:ok, follow_activity_three} = ActivityPub.follow(follower_two, user)
821 assert follow_activity.data["state"] == "pending"
822 assert follow_activity_two.data["state"] == "pending"
823 assert follow_activity_three.data["state"] == "pending"
825 {:ok, _follower} = CommonAPI.accept_follow_request(follower, user)
827 assert Repo.get(Activity, follow_activity.id).data["state"] == "accept"
828 assert Repo.get(Activity, follow_activity_two.id).data["state"] == "accept"
829 assert Repo.get(Activity, follow_activity_three.id).data["state"] == "pending"
832 test "after rejection, it sets all existing pending follow request states to 'reject'" do
833 user = insert(:user, locked: true)
834 follower = insert(:user)
835 follower_two = insert(:user)
837 {:ok, follow_activity} = ActivityPub.follow(follower, user)
838 {:ok, follow_activity_two} = ActivityPub.follow(follower, user)
839 {:ok, follow_activity_three} = ActivityPub.follow(follower_two, user)
841 assert follow_activity.data["state"] == "pending"
842 assert follow_activity_two.data["state"] == "pending"
843 assert follow_activity_three.data["state"] == "pending"
845 {:ok, _follower} = CommonAPI.reject_follow_request(follower, user)
847 assert Repo.get(Activity, follow_activity.id).data["state"] == "reject"
848 assert Repo.get(Activity, follow_activity_two.id).data["state"] == "reject"
849 assert Repo.get(Activity, follow_activity_three.id).data["state"] == "pending"
852 test "doesn't create a following relationship if the corresponding follow request doesn't exist" do
853 user = insert(:user, locked: true)
854 not_follower = insert(:user)
855 CommonAPI.accept_follow_request(not_follower, user)
857 assert Pleroma.FollowingRelationship.following?(not_follower, user) == false
862 test "does not allow to vote twice" do
864 other_user = insert(:user)
867 CommonAPI.post(user, %{
868 "status" => "Am I cute?",
869 "poll" => %{"options" => ["Yes", "No"], "expires_in" => 20}
872 object = Object.normalize(activity)
874 {:ok, _, object} = CommonAPI.vote(other_user, object, [0])
876 assert {:error, "Already voted"} == CommonAPI.vote(other_user, object, [1])
880 describe "listen/2" do
881 test "returns a valid activity" do
885 CommonAPI.listen(user, %{
886 "title" => "lain radio episode 1",
887 "album" => "lain radio",
892 object = Object.normalize(activity)
894 assert object.data["title"] == "lain radio episode 1"
896 assert Visibility.get_visibility(activity) == "public"
899 test "respects visibility=private" do
903 CommonAPI.listen(user, %{
904 "title" => "lain radio episode 1",
905 "album" => "lain radio",
908 "visibility" => "private"
911 object = Object.normalize(activity)
913 assert object.data["title"] == "lain radio episode 1"
915 assert Visibility.get_visibility(activity) == "private"