From 1ccbe562c950e588e24822d20f802dd99b01bd79 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Thu, 13 Apr 2017 14:56:19 +0200 Subject: Add actor to objects. --- test/web/twitter_api/twitter_api_test.exs | 1 + 1 file changed, 1 insertion(+) (limited to 'test/web/twitter_api') diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index e8853a910..a4c9bd7e7 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -32,6 +32,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do assert get_in(activity.data, ["object", "content"]) == "Hello again, @shp." 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 assert Enum.member?(get_in(activity.data, ["to"]), User.ap_followers(user)) assert Enum.member?(get_in(activity.data, ["to"]), "https://www.w3.org/ns/activitystreams#Public") -- cgit v1.2.3 From 653d605e14d25658d398148748335dc58f9f2229 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Thu, 13 Apr 2017 16:19:07 +0200 Subject: Add favoriting to twitter api. --- .../twitter_api/representers/activity_representer_test.exs | 6 ++++-- test/web/twitter_api/twitter_api_test.exs | 13 +++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'test/web/twitter_api') diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs index f1f2b4c9c..70df79a77 100644 --- a/test/web/twitter_api/representers/activity_representer_test.exs +++ b/test/web/twitter_api/representers/activity_representer_test.exs @@ -45,7 +45,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do "statusnetConversationId" => 4711, "attachment" => [ object - ] + ], + "like_count" => 5 }, "published" => date } @@ -68,7 +69,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do ], "attentions" => [ UserRepresenter.to_map(mentioned_user, %{for: follower}) - ] + ], + "fave_num" => 5 } assert ActivityRepresenter.to_map(activity, %{user: user, for: follower, mentioned: [mentioned_user]}) == expected_status diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index a4c9bd7e7..341622758 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -5,6 +5,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do alias Pleroma.{Activity, User, Object, Repo} alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter + import Pleroma.Factory + test "create a status" do user = UserBuilder.build(%{ap_id: "142344"}) _mentioned_user = UserBuilder.insert(%{nickname: "shp", ap_id: "shp"}) @@ -177,4 +179,15 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do 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 end -- cgit v1.2.3 From d0da40dc81f5db2b3d335fb47d00d0ac52c2cba3 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Thu, 13 Apr 2017 17:05:53 +0200 Subject: Display like activities. --- .../twitter_api/representers/activity_representer_test.exs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/web/twitter_api') diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs index 70df79a77..5673c1f0d 100644 --- a/test/web/twitter_api/representers/activity_representer_test.exs +++ b/test/web/twitter_api/representers/activity_representer_test.exs @@ -2,7 +2,21 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do use Pleroma.DataCase alias Pleroma.{User, Activity, Object} alias Pleroma.Web.TwitterAPI.Representers.{UserRepresenter, ActivityRepresenter, ObjectRepresenter} + alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Builders.UserBuilder + import Pleroma.Factory + + test "a like activity" do + user = insert(:user) + note_activity = insert(:note_activity) + object = Object.get_by_ap_id(note_activity.data["object"]["id"]) + + {:ok, like_activity, object} = ActivityPub.like(user, object) + status = ActivityRepresenter.to_map(like_activity, %{user: user, liked_activity: note_activity}) + + assert status["id"] == like_activity.id + assert status["in_reply_to_status_id"] == note_activity.id + end test "an activity" do {:ok, user} = UserBuilder.insert -- cgit v1.2.3 From 5cb446a148ab7f935b4fc90e4d353d10e18f9f7d Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Thu, 13 Apr 2017 17:22:44 +0200 Subject: Add favoriting to TwAPI controller. --- .../web/twitter_api/twitter_api_controller_test.exs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/web/twitter_api') diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 7c75ff757..728a1b6a8 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -4,6 +4,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do alias Pleroma.Builders.{ActivityBuilder, UserBuilder} alias Pleroma.{Repo, Activity, User} + import Pleroma.Factory + describe "POST /api/account/verify_credentials" do setup [:valid_user] test "without valid credentials", %{conn: conn} do @@ -154,6 +156,25 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do end end + describe "POST /api/favorites/create/:id" do + setup [:valid_user] + test "without valid credentials", %{conn: conn} do + note_activity = insert(:note_activity) + conn = post conn, "/api/favorites/create/#{note_activity.id}.json" + assert json_response(conn, 403) == %{"error" => "Invalid credentials."} + end + + test "with credentials", %{conn: conn, user: current_user} do + note_activity = insert(:note_activity) + + conn = conn + |> with_credentials(current_user.nickname, "test") + |> post("/api/favorites/create/#{note_activity.id}.json") + + assert json_response(conn, 200) + end + end + defp valid_user(_context) do { :ok, user } = UserBuilder.insert(%{nickname: "lambda", ap_id: "lambda"}) [user: user] -- cgit v1.2.3 From fa0c279139f384f6c97bce217be4131b255f00b1 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Fri, 14 Apr 2017 15:07:24 +0200 Subject: Favorite changes. - Add 'likes' to activity, collection of ids of people who liked it. - show if you favorited something or not. - Don't allow double favorites - Address favorites to the followers of the liked activity's author. --- .../web/twitter_api/representers/activity_representer_test.exs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'test/web/twitter_api') diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs index 5673c1f0d..d1f9e00c8 100644 --- a/test/web/twitter_api/representers/activity_representer_test.exs +++ b/test/web/twitter_api/representers/activity_representer_test.exs @@ -11,11 +11,16 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do note_activity = insert(:note_activity) object = Object.get_by_ap_id(note_activity.data["object"]["id"]) - {:ok, like_activity, object} = ActivityPub.like(user, object) + {:ok, like_activity, _object} = ActivityPub.like(user, object) status = ActivityRepresenter.to_map(like_activity, %{user: user, liked_activity: note_activity}) assert status["id"] == like_activity.id assert status["in_reply_to_status_id"] == note_activity.id + + note_activity = Activity.get_by_ap_id(note_activity.data["id"]) + activity_actor = Repo.get_by(User, ap_id: note_activity.data["actor"]) + liked_status = ActivityRepresenter.to_map(note_activity, %{user: activity_actor, for: user}) + assert liked_status["favorited"] == true end test "an activity" do @@ -84,7 +89,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do "attentions" => [ UserRepresenter.to_map(mentioned_user, %{for: follower}) ], - "fave_num" => 5 + "fave_num" => 5, + "favorited" => false } assert ActivityRepresenter.to_map(activity, %{user: user, for: follower, mentioned: [mentioned_user]}) == expected_status -- cgit v1.2.3 From 03ddaead7e01d096cc3caa95a956d049be2e28f6 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Fri, 14 Apr 2017 17:13:51 +0200 Subject: Add basic user caching. Expires after 5 seconds. --- test/web/twitter_api/twitter_api_controller_test.exs | 6 ++++++ test/web/twitter_api/twitter_api_test.exs | 6 ++++++ 2 files changed, 12 insertions(+) (limited to 'test/web/twitter_api') diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 728a1b6a8..a4128f442 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -184,4 +184,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do header_content = "Basic " <> Base.encode64("#{username}:#{password}") put_req_header(conn, "authorization", header_content) end + + setup do + Supervisor.terminate_child(Pleroma.Supervisor, ConCache) + Supervisor.restart_child(Pleroma.Supervisor, ConCache) + :ok + end end diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index 341622758..040a392e5 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -190,4 +190,10 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do assert status == ActivityRepresenter.to_map(updated_activity, %{user: activity_user, for: user}) end + + setup do + Supervisor.terminate_child(Pleroma.Supervisor, ConCache) + Supervisor.restart_child(Pleroma.Supervisor, ConCache) + :ok + end end -- cgit v1.2.3 From f4eea0847b4bfcc2a2e6e0c80480ca5818f17aa9 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Fri, 14 Apr 2017 18:15:15 +0200 Subject: Add unfavoriting to TwAPI. --- test/web/twitter_api/twitter_api_test.exs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/web/twitter_api') diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index 040a392e5..88e6dd684 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -4,6 +4,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do alias Pleroma.Web.TwitterAPI.TwitterAPI alias Pleroma.{Activity, User, Object, Repo} alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter + alias Pleroma.Web.ActivityPub.ActivityPub import Pleroma.Factory @@ -191,6 +192,22 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do 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) -- cgit v1.2.3 From c83f279a7d1d9061dff6fb2f3f36740abad2e85c Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Fri, 14 Apr 2017 18:27:17 +0200 Subject: Add unliking to TwAPI controller. --- .../twitter_api/twitter_api_controller_test.exs | 24 +++++++++++++++++++++- test/web/twitter_api/twitter_api_test.exs | 3 +-- 2 files changed, 24 insertions(+), 3 deletions(-) (limited to 'test/web/twitter_api') diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index a4128f442..814f457b9 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -2,7 +2,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do use Pleroma.Web.ConnCase alias Pleroma.Web.TwitterAPI.Representers.{UserRepresenter, ActivityRepresenter} alias Pleroma.Builders.{ActivityBuilder, UserBuilder} - alias Pleroma.{Repo, Activity, User} + alias Pleroma.{Repo, Activity, User, Object} + alias Pleroma.Web.ActivityPub.ActivityPub import Pleroma.Factory @@ -175,6 +176,27 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do end end + describe "POST /api/favorites/destroy/:id" do + setup [:valid_user] + test "without valid credentials", %{conn: conn} do + note_activity = insert(:note_activity) + conn = post conn, "/api/favorites/destroy/#{note_activity.id}.json" + assert json_response(conn, 403) == %{"error" => "Invalid credentials."} + end + + test "with credentials", %{conn: conn, user: current_user} do + note_activity = insert(:note_activity) + object = Object.get_by_ap_id(note_activity.data["object"]["id"]) + ActivityPub.like(current_user, object) + + conn = conn + |> with_credentials(current_user.nickname, "test") + |> post("/api/favorites/destroy/#{note_activity.id}.json") + + assert json_response(conn, 200) + end + end + defp valid_user(_context) do { :ok, user } = UserBuilder.insert(%{nickname: "lambda", ap_id: "lambda"}) [user: user] diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index 88e6dd684..36d4f4012 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -198,12 +198,11 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do 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) + {: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 -- cgit v1.2.3 From 7a47afed3c52f537e9a4851372d76ccf95459799 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Fri, 14 Apr 2017 18:59:11 +0200 Subject: Update object correctly after setting context. --- test/web/twitter_api/twitter_api_test.exs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/web/twitter_api') diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index 36d4f4012..fd9908b9f 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -48,6 +48,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do assert get_in(activity.data, ["statusnetConversationId"]) == activity.id assert is_list(activity.data["object"]["attachment"]) + + assert activity.data["object"] == Object.get_by_ap_id(activity.data["object"]["id"]).data end test "create a status that is a reply" do -- cgit v1.2.3 From 60c60de330fe8fe03594da89831351099c8c9037 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sat, 15 Apr 2017 13:54:46 +0200 Subject: Add announcements / retweets to TwAPI. --- .../representers/activity_representer_test.exs | 27 ++++++++++++++++++++-- test/web/twitter_api/twitter_api_test.exs | 11 +++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) (limited to 'test/web/twitter_api') diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs index d1f9e00c8..a9129bccc 100644 --- a/test/web/twitter_api/representers/activity_representer_test.exs +++ b/test/web/twitter_api/representers/activity_representer_test.exs @@ -6,6 +6,26 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do alias Pleroma.Builders.UserBuilder import Pleroma.Factory + test "an announce activity" do + user = insert(:user) + note_activity = insert(:note_activity) + activity_actor = Repo.get_by(User, ap_id: note_activity.data["actor"]) + object = Object.get_by_ap_id(note_activity.data["object"]["id"]) + + {:ok, announce_activity, _object} = ActivityPub.announce(user, object) + note_activity = Activity.get_by_ap_id(note_activity.data["id"]) + + status = ActivityRepresenter.to_map(announce_activity, %{users: [user, activity_actor], announced_activity: note_activity, for: user}) + + assert status["id"] == announce_activity.id + assert status["user"] == UserRepresenter.to_map(user, %{for: user}) + + retweeted_status = ActivityRepresenter.to_map(note_activity, %{user: activity_actor, for: user}) + assert retweeted_status["repeated"] == true + + assert status["retweeted_status"] == retweeted_status + end + test "a like activity" do user = insert(:user) note_activity = insert(:note_activity) @@ -65,7 +85,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do "attachment" => [ object ], - "like_count" => 5 + "like_count" => 5, + "announcement_count" => 3 }, "published" => date } @@ -90,7 +111,9 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do UserRepresenter.to_map(mentioned_user, %{for: follower}) ], "fave_num" => 5, - "favorited" => false + "repeat_num" => 3, + "favorited" => false, + "repeated" => false } assert ActivityRepresenter.to_map(activity, %{user: user, for: follower, mentioned: [mentioned_user]}) == expected_status diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index fd9908b9f..71b0d8b12 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -209,6 +209,17 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do assert status["fave_num"] == 0 end + test "it retweets a status and returns the retweet" do + user = insert(:user) + note_activity = insert(:note_activity) + activity_user = Repo.get_by!(User, ap_id: note_activity.data["actor"]) + + {:ok, status} = TwitterAPI.retweet(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 + setup do Supervisor.terminate_child(Pleroma.Supervisor, ConCache) Supervisor.restart_child(Pleroma.Supervisor, ConCache) -- cgit v1.2.3 From 4799dc6991682489e8f1701946685a7725ad0a6a Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sat, 15 Apr 2017 14:09:54 +0200 Subject: Add retweeting to TwAPI controller. --- test/web/twitter_api/twitter_api_controller_test.exs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/web/twitter_api') diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 814f457b9..0eb1b60c5 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -197,6 +197,25 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do end end + describe "POST /api/statuses/retweet/:id" do + setup [:valid_user] + test "without valid credentials", %{conn: conn} do + note_activity = insert(:note_activity) + conn = post conn, "/api/statuses/retweet/#{note_activity.id}.json" + assert json_response(conn, 403) == %{"error" => "Invalid credentials."} + end + + 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") + + assert json_response(conn, 200) + end + end + defp valid_user(_context) do { :ok, user } = UserBuilder.insert(%{nickname: "lambda", ap_id: "lambda"}) [user: user] -- cgit v1.2.3 From b1edd94baa64a18223ae2cc731231ba4314fd0d3 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sun, 16 Apr 2017 10:25:27 +0200 Subject: Add user registration to TwAPI. --- test/web/twitter_api/twitter_api_test.exs | 33 ++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'test/web/twitter_api') diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index 71b0d8b12..eb5f8ec26 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -3,7 +3,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do alias Pleroma.Builders.{UserBuilder, ActivityBuilder} alias Pleroma.Web.TwitterAPI.TwitterAPI alias Pleroma.{Activity, User, Object, Repo} - alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter + alias Pleroma.Web.TwitterAPI.Representers.{ActivityRepresenter, UserRepresenter} alias Pleroma.Web.ActivityPub.ActivityPub import Pleroma.Factory @@ -220,6 +220,37 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do assert status == ActivityRepresenter.to_map(updated_activity, %{user: activity_user, for: user}) end + test "it registers a new user and returns the user." do + data = %{ + "nickname" => "lain", + "email" => "lain@wired.jp", + "fullname" => "lain iwakura", + "bio" => "close the world.", + "password" => "bear", + "confirm" => "bear" + } + + {:ok, user} = TwitterAPI.register_user(data) + + fetched_user = Repo.get_by(User, nickname: "lain") + assert user == UserRepresenter.to_map(fetched_user) + end + + test "it returns the error on registration problems" do + data = %{ + "nickname" => "lain", + "email" => "lain@wired.jp", + "fullname" => "lain iwakura", + "bio" => "close the world.", + "password" => "bear" + } + + {:error, error_object} = TwitterAPI.register_user(data) + + assert is_binary(error_object[:error]) + refute Repo.get_by(User, nickname: "lain") + end + setup do Supervisor.terminate_child(Pleroma.Supervisor, ConCache) Supervisor.restart_child(Pleroma.Supervisor, ConCache) -- cgit v1.2.3 From 5dac3727f10d65eea284da56fe4b0db5cab53f1f Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sun, 16 Apr 2017 11:01:24 +0200 Subject: Add registration to the TwAPI controller. --- .../twitter_api/twitter_api_controller_test.exs | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'test/web/twitter_api') diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 0eb1b60c5..3bc4eb700 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -216,6 +216,44 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do end end + describe "POST /api/account/register" do + test "it creates a new user", %{conn: conn} do + data = %{ + "nickname" => "lain", + "email" => "lain@wired.jp", + "fullname" => "lain iwakura", + "bio" => "close the world.", + "password" => "bear", + "confirm" => "bear" + } + + conn = conn + |> post("/api/account/register", data) + + user = json_response(conn, 200) + + fetched_user = Repo.get_by(User, nickname: "lain") + assert user == UserRepresenter.to_map(fetched_user) + end + + test "it returns errors on a problem", %{conn: conn} do + data = %{ + "email" => "lain@wired.jp", + "fullname" => "lain iwakura", + "bio" => "close the world.", + "password" => "bear", + "confirm" => "bear" + } + + conn = conn + |> post("/api/account/register", data) + + errors = json_response(conn, 400) + + assert is_binary(errors["error"]) + end + end + defp valid_user(_context) do { :ok, user } = UserBuilder.insert(%{nickname: "lambda", ap_id: "lambda"}) [user: user] -- cgit v1.2.3 From b41f3eff84e9ec496f0049cdd4fa9388a0fb7b5c Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sun, 16 Apr 2017 11:51:00 +0200 Subject: Preserve newlines in messages. --- test/web/twitter_api/twitter_api_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/web/twitter_api') diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index eb5f8ec26..b8bfb4cf9 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -27,13 +27,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do object = Repo.insert!(%Object{data: object_data}) input = %{ - "status" => "Hello again, @shp.", + "status" => "Hello again, @shp.\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, @shp." + assert get_in(activity.data, ["object", "content"]) == "Hello again, @shp.
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 -- cgit v1.2.3