object = Repo.insert!(%Object{data: object_data})
input = %{
- "status" => "Hello again, @shp.<script></script>",
+ "status" => "Hello again, @shp.<script></script>\nThis is on another line.",
"media_ids" => [object.id]
}
{ :ok, activity = %Activity{} } = TwitterAPI.create_status(user, input)
- assert get_in(activity.data, ["object", "content"]) == "Hello again, <a href='shp'>@shp</a>."
+ assert get_in(activity.data, ["object", "content"]) == "Hello again, <a href='shp'>@shp</a>.<br>This is on another line."
assert get_in(activity.data, ["object", "type"]) == "Note"
assert get_in(activity.data, ["object", "actor"]) == user.ap_id
assert get_in(activity.data, ["actor"]) == user.ap_id
test "fetch public statuses" do
%{ public: activity, user: user } = ActivityBuilder.public_and_non_public
- {:ok, follower } = UserBuilder.insert(%{name: "dude", ap_id: "idididid", following: [User.ap_followers(user)]})
+
+ follower = insert(:user, following: [User.ap_followers(user)])
statuses = TwitterAPI.fetch_public_statuses(follower)
end
test "fetch friends' statuses" do
- ActivityBuilder.public_and_non_public
-
+ user = insert(:user, %{following: ["someguy/followers"]})
{:ok, activity} = ActivityBuilder.insert(%{"to" => ["someguy/followers"]})
- {:ok, direct_activity} = ActivityBuilder.insert(%{"to" => ["some other id"]})
- {:ok, user} = UserBuilder.insert(%{ap_id: "some other id", following: ["someguy/followers"]})
+ {:ok, direct_activity} = ActivityBuilder.insert(%{"to" => [user.ap_id]})
statuses = TwitterAPI.fetch_friend_statuses(user)
activity_user = Repo.get_by(User, ap_id: activity.data["actor"])
+ direct_activity_user = Repo.get_by(User, ap_id: direct_activity.data["actor"])
assert length(statuses) == 2
assert Enum.at(statuses, 0) == ActivityRepresenter.to_map(activity, %{user: activity_user})
- assert Enum.at(statuses, 1) == ActivityRepresenter.to_map(direct_activity, %{user: activity_user, mentioned: [user]})
+ assert Enum.at(statuses, 1) == ActivityRepresenter.to_map(direct_activity, %{user: direct_activity_user, mentioned: [user]})
end
test "fetch a single status" do
end
test "Follow another user" do
- { :ok, user } = UserBuilder.insert
- { :ok, following } = UserBuilder.insert(%{nickname: "guy"})
+ user = insert(:user)
+ followed = insert(:user)
- {:ok, user, following, activity } = TwitterAPI.follow(user, following.id)
+ { :ok, user, followed, activity } = TwitterAPI.follow(user, followed.id)
user = Repo.get(User, user.id)
follow = Repo.get(Activity, activity.id)
- assert user.following == [User.ap_followers(following)]
+ assert user.following == [User.ap_followers(followed)]
assert follow == activity
+
+ { :error, msg } = TwitterAPI.follow(user, followed.id)
+ assert msg == "Could not follow user: #{followed.nickname} is already on your list."
end
test "Unfollow another user" do
- { :ok, following } = UserBuilder.insert(%{nickname: "guy"})
- { :ok, user } = UserBuilder.insert(%{following: [User.ap_followers(following)]})
+ followed = insert(:user)
+ user = insert(:user, %{following: [User.ap_followers(followed)]})
- {:ok, user, _following } = TwitterAPI.unfollow(user, following.id)
+ { :ok, user, _followed } = TwitterAPI.unfollow(user, followed.id)
user = Repo.get(User, user.id)
assert user.following == []
+ { :error, msg } = TwitterAPI.unfollow(user, followed.id)
+ assert msg == "Not subscribed!"
end
test "fetch statuses in a context using the conversation id" do
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"})
+ gsimg = insert(:user, %{nickname: "gsimg"})
+ archaeme = insert(:user, %{nickname: "archaeme"})
expected_result = [
{"@gsimg", gsimg},
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"})
+ gsimg = insert(:user, %{nickname: "gsimg"})
+ archaeme = insert(:user, %{nickname: "archaeme"})
mentions = TwitterAPI.parse_mentions(text)
- expected_text = "<a href='first_link'>@gsimg</a> According to <a href='second_link'>@archaeme</a> , that is @daggsy."
+ expected_text = "<a href='#{gsimg.ap_id}'>@gsimg</a> According to <a href='#{archaeme.ap_id}'>@archaeme</a> , that is @daggsy."
assert TwitterAPI.add_user_links(text, mentions) == expected_text
end
end
setup do
- Supervisor.terminate_child(Pleroma.Supervisor, ConCache)
- Supervisor.restart_child(Pleroma.Supervisor, ConCache)
+ Supervisor.terminate_child(Pleroma.Supervisor, Cachex)
+ Supervisor.restart_child(Pleroma.Supervisor, Cachex)
:ok
end
end