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 "deletion" do
102 test "it works with pruned objects" do
105 {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
107 Object.normalize(post, false)
110 with_mock Pleroma.Web.Federator,
111 publish: fn _ -> nil end do
112 assert {:ok, delete} = CommonAPI.delete(post.id, user)
114 assert called(Pleroma.Web.Federator.publish(delete))
117 refute Activity.get_by_id(post.id)
120 test "it allows users to delete their posts" do
123 {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
125 with_mock Pleroma.Web.Federator,
126 publish: fn _ -> nil end do
127 assert {:ok, delete} = CommonAPI.delete(post.id, user)
129 assert called(Pleroma.Web.Federator.publish(delete))
132 refute Activity.get_by_id(post.id)
135 test "it does not allow a user to delete their posts" do
137 other_user = insert(:user)
139 {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
141 assert {:error, "Could not delete"} = CommonAPI.delete(post.id, other_user)
142 assert Activity.get_by_id(post.id)
145 test "it allows moderators to delete other user's posts" do
147 moderator = insert(:user, is_moderator: true)
149 {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
151 assert {:ok, delete} = CommonAPI.delete(post.id, moderator)
154 refute Activity.get_by_id(post.id)
157 test "it allows admins to delete other user's posts" do
159 moderator = insert(:user, is_admin: 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 "superusers deleting non-local posts won't federate the delete" do
170 # This is the user of the ingested activity
174 ap_id: "http://mastodon.example.org/users/admin",
175 last_refreshed_at: NaiveDateTime.utc_now()
178 moderator = insert(:user, is_admin: true)
181 File.read!("test/fixtures/mastodon-post-activity.json")
184 {:ok, post} = Transmogrifier.handle_incoming(data)
186 with_mock Pleroma.Web.Federator,
187 publish: fn _ -> nil end do
188 assert {:ok, delete} = CommonAPI.delete(post.id, moderator)
190 refute called(Pleroma.Web.Federator.publish(:_))
193 refute Activity.get_by_id(post.id)
197 test "favoriting race condition" do
199 users_serial = insert_list(10, :user)
200 users = insert_list(10, :user)
202 {:ok, activity} = CommonAPI.post(user, %{status: "."})
205 |> Enum.map(fn user ->
206 CommonAPI.favorite(user, activity.id)
209 object = Object.get_by_ap_id(activity.data["object"])
210 assert object.data["like_count"] == 10
213 |> Enum.map(fn user ->
215 CommonAPI.favorite(user, activity.id)
218 |> Enum.map(&Task.await/1)
220 object = Object.get_by_ap_id(activity.data["object"])
221 assert object.data["like_count"] == 20
224 test "repeating race condition" do
226 users_serial = insert_list(10, :user)
227 users = insert_list(10, :user)
229 {:ok, activity} = CommonAPI.post(user, %{status: "."})
232 |> Enum.map(fn user ->
233 CommonAPI.repeat(activity.id, user)
236 object = Object.get_by_ap_id(activity.data["object"])
237 assert object.data["announcement_count"] == 10
240 |> Enum.map(fn user ->
242 CommonAPI.repeat(activity.id, user)
245 |> Enum.map(&Task.await/1)
247 object = Object.get_by_ap_id(activity.data["object"])
248 assert object.data["announcement_count"] == 20
251 test "when replying to a conversation / participation, it will set the correct context id even if no explicit reply_to is given" do
253 {:ok, activity} = CommonAPI.post(user, %{status: ".", visibility: "direct"})
255 [participation] = Participation.for_user(user)
258 CommonAPI.post(user, %{status: ".", in_reply_to_conversation_id: participation.id})
260 assert Visibility.is_direct?(convo_reply)
262 assert activity.data["context"] == convo_reply.data["context"]
265 test "when replying to a conversation / participation, it only mentions the recipients explicitly declared in the participation" do
267 jafnhar = insert(:user)
268 tridi = insert(:user)
271 CommonAPI.post(har, %{
272 status: "@#{jafnhar.nickname} hey",
276 assert har.ap_id in activity.recipients
277 assert jafnhar.ap_id in activity.recipients
279 [participation] = Participation.for_user(har)
282 CommonAPI.post(har, %{
283 status: "I don't really like @#{tridi.nickname}",
284 visibility: "direct",
285 in_reply_to_status_id: activity.id,
286 in_reply_to_conversation_id: participation.id
289 assert har.ap_id in activity.recipients
290 assert jafnhar.ap_id in activity.recipients
291 refute tridi.ap_id in activity.recipients
294 test "with the safe_dm_mention option set, it does not mention people beyond the initial tags" do
296 jafnhar = insert(:user)
297 tridi = insert(:user)
299 Pleroma.Config.put([:instance, :safe_dm_mentions], true)
302 CommonAPI.post(har, %{
303 status: "@#{jafnhar.nickname} hey, i never want to see @#{tridi.nickname} again",
307 refute tridi.ap_id in activity.recipients
308 assert jafnhar.ap_id in activity.recipients
311 test "it de-duplicates tags" do
313 {:ok, activity} = CommonAPI.post(user, %{status: "#2hu #2HU"})
315 object = Object.normalize(activity)
317 assert object.data["tag"] == ["2hu"]
320 test "it adds emoji in the object" do
322 {:ok, activity} = CommonAPI.post(user, %{status: ":firefox:"})
324 assert Object.normalize(activity).data["emoji"]["firefox"]
327 describe "posting" do
328 test "it supports explicit addressing" do
330 user_two = insert(:user)
331 user_three = insert(:user)
332 user_four = insert(:user)
335 CommonAPI.post(user, %{
337 "Hey, I think @#{user_three.nickname} is ugly. @#{user_four.nickname} is alright though.",
338 to: [user_two.nickname, user_four.nickname, "nonexistent"]
341 assert user.ap_id in activity.recipients
342 assert user_two.ap_id in activity.recipients
343 assert user_four.ap_id in activity.recipients
344 refute user_three.ap_id in activity.recipients
347 test "it filters out obviously bad tags when accepting a post as HTML" do
350 post = "<p><b>2hu</b></p><script>alert('xss')</script>"
353 CommonAPI.post(user, %{
355 content_type: "text/html"
358 object = Object.normalize(activity)
360 assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
363 test "it filters out obviously bad tags when accepting a post as Markdown" do
366 post = "<p><b>2hu</b></p><script>alert('xss')</script>"
369 CommonAPI.post(user, %{
371 content_type: "text/markdown"
374 object = Object.normalize(activity)
376 assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
379 test "it does not allow replies to direct messages that are not direct messages themselves" do
382 {:ok, activity} = CommonAPI.post(user, %{status: "suya..", visibility: "direct"})
385 CommonAPI.post(user, %{
387 visibility: "direct",
388 in_reply_to_status_id: activity.id
391 Enum.each(["public", "private", "unlisted"], fn visibility ->
392 assert {:error, "The message visibility must be direct"} =
393 CommonAPI.post(user, %{
395 visibility: visibility,
396 in_reply_to_status_id: activity.id
401 test "it allows to address a list" do
403 {:ok, list} = Pleroma.List.create("foo", user)
405 {:ok, activity} = CommonAPI.post(user, %{status: "foobar", visibility: "list:#{list.id}"})
407 assert activity.data["bcc"] == [list.ap_id]
408 assert activity.recipients == [list.ap_id, user.ap_id]
409 assert activity.data["listMessage"] == list.ap_id
412 test "it returns error when status is empty and no attachments" do
415 assert {:error, "Cannot post an empty status without attachments"} =
416 CommonAPI.post(user, %{status: ""})
419 test "it validates character limits are correctly enforced" do
420 Pleroma.Config.put([:instance, :limit], 5)
424 assert {:error, "The status is over the character limit"} =
425 CommonAPI.post(user, %{status: "foobar"})
427 assert {:ok, activity} = CommonAPI.post(user, %{status: "12345"})
430 test "it can handle activities that expire" do
434 NaiveDateTime.utc_now()
435 |> NaiveDateTime.truncate(:second)
436 |> NaiveDateTime.add(1_000_000, :second)
438 assert {:ok, activity} = CommonAPI.post(user, %{status: "chai", expires_in: 1_000_000})
440 assert expiration = Pleroma.ActivityExpiration.get_by_activity_id(activity.id)
441 assert expiration.scheduled_at == expires_at
445 describe "reactions" do
446 test "reacting to a status with an emoji" do
448 other_user = insert(:user)
450 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
452 {:ok, reaction} = CommonAPI.react_with_emoji(activity.id, user, "👍")
454 assert reaction.data["actor"] == user.ap_id
455 assert reaction.data["content"] == "👍"
457 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
459 {:error, _} = CommonAPI.react_with_emoji(activity.id, user, ".")
462 test "unreacting to a status with an emoji" do
464 other_user = insert(:user)
466 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
467 {:ok, reaction} = CommonAPI.react_with_emoji(activity.id, user, "👍")
469 {:ok, unreaction} = CommonAPI.unreact_with_emoji(activity.id, user, "👍")
471 assert unreaction.data["type"] == "Undo"
472 assert unreaction.data["object"] == reaction.data["id"]
473 assert unreaction.local
476 test "repeating a status" do
478 other_user = insert(:user)
480 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
482 {:ok, %Activity{}, _} = CommonAPI.repeat(activity.id, user)
485 test "can't repeat a repeat" do
487 other_user = insert(:user)
488 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
490 {:ok, %Activity{} = announce, _} = CommonAPI.repeat(activity.id, other_user)
492 refute match?({:ok, %Activity{}, _}, CommonAPI.repeat(announce.id, user))
495 test "repeating a status privately" do
497 other_user = insert(:user)
499 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
501 {:ok, %Activity{} = announce_activity, _} =
502 CommonAPI.repeat(activity.id, user, %{visibility: "private"})
504 assert Visibility.is_private?(announce_activity)
507 test "favoriting a status" do
509 other_user = insert(:user)
511 {:ok, post_activity} = CommonAPI.post(other_user, %{status: "cofe"})
513 {:ok, %Activity{data: data}} = CommonAPI.favorite(user, post_activity.id)
514 assert data["type"] == "Like"
515 assert data["actor"] == user.ap_id
516 assert data["object"] == post_activity.data["object"]
519 test "retweeting a status twice returns the status" do
521 other_user = insert(:user)
523 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
524 {:ok, %Activity{} = announce, object} = CommonAPI.repeat(activity.id, user)
525 {:ok, ^announce, ^object} = CommonAPI.repeat(activity.id, user)
528 test "favoriting a status twice returns ok, but without the like activity" do
530 other_user = insert(:user)
532 {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
533 {:ok, %Activity{}} = CommonAPI.favorite(user, activity.id)
534 assert {:ok, :already_liked} = CommonAPI.favorite(user, activity.id)
538 describe "pinned statuses" do
540 Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
543 {:ok, activity} = CommonAPI.post(user, %{status: "HI!!!"})
545 [user: user, activity: activity]
548 test "pin status", %{user: user, activity: activity} do
549 assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
552 user = refresh_record(user)
554 assert %User{pinned_activities: [^id]} = user
557 test "pin poll", %{user: user} do
559 CommonAPI.post(user, %{
560 status: "How is fediverse today?",
561 poll: %{options: ["Absolutely outstanding", "Not good"], expires_in: 20}
564 assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
567 user = refresh_record(user)
569 assert %User{pinned_activities: [^id]} = user
572 test "unlisted statuses can be pinned", %{user: user} do
573 {:ok, activity} = CommonAPI.post(user, %{status: "HI!!!", visibility: "unlisted"})
574 assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
577 test "only self-authored can be pinned", %{activity: activity} do
580 assert {:error, "Could not pin"} = CommonAPI.pin(activity.id, user)
583 test "max pinned statuses", %{user: user, activity: activity_one} do
584 {:ok, activity_two} = CommonAPI.post(user, %{status: "HI!!!"})
586 assert {:ok, ^activity_one} = CommonAPI.pin(activity_one.id, user)
588 user = refresh_record(user)
590 assert {:error, "You have already pinned the maximum number of statuses"} =
591 CommonAPI.pin(activity_two.id, user)
594 test "unpin status", %{user: user, activity: activity} do
595 {:ok, activity} = CommonAPI.pin(activity.id, user)
597 user = refresh_record(user)
601 assert match?({:ok, %{id: ^id}}, CommonAPI.unpin(activity.id, user))
603 user = refresh_record(user)
605 assert %User{pinned_activities: []} = user
608 test "should unpin when deleting a status", %{user: user, activity: activity} do
609 {:ok, activity} = CommonAPI.pin(activity.id, user)
611 user = refresh_record(user)
613 assert {:ok, _} = CommonAPI.delete(activity.id, user)
615 user = refresh_record(user)
617 assert %User{pinned_activities: []} = user
621 describe "mute tests" do
625 activity = insert(:note_activity)
627 [user: user, activity: activity]
630 test "add mute", %{user: user, activity: activity} do
631 {:ok, _} = CommonAPI.add_mute(user, activity)
632 assert CommonAPI.thread_muted?(user, activity)
635 test "remove mute", %{user: user, activity: activity} do
636 CommonAPI.add_mute(user, activity)
637 {:ok, _} = CommonAPI.remove_mute(user, activity)
638 refute CommonAPI.thread_muted?(user, activity)
641 test "check that mutes can't be duplicate", %{user: user, activity: activity} do
642 CommonAPI.add_mute(user, activity)
643 {:error, _} = CommonAPI.add_mute(user, activity)
647 describe "reports" do
648 test "creates a report" do
649 reporter = insert(:user)
650 target_user = insert(:user)
652 {:ok, activity} = CommonAPI.post(target_user, %{status: "foobar"})
654 reporter_ap_id = reporter.ap_id
655 target_ap_id = target_user.ap_id
656 activity_ap_id = activity.data["id"]
660 account_id: target_user.id,
662 status_ids: [activity.id]
667 "id" => activity_ap_id,
668 "content" => "foobar",
669 "published" => activity.object.data["published"],
670 "actor" => AccountView.render("show.json", %{user: target_user})
673 assert {:ok, flag_activity} = CommonAPI.report(reporter, report_data)
676 actor: ^reporter_ap_id,
679 "content" => ^comment,
680 "object" => [^target_ap_id, ^note_obj],
686 test "updates report state" 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 {:ok, report} = CommonAPI.update_report_state(report_id, "resolved")
699 assert report.data["state"] == "resolved"
701 [reported_user, activity_id] = report.data["object"]
703 assert reported_user == target_user.ap_id
704 assert activity_id == activity.data["id"]
707 test "does not update report state when state is unsupported" do
708 [reporter, target_user] = insert_pair(:user)
709 activity = insert(:note_activity, user: target_user)
711 {:ok, %Activity{id: report_id}} =
712 CommonAPI.report(reporter, %{
713 account_id: target_user.id,
714 comment: "I feel offended",
715 status_ids: [activity.id]
718 assert CommonAPI.update_report_state(report_id, "test") == {:error, "Unsupported state"}
721 test "updates state of multiple reports" do
722 [reporter, target_user] = insert_pair(:user)
723 activity = insert(:note_activity, user: target_user)
725 {:ok, %Activity{id: first_report_id}} =
726 CommonAPI.report(reporter, %{
727 account_id: target_user.id,
728 comment: "I feel offended",
729 status_ids: [activity.id]
732 {:ok, %Activity{id: second_report_id}} =
733 CommonAPI.report(reporter, %{
734 account_id: target_user.id,
735 comment: "I feel very offended!",
736 status_ids: [activity.id]
740 CommonAPI.update_report_state([first_report_id, second_report_id], "resolved")
742 first_report = Activity.get_by_id(first_report_id)
743 second_report = Activity.get_by_id(second_report_id)
745 assert report_ids -- [first_report_id, second_report_id] == []
746 assert first_report.data["state"] == "resolved"
747 assert second_report.data["state"] == "resolved"
751 describe "reblog muting" do
753 muter = insert(:user)
755 muted = insert(:user)
757 [muter: muter, muted: muted]
760 test "add a reblog mute", %{muter: muter, muted: muted} do
761 {:ok, _reblog_mute} = CommonAPI.hide_reblogs(muter, muted)
763 assert User.showing_reblogs?(muter, muted) == false
766 test "remove a reblog mute", %{muter: muter, muted: muted} do
767 {:ok, _reblog_mute} = CommonAPI.hide_reblogs(muter, muted)
768 {:ok, _reblog_mute} = CommonAPI.show_reblogs(muter, muted)
770 assert User.showing_reblogs?(muter, muted) == true
774 describe "unfollow/2" do
775 test "also unsubscribes a user" do
776 [follower, followed] = insert_pair(:user)
777 {:ok, follower, followed, _} = CommonAPI.follow(follower, followed)
778 {:ok, _subscription} = User.subscribe(follower, followed)
780 assert User.subscribed_to?(follower, followed)
782 {:ok, follower} = CommonAPI.unfollow(follower, followed)
784 refute User.subscribed_to?(follower, followed)
787 test "cancels a pending follow for a local user" do
788 follower = insert(:user)
789 followed = insert(:user, locked: true)
791 assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} =
792 CommonAPI.follow(follower, followed)
794 assert User.get_follow_state(follower, followed) == :follow_pending
795 assert {:ok, follower} = CommonAPI.unfollow(follower, followed)
796 assert User.get_follow_state(follower, followed) == nil
798 assert %{id: ^activity_id, data: %{"state" => "cancelled"}} =
799 Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(follower, followed)
804 "object" => %{"type" => "Follow", "state" => "cancelled"}
806 } = Pleroma.Web.ActivityPub.Utils.fetch_latest_undo(follower)
809 test "cancels a pending follow for a remote user" do
810 follower = insert(:user)
811 followed = insert(:user, locked: true, local: false, ap_enabled: true)
813 assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} =
814 CommonAPI.follow(follower, followed)
816 assert User.get_follow_state(follower, followed) == :follow_pending
817 assert {:ok, follower} = CommonAPI.unfollow(follower, followed)
818 assert User.get_follow_state(follower, followed) == nil
820 assert %{id: ^activity_id, data: %{"state" => "cancelled"}} =
821 Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(follower, followed)
826 "object" => %{"type" => "Follow", "state" => "cancelled"}
828 } = Pleroma.Web.ActivityPub.Utils.fetch_latest_undo(follower)
832 describe "accept_follow_request/2" do
833 test "after acceptance, it sets all existing pending follow request states to 'accept'" do
834 user = insert(:user, locked: true)
835 follower = insert(:user)
836 follower_two = insert(:user)
838 {:ok, follow_activity} = ActivityPub.follow(follower, user)
839 {:ok, follow_activity_two} = ActivityPub.follow(follower, user)
840 {:ok, follow_activity_three} = ActivityPub.follow(follower_two, user)
842 assert follow_activity.data["state"] == "pending"
843 assert follow_activity_two.data["state"] == "pending"
844 assert follow_activity_three.data["state"] == "pending"
846 {:ok, _follower} = CommonAPI.accept_follow_request(follower, user)
848 assert Repo.get(Activity, follow_activity.id).data["state"] == "accept"
849 assert Repo.get(Activity, follow_activity_two.id).data["state"] == "accept"
850 assert Repo.get(Activity, follow_activity_three.id).data["state"] == "pending"
853 test "after rejection, it sets all existing pending follow request states to 'reject'" do
854 user = insert(:user, locked: true)
855 follower = insert(:user)
856 follower_two = insert(:user)
858 {:ok, follow_activity} = ActivityPub.follow(follower, user)
859 {:ok, follow_activity_two} = ActivityPub.follow(follower, user)
860 {:ok, follow_activity_three} = ActivityPub.follow(follower_two, user)
862 assert follow_activity.data["state"] == "pending"
863 assert follow_activity_two.data["state"] == "pending"
864 assert follow_activity_three.data["state"] == "pending"
866 {:ok, _follower} = CommonAPI.reject_follow_request(follower, user)
868 assert Repo.get(Activity, follow_activity.id).data["state"] == "reject"
869 assert Repo.get(Activity, follow_activity_two.id).data["state"] == "reject"
870 assert Repo.get(Activity, follow_activity_three.id).data["state"] == "pending"
873 test "doesn't create a following relationship if the corresponding follow request doesn't exist" do
874 user = insert(:user, locked: true)
875 not_follower = insert(:user)
876 CommonAPI.accept_follow_request(not_follower, user)
878 assert Pleroma.FollowingRelationship.following?(not_follower, user) == false
883 test "does not allow to vote twice" do
885 other_user = insert(:user)
888 CommonAPI.post(user, %{
889 status: "Am I cute?",
890 poll: %{options: ["Yes", "No"], expires_in: 20}
893 object = Object.normalize(activity)
895 {:ok, _, object} = CommonAPI.vote(other_user, object, [0])
897 assert {:error, "Already voted"} == CommonAPI.vote(other_user, object, [1])
901 describe "listen/2" do
902 test "returns a valid activity" do
906 CommonAPI.listen(user, %{
907 "title" => "lain radio episode 1",
908 "album" => "lain radio",
913 object = Object.normalize(activity)
915 assert object.data["title"] == "lain radio episode 1"
917 assert Visibility.get_visibility(activity) == "public"
920 test "respects visibility=private" do
924 CommonAPI.listen(user, %{
925 "title" => "lain radio episode 1",
926 "album" => "lain radio",
929 "visibility" => "private"
932 object = Object.normalize(activity)
934 assert object.data["title"] == "lain radio episode 1"
936 assert Visibility.get_visibility(activity) == "private"