summaryrefslogtreecommitdiff
path: root/test/web/twitter_api
diff options
context:
space:
mode:
Diffstat (limited to 'test/web/twitter_api')
-rw-r--r--test/web/twitter_api/representers/activity_representer_test.exs6
-rw-r--r--test/web/twitter_api/representers/object_representer_test.exs6
-rw-r--r--test/web/twitter_api/twitter_api_controller_test.exs156
-rw-r--r--test/web/twitter_api/twitter_api_test.exs2
-rw-r--r--test/web/twitter_api/views/activity_view_test.exs31
-rw-r--r--test/web/twitter_api/views/user_view_test.exs51
6 files changed, 242 insertions, 10 deletions
diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs
index 3f85e028b..291fd5237 100644
--- a/test/web/twitter_api/representers/activity_representer_test.exs
+++ b/test/web/twitter_api/representers/activity_representer_test.exs
@@ -126,7 +126,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
}
expected_html =
- "<p>2hu</p>alert('YAY')Some <img height='32px' width='32px' alt='2hu' title='2hu' src='corndog.png' /> content mentioning <a href=\"#{
+ "<p>2hu</p>alert('YAY')Some <img height=\"32px\" width=\"32px\" alt=\"2hu\" title=\"2hu\" src=\"corndog.png\" /> content mentioning <a href=\"#{
mentioned_user.ap_id
}\">@shp</a>"
@@ -139,6 +139,10 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
"is_post_verb" => true,
"created_at" => "Tue May 24 13:26:08 +0000 2016",
"in_reply_to_status_id" => 213_123,
+ "in_reply_to_screen_name" => nil,
+ "in_reply_to_user_id" => nil,
+ "in_reply_to_profileurl" => nil,
+ "in_reply_to_ostatus_uri" => nil,
"statusnet_conversation_id" => convo_object.id,
"attachments" => [
ObjectRepresenter.to_map(object)
diff --git a/test/web/twitter_api/representers/object_representer_test.exs b/test/web/twitter_api/representers/object_representer_test.exs
index ebac051dc..228b2ac42 100644
--- a/test/web/twitter_api/representers/object_representer_test.exs
+++ b/test/web/twitter_api/representers/object_representer_test.exs
@@ -23,7 +23,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ObjectReprenterTest do
id: 6,
url: "someurl",
mimetype: "sometype",
- oembed: false
+ oembed: false,
+ description: nil
}
assert expected_object == ObjectRepresenter.to_map(object)
@@ -46,7 +47,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ObjectReprenterTest do
"http://mastodon.example.org/system/media_attachments/files/000/000/001/original/8619f31c6edec470.png",
mimetype: "image/png",
oembed: false,
- id: nil
+ id: nil,
+ description: "blabla"
}
assert expected_object == ObjectRepresenter.to_map(object)
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 3a035e298..6bdcb4fd8 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -77,7 +77,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
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."})
+ # we post with visibility private in order to avoid triggering relay
+ conn = conn_with_creds |> post(request_path, %{status: "Nice meme.", visibility: "private"})
assert json_response(conn, 200) ==
ActivityRepresenter.to_map(Repo.one(Activity), %{user: user})
@@ -99,6 +100,56 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert length(response) == 10
end
+
+ test "returns 403 to unauthenticated request when the instance is not public" do
+ instance =
+ Application.get_env(:pleroma, :instance)
+ |> Keyword.put(:public, false)
+
+ Application.put_env(:pleroma, :instance, instance)
+
+ conn
+ |> get("/api/statuses/public_timeline.json")
+ |> json_response(403)
+
+ instance =
+ Application.get_env(:pleroma, :instance)
+ |> Keyword.put(:public, true)
+
+ Application.put_env(:pleroma, :instance, instance)
+ end
+
+ test "returns 200 to unauthenticated request when the instance is public" do
+ conn
+ |> get("/api/statuses/public_timeline.json")
+ |> json_response(200)
+ end
+ end
+
+ describe "GET /statuses/public_and_external_timeline.json" do
+ test "returns 403 to unauthenticated request when the instance is not public" do
+ instance =
+ Application.get_env(:pleroma, :instance)
+ |> Keyword.put(:public, false)
+
+ Application.put_env(:pleroma, :instance, instance)
+
+ conn
+ |> get("/api/statuses/public_and_external_timeline.json")
+ |> json_response(403)
+
+ instance =
+ Application.get_env(:pleroma, :instance)
+ |> Keyword.put(:public, true)
+
+ Application.put_env(:pleroma, :instance, instance)
+ end
+
+ test "returns 200 to unauthenticated request when the instance is public" do
+ conn
+ |> get("/api/statuses/public_and_external_timeline.json")
+ |> json_response(200)
+ end
end
describe "GET /statuses/show/:id.json" do
@@ -220,6 +271,43 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
end
end
+ describe "GET /statuses/dm_timeline.json" do
+ test "it show direct messages", %{conn: conn} do
+ user_one = insert(:user)
+ user_two = insert(:user)
+
+ {:ok, user_two} = User.follow(user_two, user_one)
+
+ {:ok, direct} =
+ CommonAPI.post(user_one, %{
+ "status" => "Hi @#{user_two.nickname}!",
+ "visibility" => "direct"
+ })
+
+ {:ok, direct_two} =
+ CommonAPI.post(user_two, %{
+ "status" => "Hi @#{user_one.nickname}!",
+ "visibility" => "direct"
+ })
+
+ {:ok, _follower_only} =
+ CommonAPI.post(user_one, %{
+ "status" => "Hi @#{user_two.nickname}!",
+ "visibility" => "private"
+ })
+
+ # Only direct should be visible here
+ res_conn =
+ conn
+ |> assign(:user, user_two)
+ |> get("/api/statuses/dm_timeline.json")
+
+ [status, status_two] = json_response(res_conn, 200)
+ assert status["id"] == direct_two.id
+ assert status_two["id"] == direct.id
+ end
+ end
+
describe "GET /statuses/mentions.json" do
setup [:valid_user]
@@ -280,6 +368,56 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
end
end
+ describe "POST /api/qvitter/statuses/notifications/read" do
+ setup [:valid_user]
+
+ test "without valid credentials", %{conn: conn} do
+ conn = post(conn, "/api/qvitter/statuses/notifications/read", %{"latest_id" => 1_234_567})
+ assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
+ end
+
+ test "with credentials, without any params", %{conn: conn, user: current_user} do
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/qvitter/statuses/notifications/read")
+
+ assert json_response(conn, 400) == %{
+ "error" => "You need to specify latest_id",
+ "request" => "/api/qvitter/statuses/notifications/read"
+ }
+ end
+
+ test "with credentials, with params", %{conn: conn, user: current_user} do
+ other_user = insert(:user)
+
+ {:ok, _activity} =
+ ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: other_user})
+
+ response_conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> get("/api/qvitter/statuses/notifications.json")
+
+ [notification] = response = json_response(response_conn, 200)
+
+ assert length(response) == 1
+
+ assert notification["is_seen"] == 0
+
+ response_conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/qvitter/statuses/notifications/read", %{"latest_id" => notification["id"]})
+
+ [notification] = response = json_response(response_conn, 200)
+
+ assert length(response) == 1
+
+ assert notification["is_seen"] == 1
+ end
+ end
+
describe "GET /statuses/user_timeline.json" do
setup [:valid_user]
@@ -1080,4 +1218,20 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert relationship["follows_you"] == false
end
end
+
+ describe "GET /api/pleroma/search_user" do
+ test "it returns users, ordered by similarity", %{conn: conn} do
+ user = insert(:user, %{name: "eal"})
+ user_two = insert(:user, %{name: "ean"})
+ user_three = insert(:user, %{name: "ebn"})
+
+ resp =
+ conn
+ |> get(twitter_api_search__path(conn, :search_user), query: "eal")
+ |> json_response(200)
+
+ assert length(resp) == 3
+ assert [user.id, user_two.id, user_three.id] == Enum.map(resp, fn %{"id" => id} -> id end)
+ end
+ end
end
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index 6486540f8..8b9920bd9 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -48,7 +48,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
"https://www.w3.org/ns/activitystreams#Public"
)
- assert Enum.member?(get_in(activity.data, ["cc"]), "shp")
+ assert Enum.member?(get_in(activity.data, ["to"]), "shp")
assert activity.local == true
assert %{"moominmamma" => "http://localhost:4001/finmoji/128px/moominmamma-128.png"} =
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index a101e4ae8..5cef06f88 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -36,6 +36,10 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
"favorited" => false,
"id" => activity.id,
"in_reply_to_status_id" => nil,
+ "in_reply_to_screen_name" => nil,
+ "in_reply_to_user_id" => nil,
+ "in_reply_to_profileurl" => nil,
+ "in_reply_to_ostatus_uri" => nil,
"is_local" => true,
"is_post_verb" => true,
"possibly_sensitive" => false,
@@ -126,6 +130,33 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
assert result == expected
end
+ test "a like activity for deleted post" do
+ user = insert(:user)
+ other_user = insert(:user, %{nickname: "shp"})
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
+ {:ok, like, _object} = CommonAPI.favorite(activity.id, other_user)
+ CommonAPI.delete(activity.id, user)
+
+ result = ActivityView.render("activity.json", activity: like)
+
+ expected = %{
+ "activity_type" => "like",
+ "created_at" => like.data["published"] |> Utils.date_to_asctime(),
+ "external_url" => like.data["id"],
+ "id" => like.id,
+ "in_reply_to_status_id" => nil,
+ "is_local" => true,
+ "is_post_verb" => false,
+ "statusnet_html" => "shp favorited a status.",
+ "text" => "shp favorited a status.",
+ "uri" => "tag:#{like.data["id"]}:objectType=Favourite",
+ "user" => UserView.render("show.json", user: other_user)
+ }
+
+ assert result == expected
+ end
+
test "an announce activity" do
user = insert(:user)
other_user = insert(:user, %{nickname: "shp"})
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
index 24a5c5bca..2c583c0d3 100644
--- a/test/web/twitter_api/views/user_view_test.exs
+++ b/test/web/twitter_api/views/user_view_test.exs
@@ -13,6 +13,13 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
[user: user]
end
+ test "A user with only a nickname", %{user: user} do
+ user = %{user | name: nil, nickname: "scarlett@catgirl.science"}
+ represented = UserView.render("show.json", %{user: user})
+ assert represented["name"] == user.nickname
+ assert represented["name_html"] == user.nickname
+ end
+
test "A user with an avatar object", %{user: user} do
image = "image"
user = %{user | avatar: %{"url" => [%{"href" => image}]}}
@@ -22,7 +29,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
test "A user with emoji in username", %{user: user} do
expected =
- "<img height='32px' width='32px' alt='karjalanpiirakka' title='karjalanpiirakka' src='/file.png' /> man"
+ "<img height=\"32px\" width=\"32px\" alt=\"karjalanpiirakka\" title=\"karjalanpiirakka\" src=\"/file.png\" /> man"
user = %{
user
@@ -87,7 +94,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"background_image" => nil,
"is_local" => true,
"locked" => false,
- "default_scope" => "public"
+ "default_scope" => "public",
+ "no_rich_text" => false,
+ "fields" => []
}
assert represented == UserView.render("show.json", %{user: user})
@@ -126,7 +135,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"background_image" => nil,
"is_local" => true,
"locked" => false,
- "default_scope" => "public"
+ "default_scope" => "public",
+ "no_rich_text" => false,
+ "fields" => []
}
assert represented == UserView.render("show.json", %{user: user, for: follower})
@@ -166,7 +177,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"background_image" => nil,
"is_local" => true,
"locked" => false,
- "default_scope" => "public"
+ "default_scope" => "public",
+ "no_rich_text" => false,
+ "fields" => []
}
assert represented == UserView.render("show.json", %{user: follower, for: user})
@@ -213,10 +226,38 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"background_image" => nil,
"is_local" => true,
"locked" => false,
- "default_scope" => "public"
+ "default_scope" => "public",
+ "no_rich_text" => false,
+ "fields" => []
}
blocker = Repo.get(User, blocker.id)
assert represented == UserView.render("show.json", %{user: user, for: blocker})
end
+
+ test "a user with mastodon fields" do
+ fields = [
+ %{
+ "name" => "Pronouns",
+ "value" => "she/her"
+ },
+ %{
+ "name" => "Website",
+ "value" => "https://example.org/"
+ }
+ ]
+
+ user =
+ insert(:user, %{
+ info: %{
+ "source_data" => %{
+ "attachment" =>
+ Enum.map(fields, fn field -> Map.put(field, "type", "PropertyValue") end)
+ }
+ }
+ })
+
+ userview = UserView.render("show.json", %{user: user})
+ assert userview["fields"] == fields
+ end
end