2017-03-20 20:30:44 +00:00
|
|
|
defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|
|
|
use Pleroma.Web.ConnCase
|
2017-03-21 17:17:35 +00:00
|
|
|
alias Pleroma.Web.TwitterAPI.Representers.{UserRepresenter, ActivityRepresenter}
|
2017-03-21 16:53:20 +00:00
|
|
|
alias Pleroma.Builders.UserBuilder
|
2017-03-21 17:17:35 +00:00
|
|
|
alias Pleroma.{Repo, Activity}
|
2017-03-20 20:30:44 +00:00
|
|
|
|
|
|
|
describe "POST /api/account/verify_credentials" do
|
|
|
|
setup [:valid_user]
|
|
|
|
test "without valid credentials", %{conn: conn} do
|
|
|
|
conn = post conn, "/api/account/verify_credentials.json"
|
|
|
|
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with credentials", %{conn: conn, user: user} do
|
|
|
|
conn = conn
|
|
|
|
|> with_credentials(user.nickname, "test")
|
|
|
|
|> post("/api/account/verify_credentials.json")
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == UserRepresenter.to_map(user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-21 17:17:35 +00:00
|
|
|
describe "POST /statuses/update.json" do
|
|
|
|
setup [:valid_user]
|
|
|
|
test "without valid credentials", %{conn: conn} do
|
|
|
|
conn = post conn, "/api/statuses/update.json"
|
|
|
|
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with credentials", %{conn: conn, user: user} do
|
|
|
|
conn = conn
|
|
|
|
|> with_credentials(user.nickname, "test")
|
|
|
|
|> post("/api/statuses/update.json", %{ status: "Nice meme." })
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == ActivityRepresenter.to_map(Repo.one(Activity), %{user: user})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-20 20:30:44 +00:00
|
|
|
defp valid_user(_context) do
|
2017-03-21 16:53:20 +00:00
|
|
|
{ :ok, user } = UserBuilder.insert
|
2017-03-20 20:30:44 +00:00
|
|
|
[user: user]
|
|
|
|
end
|
|
|
|
|
|
|
|
defp with_credentials(conn, username, password) do
|
|
|
|
header_content = "Basic " <> Base.encode64("#{username}:#{password}")
|
|
|
|
put_req_header(conn, "authorization", header_content)
|
|
|
|
end
|
|
|
|
end
|