+
+ test "it can parse mentions and return the relevant users" do
+ text = "@gsimg According to @archaeme , that is @daggsy."
+
+ {:ok, gsimg} = UserBuilder.insert(%{nickname: "gsimg"})
+ {:ok, archaeme} = UserBuilder.insert(%{nickname: "archaeme"})
+
+ expected_result = [
+ {"@gsimg", gsimg},
+ {"@archaeme", archaeme}
+ ]
+
+ assert TwitterAPI.parse_mentions(text) == expected_result
+ end
+
+ test "it adds user links to an existing text" do
+ text = "@gsimg According to @archaeme , that is @daggsy."
+
+ {:ok, _gsimg} = UserBuilder.insert(%{nickname: "gsimg", ap_id: "first_link" })
+ {:ok, _archaeme} = UserBuilder.insert(%{nickname: "archaeme", ap_id: "second_link"})
+
+ mentions = TwitterAPI.parse_mentions(text)
+ expected_text = "<a href='first_link'>@gsimg</a> According to <a href='second_link'>@archaeme</a> , that is @daggsy."
+
+ assert TwitterAPI.add_user_links(text, mentions) == expected_text
+ end
+
+ test "it favorites a status, returns the updated status" do
+ user = insert(:user)
+ note_activity = insert(:note_activity)
+ activity_user = Repo.get_by!(User, ap_id: note_activity.data["actor"])
+
+ {:ok, status} = TwitterAPI.favorite(user, note_activity)
+ updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
+
+ assert status == ActivityRepresenter.to_map(updated_activity, %{user: activity_user, for: user})
+ end
+
+ test "it unfavorites a status, returns the updated status" do
+ user = insert(:user)
+ note_activity = insert(:note_activity)
+ activity_user = Repo.get_by!(User, ap_id: note_activity.data["actor"])
+ object = Object.get_by_ap_id(note_activity.data["object"]["id"])
+
+ {:ok, like_activity, object } = ActivityPub.like(user, object)
+ updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
+ assert ActivityRepresenter.to_map(updated_activity, %{user: activity_user, for: user})["fave_num"] == 1
+
+ {:ok, status} = TwitterAPI.unfavorite(user, note_activity)
+ updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
+
+ assert status["fave_num"] == 0
+ end
+
+ setup do
+ Supervisor.terminate_child(Pleroma.Supervisor, ConCache)
+ Supervisor.restart_child(Pleroma.Supervisor, ConCache)
+ :ok
+ end