Merge branch 'develop' of ssh.gitgud.io:lambadalambda/pleroma into feature/help-test
This commit is contained in:
commit
85bd480be3
22 changed files with 143 additions and 47 deletions
File diff suppressed because one or more lines are too long
|
|
@ -45,8 +45,11 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
|
|||
|
||||
test "an activity" do
|
||||
{:ok, user} = UserBuilder.insert
|
||||
{:ok, mentioned_user } = UserBuilder.insert(%{nickname: "shp", ap_id: "shp"})
|
||||
{:ok, follower} = UserBuilder.insert(%{following: [User.ap_followers(user)]})
|
||||
# {:ok, mentioned_user } = UserBuilder.insert(%{nickname: "shp", ap_id: "shp"})
|
||||
mentioned_user = insert(:user, %{nickname: "shp"})
|
||||
|
||||
# {:ok, follower} = UserBuilder.insert(%{following: [User.ap_followers(user)]})
|
||||
follower = insert(:user, %{following: [User.ap_followers(user)]})
|
||||
|
||||
object = %Object{
|
||||
data: %{
|
||||
|
|
@ -62,7 +65,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
|
|||
}
|
||||
}
|
||||
|
||||
content_html = "Some content mentioning <a href='shp'>@shp</shp>"
|
||||
content_html = "Some content mentioning <a href='#{mentioned_user.ap_id}'>@shp</shp>"
|
||||
content = HtmlSanitizeEx.strip_tags(content_html)
|
||||
date = DateTime.from_naive!(~N[2016-05-24 13:26:08.003], "Etc/UTC") |> DateTime.to_iso8601
|
||||
|
||||
|
|
|
|||
|
|
@ -5,13 +5,23 @@ defmodule Pleroma.Web.TwitterAPI.Representers.UserRepresenterTest do
|
|||
alias Pleroma.Web.TwitterAPI.Representers.UserRepresenter
|
||||
alias Pleroma.Builders.UserBuilder
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
setup do
|
||||
{:ok, user} = UserBuilder.insert
|
||||
user = insert(:user)
|
||||
[user: user]
|
||||
end
|
||||
|
||||
test "A user with an avatar object", %{user: user} do
|
||||
image = "image"
|
||||
user = %{ user | avatar: %{ "url" => [%{"href" => image}] }}
|
||||
represented = UserRepresenter.to_map(user)
|
||||
assert represented["profile_image_url"] == image
|
||||
end
|
||||
|
||||
test "A user", %{user: user} do
|
||||
image = "https://placehold.it/48x48"
|
||||
|
||||
represented = %{
|
||||
"id" => user.id,
|
||||
"name" => user.name,
|
||||
|
|
|
|||
|
|
@ -94,10 +94,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
end
|
||||
|
||||
test "with credentials", %{conn: conn, user: current_user} do
|
||||
{:ok, user} = UserBuilder.insert
|
||||
user = insert(:user)
|
||||
activities = ActivityBuilder.insert_list(30, %{"to" => [User.ap_followers(user)]}, %{user: user})
|
||||
returned_activities = ActivityBuilder.insert_list(10, %{"to" => [User.ap_followers(user)]}, %{user: user})
|
||||
{:ok, other_user} = UserBuilder.insert(%{ap_id: "glimmung", nickname: "nockame"})
|
||||
other_user = insert(:user)
|
||||
ActivityBuilder.insert_list(10, %{}, %{user: other_user})
|
||||
since_id = List.last(activities).id
|
||||
|
||||
|
|
@ -110,7 +110,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
response = json_response(conn, 200)
|
||||
|
||||
assert length(response) == 10
|
||||
assert response == Enum.map(returned_activities, fn (activity) -> ActivityRepresenter.to_map(activity, %{user: user, for: current_user}) end)
|
||||
assert response == Enum.map(returned_activities, fn (activity) -> ActivityRepresenter.to_map(activity, %{user: User.get_cached_by_ap_id(activity.data["actor"]), for: current_user}) end)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -122,7 +122,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
end
|
||||
|
||||
test "with credentials", %{conn: conn, user: current_user} do
|
||||
{:ok, followed } = UserBuilder.insert(%{name: "some guy"})
|
||||
followed = insert(:user)
|
||||
|
||||
conn = conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|
|
@ -142,7 +142,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
end
|
||||
|
||||
test "with credentials", %{conn: conn, user: current_user} do
|
||||
{:ok, followed } = UserBuilder.insert(%{name: "some guy"})
|
||||
followed = insert(:user)
|
||||
|
||||
{:ok, current_user} = User.follow(current_user, followed)
|
||||
assert current_user.following == [User.ap_followers(followed)]
|
||||
|
|
@ -163,6 +163,24 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
assert json_response(conn, 200) == "ok"
|
||||
end
|
||||
|
||||
describe "POST /api/qvitter/update_avatar.json" do
|
||||
setup [:valid_user]
|
||||
test "without valid credentials", %{conn: conn} do
|
||||
conn = post conn, "/api/qvitter/update_avatar.json"
|
||||
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
||||
end
|
||||
|
||||
test "with credentials", %{conn: conn, user: current_user} do
|
||||
conn = conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/qvitter/update_avatar.json", %{img: Pleroma.Web.ActivityPub.ActivityPubTest.data_uri})
|
||||
|
||||
current_user = Repo.get(User, current_user.id)
|
||||
assert is_map(current_user.avatar)
|
||||
assert json_response(conn, 200) == UserRepresenter.to_map(current_user, %{for: current_user})
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /api/favorites/create/:id" do
|
||||
setup [:valid_user]
|
||||
test "without valid credentials", %{conn: conn} do
|
||||
|
|
|
|||
|
|
@ -78,7 +78,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
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)
|
||||
|
||||
|
|
@ -87,19 +88,18 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
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
|
||||
|
|
@ -113,8 +113,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
end
|
||||
|
||||
test "Follow another user" do
|
||||
{ :ok, user } = UserBuilder.insert
|
||||
{ :ok, following } = UserBuilder.insert(%{nickname: "guy"})
|
||||
user = insert(:user)
|
||||
following = insert(:user)
|
||||
|
||||
{:ok, user, following, activity } = TwitterAPI.follow(user, following.id)
|
||||
|
||||
|
|
@ -126,8 +126,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
end
|
||||
|
||||
test "Unfollow another user" do
|
||||
{ :ok, following } = UserBuilder.insert(%{nickname: "guy"})
|
||||
{ :ok, user } = UserBuilder.insert(%{following: [User.ap_followers(following)]})
|
||||
following = insert(:user)
|
||||
user = insert(:user, %{following: [User.ap_followers(following)]})
|
||||
|
||||
{:ok, user, _following } = TwitterAPI.unfollow(user, following.id)
|
||||
|
||||
|
|
@ -160,8 +160,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest 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},
|
||||
|
|
@ -174,11 +174,11 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue