X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Ftwitter_api%2Ftwitter_api_controller_test.exs;h=3bc4eb700a33073df31cbff3cf0b18f69eb2b1c8;hb=5dac3727f10d65eea284da56fe4b0db5cab53f1f;hp=728a1b6a81a0a6c2903ace01192fa4ddde2e69bb;hpb=5cb446a148ab7f935b4fc90e4d353d10e18f9f7d;p=akkoma diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 728a1b6a8..3bc4eb700 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,84 @@ 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 + + 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 + + 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] @@ -184,4 +263,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