Merge branch 'feature/incoming_ostatus' of ssh.gitgud.io:lambadalambda/pleroma into feature/incoming_ostatus
This commit is contained in:
commit
7561158ab1
10 changed files with 116 additions and 54 deletions
|
|
@ -24,7 +24,8 @@ defmodule Pleroma.Factory do
|
|||
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"published_at" => DateTime.utc_now() |> DateTime.to_iso8601,
|
||||
"likes" => [],
|
||||
"like_count" => 0
|
||||
"like_count" => 0,
|
||||
"context" => "2hu"
|
||||
}
|
||||
|
||||
%Pleroma.Object{
|
||||
|
|
@ -40,7 +41,8 @@ defmodule Pleroma.Factory do
|
|||
"actor" => note.data["actor"],
|
||||
"to" => note.data["to"],
|
||||
"object" => note.data,
|
||||
"published_at" => DateTime.utc_now() |> DateTime.to_iso8601
|
||||
"published_at" => DateTime.utc_now() |> DateTime.to_iso8601,
|
||||
"context" => note.data["context"]
|
||||
}
|
||||
|
||||
%Pleroma.Activity{
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
|
|||
<content type="html">#{note_activity.data["object"]["content"]}</content>
|
||||
<published>#{inserted_at}</published>
|
||||
<updated>#{updated_at}</updated>
|
||||
<ostatus:conversation>#{note_activity.data["context"]}</ostatus:conversation>
|
||||
<link href="#{note_activity.data["context"]}" rel="ostatus:conversation" />
|
||||
"""
|
||||
|
||||
tuple = ActivityRepresenter.to_simple_form(note_activity, user)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ defmodule Pleroma.Web.OStatus.FeedRepresenterTest do
|
|||
|> :xmerl.export_simple_content(:xmerl_xml)
|
||||
|
||||
expected = """
|
||||
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:poco="http://portablecontacts.net/spec/1.0">
|
||||
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:ostatus="http://ostatus.org/schema/1.0">
|
||||
<id>#{OStatus.feed_path(user)}</id>
|
||||
<title>#{user.nickname}'s timeline</title>
|
||||
<updated>#{most_recent_update}</updated>
|
||||
|
|
|
|||
|
|
@ -31,10 +31,21 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
end
|
||||
|
||||
test "with credentials", %{conn: conn, user: user} do
|
||||
conn = conn
|
||||
|> with_credentials(user.nickname, "test")
|
||||
|> post("/api/statuses/update.json", %{ status: "Nice meme." })
|
||||
conn_with_creds = conn |> with_credentials(user.nickname, "test")
|
||||
request_path = "/api/statuses/update.json"
|
||||
|
||||
error_response = %{"request" => request_path,
|
||||
"error" => "Client must provide a 'status' parameter with a value."}
|
||||
conn = conn_with_creds |> post(request_path)
|
||||
assert json_response(conn, 400) == error_response
|
||||
|
||||
conn = conn_with_creds |> post(request_path, %{ status: "" })
|
||||
assert json_response(conn, 400) == error_response
|
||||
|
||||
conn = conn_with_creds |> post(request_path, %{ status: " " })
|
||||
assert json_response(conn, 400) == error_response
|
||||
|
||||
conn = conn_with_creds |> post(request_path, %{ status: "Nice meme." })
|
||||
assert json_response(conn, 200) == ActivityRepresenter.to_map(Repo.one(Activity), %{user: user})
|
||||
end
|
||||
end
|
||||
|
|
@ -139,7 +150,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
setup [:valid_user]
|
||||
test "without any params", %{conn: conn} do
|
||||
conn = get(conn, "/api/statuses/user_timeline.json")
|
||||
assert json_response(conn, 400) == %{"error" => "You need to specify screen_name or user_id"}
|
||||
assert json_response(conn, 400) == %{"error" => "You need to specify screen_name or user_id", "request" => "/api/statuses/user_timeline.json"}
|
||||
end
|
||||
|
||||
test "with user_id", %{conn: conn} do
|
||||
|
|
@ -320,11 +331,21 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
test "with credentials", %{conn: conn, user: current_user} do
|
||||
note_activity = insert(:note_activity)
|
||||
|
||||
conn = conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/statuses/retweet/#{note_activity.id}.json")
|
||||
request_path = "/api/statuses/retweet/#{note_activity.id}.json"
|
||||
|
||||
assert json_response(conn, 200)
|
||||
user = Repo.get_by(User, ap_id: note_activity.data["actor"])
|
||||
response = conn
|
||||
|> with_credentials(user.nickname, "test")
|
||||
|> post(request_path)
|
||||
assert json_response(response, 400) == %{"error" => "You cannot repeat your own notice.",
|
||||
"request" => request_path}
|
||||
|
||||
response = conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post(request_path)
|
||||
activity = Repo.get(Activity, note_activity.id)
|
||||
activity_user = Repo.get_by(User, ap_id: note_activity.data["actor"])
|
||||
assert json_response(response, 200) == ActivityRepresenter.to_map(activity, %{user: activity_user, for: current_user})
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -155,32 +155,47 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
assert status == ActivityRepresenter.to_map(activity, %{for: user, user: actor})
|
||||
end
|
||||
|
||||
test "Follow another user" do
|
||||
test "Follow another user using user_id" do
|
||||
user = insert(:user)
|
||||
followed = insert(:user)
|
||||
|
||||
{ :ok, user, followed, activity } = TwitterAPI.follow(user, followed.id)
|
||||
|
||||
user = Repo.get(User, user.id)
|
||||
follow = Repo.get(Activity, activity.id)
|
||||
|
||||
{:ok, user, followed, _activity } = TwitterAPI.follow(user, %{"user_id" => followed.id})
|
||||
assert user.following == [User.ap_followers(followed)]
|
||||
assert follow == activity
|
||||
|
||||
{ :error, msg } = TwitterAPI.follow(user, followed.id)
|
||||
{ :error, msg } = TwitterAPI.follow(user, %{"user_id" => followed.id})
|
||||
assert msg == "Could not follow user: #{followed.nickname} is already on your list."
|
||||
end
|
||||
|
||||
test "Unfollow another user" do
|
||||
test "Follow another user using screen_name" do
|
||||
user = insert(:user)
|
||||
followed = insert(:user)
|
||||
user = insert(:user, %{following: [User.ap_followers(followed)]})
|
||||
|
||||
{ :ok, user, _followed } = TwitterAPI.unfollow(user, followed.id)
|
||||
{:ok, user, followed, _activity } = TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
|
||||
assert user.following == [User.ap_followers(followed)]
|
||||
|
||||
user = Repo.get(User, user.id)
|
||||
{ :error, msg } = TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
|
||||
assert msg == "Could not follow user: #{followed.nickname} is already on your list."
|
||||
end
|
||||
|
||||
test "Unfollow another user using user_id" do
|
||||
unfollowed = insert(:user)
|
||||
user = insert(:user, %{following: [User.ap_followers(unfollowed)]})
|
||||
|
||||
{:ok, user, unfollowed } = TwitterAPI.unfollow(user, %{"user_id" => unfollowed.id})
|
||||
assert user.following == []
|
||||
{ :error, msg } = TwitterAPI.unfollow(user, followed.id)
|
||||
|
||||
{ :error, msg } = TwitterAPI.unfollow(user, %{"user_id" => unfollowed.id})
|
||||
assert msg == "Not subscribed!"
|
||||
end
|
||||
|
||||
test "Unfollow another user using screen_name" do
|
||||
unfollowed = insert(:user)
|
||||
user = insert(:user, %{following: [User.ap_followers(unfollowed)]})
|
||||
|
||||
{:ok, user, unfollowed } = TwitterAPI.unfollow(user, %{"screen_name" => unfollowed.nickname})
|
||||
assert user.following == []
|
||||
|
||||
{ :error, msg } = TwitterAPI.unfollow(user, %{"screen_name" => unfollowed.nickname})
|
||||
assert msg == "Not subscribed!"
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue