Merge branch 'develop' of ssh.gitgud.io:lambadalambda/pleroma into feature/help-test
authordtluna <dtluna@openmailbox.org>
Sun, 16 Apr 2017 10:25:38 +0000 (13:25 +0300)
committerdtluna <dtluna@openmailbox.org>
Sun, 16 Apr 2017 10:25:38 +0000 (13:25 +0300)
1  2 
lib/pleroma/web/router.ex
lib/pleroma/web/twitter_api/twitter_api_controller.ex
test/web/twitter_api/twitter_api_controller_test.exs

Simple merge
index 766da6c93d23d40aa0d3f6b6c2a43606e3ac5672,fa26bb3e9f5c3f8ffa2818ff677e01c953d1c9f8..f2ca83915f7da353c860de1e623ca5d81327c10c
@@@ -83,10 -84,12 +84,16 @@@ defmodule Pleroma.Web.TwitterAPI.Contro
      |> send_resp(200, response)
    end
  
 +  def help_test(conn, _params) do
 +    conn |> json_reply(200, Poison.encode!("ok"))
 +  end
 +
+   def upload_json(conn, %{"media" => media}) do
+     response = TwitterAPI.upload(media, "json")
+     conn
+     |> json_reply(200, response)
+   end
    def config(conn, _params) do
      response = %{
        site: %{
index 80ec9e4bb3a68e0fb1d8c48b6a93e8da74a0bc11,3bc4eb700a33073df31cbff3cf0b18f69eb2b1c8..e54177c9414da79f120b289c334bdfaca0dad433
@@@ -154,10 -157,100 +157,106 @@@ defmodule Pleroma.Web.TwitterAPI.Contro
      end
    end
  
 +  describe "GET /help/test.json" do
 +    test "returns \"ok\"", %{conn: conn} do
 +      conn = get conn, "/api/help/test.json"
 +      assert json_response(conn, 200) == "ok"
++  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
+   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