Add spec for AccountController.create

This commit is contained in:
Egor Kislitsyn 2020-04-03 22:45:08 +04:00
parent ef37774403
commit b08ded6c2f
No known key found for this signature in database
GPG Key ID: 1B49CB15B71E7805
9 changed files with 426 additions and 192 deletions

View File

@ -0,0 +1,68 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ApiSpec.AccountOperation do
alias OpenApiSpex.Operation
alias Pleroma.Web.ApiSpec.Schemas.AccountCreateRequest
alias Pleroma.Web.ApiSpec.Schemas.AccountCreateResponse
alias Pleroma.Web.ApiSpec.Helpers
@spec open_api_operation(atom) :: Operation.t()
def open_api_operation(action) do
operation = String.to_existing_atom("#{action}_operation")
apply(__MODULE__, operation, [])
end
@spec create_operation() :: Operation.t()
def create_operation do
%Operation{
tags: ["accounts"],
summary: "Register an account",
description:
"Creates a user and account records. Returns an account access token for the app that initiated the request. The app should save this token for later, and should wait for the user to confirm their account by clicking a link in their email inbox.",
operationId: "AccountController.create",
requestBody: Helpers.request_body("Parameters", AccountCreateRequest, required: true),
responses: %{
200 => Operation.response("Account", "application/json", AccountCreateResponse)
}
}
end
def verify_credentials_operation do
:ok
end
def update_credentials_operation do
:ok
end
def relationships_operation do
:ok
end
def show_operation do
:ok
end
def statuses_operation do
:ok
end
def followers_operation do
:ok
end
def following_operation, do: :ok
def lists_operation, do: :ok
def follow_operation, do: :ok
def unfollow_operation, do: :ok
def mute_operation, do: :ok
def unmute_operation, do: :ok
def block_operation, do: :ok
def unblock_operation, do: :ok
def follows_operation, do: :ok
def mutes_operation, do: :ok
def blocks_operation, do: :ok
def endorsements_operation, do: :ok
end

View File

@ -0,0 +1,27 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ApiSpec.RenderError do
@behaviour Plug
alias Plug.Conn
alias OpenApiSpex.Plug.JsonRenderError
@impl Plug
def init(opts), do: opts
@impl Plug
def call(%{private: %{open_api_spex: %{operation_id: "AccountController.create"}}} = conn, _) do
conn
|> Conn.put_status(:bad_request)
|> Phoenix.Controller.json(%{"error" => "Missing parameters"})
end
def call(conn, reason) do
opts = JsonRenderError.init(reason)
JsonRenderError.call(conn, opts)
end
end

View File

@ -0,0 +1,56 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ApiSpec.Schemas.AccountCreateRequest do
alias OpenApiSpex.Schema
require OpenApiSpex
OpenApiSpex.schema(%{
title: "AccountCreateRequest",
description: "POST body for creating an account",
type: :object,
properties: %{
reason: %Schema{
type: :string,
description:
"Text that will be reviewed by moderators if registrations require manual approval"
},
username: %Schema{type: :string, description: "The desired username for the account"},
email: %Schema{
type: :string,
description:
"The email address to be used for login. Required when `account_activation_required` is enabled.",
format: :email
},
password: %Schema{type: :string, description: "The password to be used for login"},
agreement: %Schema{
type: :boolean,
description:
"Whether the user agrees to the local rules, terms, and policies. These should be presented to the user in order to allow them to consent before setting this parameter to TRUE."
},
locale: %Schema{
type: :string,
description: "The language of the confirmation email that will be sent"
},
# Pleroma-specific properties:
fullname: %Schema{type: :string, description: "Full name"},
bio: %Schema{type: :string, description: "Bio", default: ""},
captcha_solution: %Schema{type: :string, description: "Provider-specific captcha solution"},
captcha_token: %Schema{type: :string, description: "Provider-specific captcha token"},
captcha_answer_data: %Schema{type: :string, description: "Provider-specific captcha data"},
token: %Schema{
type: :string,
description: "Invite token required when the registrations aren't public"
}
},
required: [:username, :password, :agreement],
example: %{
"username" => "cofe",
"email" => "cofe@example.com",
"password" => "secret",
"agreement" => "true",
"bio" => "☕️"
}
})
end

View File

@ -0,0 +1,29 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ApiSpec.Schemas.AccountCreateResponse do
alias OpenApiSpex.Schema
require OpenApiSpex
OpenApiSpex.schema(%{
title: "AccountCreateResponse",
description: "Response schema for an account",
type: :object,
properties: %{
token_type: %Schema{type: :string},
access_token: %Schema{type: :string},
scope: %Schema{type: :array, items: %Schema{type: :string}},
created_at: %Schema{type: :integer}
},
example: %{
"JSON" => %{
"access_token" => "i9hAVVzGld86Pl5JtLtizKoXVvtTlSCJvwaugCxvZzk",
"created_at" => 1_585_918_714,
"scope" => ["read", "write", "follow", "push"],
"token_type" => "Bearer"
}
}
})
end

View File

@ -80,27 +80,33 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
plug(RateLimiter, [name: :app_account_creation] when action == :create) plug(RateLimiter, [name: :app_account_creation] when action == :create)
plug(:assign_account_by_id when action in @needs_account) plug(:assign_account_by_id when action in @needs_account)
plug(
OpenApiSpex.Plug.CastAndValidate,
[render_error: Pleroma.Web.ApiSpec.RenderError] when action == :create
)
action_fallback(Pleroma.Web.MastodonAPI.FallbackController) action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.AccountOperation
@doc "POST /api/v1/accounts" @doc "POST /api/v1/accounts"
def create( def create(%{assigns: %{app: app}, body_params: params} = conn, _params) do
%{assigns: %{app: app}} = conn,
%{"username" => nickname, "password" => _, "agreement" => true} = params
) do
params = params =
params params
|> Map.take([ |> Map.take([
"email", :email,
"captcha_solution", :bio,
"captcha_token", :captcha_solution,
"captcha_answer_data", :captcha_token,
"token", :captcha_answer_data,
"password" :token,
:password,
:fullname
]) ])
|> Map.put("nickname", nickname) |> Map.put(:nickname, params.username)
|> Map.put("fullname", params["fullname"] || nickname) |> Map.put(:fullname, params.fullname || params.username)
|> Map.put("bio", params["bio"] || "") |> Map.put(:bio, params.bio || "")
|> Map.put("confirm", params["password"]) |> Map.put(:confirm, params.password)
with :ok <- validate_email_param(params), with :ok <- validate_email_param(params),
{:ok, user} <- TwitterAPI.register_user(params, need_confirmation: true), {:ok, user} <- TwitterAPI.register_user(params, need_confirmation: true),
@ -124,7 +130,7 @@ def create(conn, _) do
render_error(conn, :forbidden, "Invalid credentials") render_error(conn, :forbidden, "Invalid credentials")
end end
defp validate_email_param(%{"email" => _}), do: :ok defp validate_email_param(%{:email => email}) when not is_nil(email), do: :ok
defp validate_email_param(_) do defp validate_email_param(_) do
case Pleroma.Config.get([:instance, :account_activation_required]) do case Pleroma.Config.get([:instance, :account_activation_required]) do

View File

@ -12,72 +12,56 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
require Pleroma.Constants require Pleroma.Constants
def register_user(params, opts \\ []) do def register_user(params, opts \\ []) do
token = params["token"] params =
params
|> Map.take([
:nickname,
:password,
:captcha_solution,
:captcha_token,
:captcha_answer_data,
:token,
:email
])
|> Map.put(:bio, User.parse_bio(params[:bio] || ""))
|> Map.put(:name, params.fullname)
|> Map.put(:password_confirmation, params[:confirm])
params = %{ case validate_captcha(params) do
nickname: params["nickname"], :ok ->
name: params["fullname"], if Pleroma.Config.get([:instance, :registrations_open]) do
bio: User.parse_bio(params["bio"]), create_user(params, opts)
email: params["email"], else
password: params["password"], create_user_with_invite(params, opts)
password_confirmation: params["confirm"], end
captcha_solution: params["captcha_solution"],
captcha_token: params["captcha_token"],
captcha_answer_data: params["captcha_answer_data"]
}
captcha_enabled = Pleroma.Config.get([Pleroma.Captcha, :enabled]) {:error, error} ->
# true if captcha is disabled or enabled and valid, false otherwise # I have no idea how this error handling works
captcha_ok = {:error, %{error: Jason.encode!(%{captcha: [error]})}}
if not captcha_enabled do
:ok
else
Pleroma.Captcha.validate(
params[:captcha_token],
params[:captcha_solution],
params[:captcha_answer_data]
)
end
# Captcha invalid
if captcha_ok != :ok do
{:error, error} = captcha_ok
# I have no idea how this error handling works
{:error, %{error: Jason.encode!(%{captcha: [error]})}}
else
registration_process(
params,
%{
registrations_open: Pleroma.Config.get([:instance, :registrations_open]),
token: token
},
opts
)
end end
end end
defp registration_process(params, %{registrations_open: true}, opts) do defp validate_captcha(params) do
create_user(params, opts) if Pleroma.Config.get([Pleroma.Captcha, :enabled]) do
Pleroma.Captcha.validate(
params.captcha_token,
params.captcha_solution,
params.captcha_answer_data
)
else
:ok
end
end end
defp registration_process(params, %{token: token}, opts) do defp create_user_with_invite(params, opts) do
invite = with %{token: token} when is_binary(token) <- params,
unless is_nil(token) do %UserInviteToken{} = invite <- Repo.get_by(UserInviteToken, %{token: token}),
Repo.get_by(UserInviteToken, %{token: token}) true <- UserInviteToken.valid_invite?(invite) do
end UserInviteToken.update_usage!(invite)
create_user(params, opts)
valid_invite? = invite && UserInviteToken.valid_invite?(invite) else
nil -> {:error, "Invalid token"}
case invite do _ -> {:error, "Expired token"}
nil ->
{:error, "Invalid token"}
invite when valid_invite? ->
UserInviteToken.update_usage!(invite)
create_user(params, opts)
_ ->
{:error, "Expired token"}
end end
end end

View File

@ -0,0 +1,48 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ApiSpec.AccountOperationTest do
use Pleroma.Web.ConnCase, async: true
alias Pleroma.Web.ApiSpec
alias Pleroma.Web.ApiSpec.Schemas.AccountCreateRequest
alias Pleroma.Web.ApiSpec.Schemas.AccountCreateResponse
import OpenApiSpex.TestAssertions
import Pleroma.Factory
test "AccountCreateRequest example matches schema" do
api_spec = ApiSpec.spec()
schema = AccountCreateRequest.schema()
assert_schema(schema.example, "AccountCreateRequest", api_spec)
end
test "AccountCreateResponse example matches schema" do
api_spec = ApiSpec.spec()
schema = AccountCreateResponse.schema()
assert_schema(schema.example, "AccountCreateResponse", api_spec)
end
test "AccountController produces a AccountCreateResponse", %{conn: conn} do
api_spec = ApiSpec.spec()
app_token = insert(:oauth_token, user: nil)
json =
conn
|> put_req_header("authorization", "Bearer " <> app_token.token)
|> put_req_header("content-type", "application/json")
|> post(
"/api/v1/accounts",
%{
username: "foo",
email: "bar@example.org",
password: "qwerty",
agreement: true
}
)
|> json_response(200)
assert_schema(json, "AccountCreateResponse", api_spec)
end
end

View File

@ -830,6 +830,7 @@ test "Account registration via Application", %{conn: conn} do
conn = conn =
build_conn() build_conn()
|> put_req_header("content-type", "multipart/form-data")
|> put_req_header("authorization", "Bearer " <> token) |> put_req_header("authorization", "Bearer " <> token)
|> post("/api/v1/accounts", %{ |> post("/api/v1/accounts", %{
username: "lain", username: "lain",
@ -858,11 +859,12 @@ test "returns error when user already registred", %{conn: conn, valid_params: va
_user = insert(:user, email: "lain@example.org") _user = insert(:user, email: "lain@example.org")
app_token = insert(:oauth_token, user: nil) app_token = insert(:oauth_token, user: nil)
conn = res =
conn conn
|> put_req_header("authorization", "Bearer " <> app_token.token) |> put_req_header("authorization", "Bearer " <> app_token.token)
|> put_req_header("content-type", "application/json")
|> post("/api/v1/accounts", valid_params)
res = post(conn, "/api/v1/accounts", valid_params)
assert json_response(res, 400) == %{"error" => "{\"email\":[\"has already been taken\"]}"} assert json_response(res, 400) == %{"error" => "{\"email\":[\"has already been taken\"]}"}
end end
@ -872,7 +874,10 @@ test "returns bad_request if missing required params", %{
} do } do
app_token = insert(:oauth_token, user: nil) app_token = insert(:oauth_token, user: nil)
conn = put_req_header(conn, "authorization", "Bearer " <> app_token.token) conn =
conn
|> put_req_header("authorization", "Bearer " <> app_token.token)
|> put_req_header("content-type", "application/json")
res = post(conn, "/api/v1/accounts", valid_params) res = post(conn, "/api/v1/accounts", valid_params)
assert json_response(res, 200) assert json_response(res, 200)
@ -897,7 +902,11 @@ test "returns bad_request if missing email params when :account_activation_requi
Pleroma.Config.put([:instance, :account_activation_required], true) Pleroma.Config.put([:instance, :account_activation_required], true)
app_token = insert(:oauth_token, user: nil) app_token = insert(:oauth_token, user: nil)
conn = put_req_header(conn, "authorization", "Bearer " <> app_token.token)
conn =
conn
|> put_req_header("authorization", "Bearer " <> app_token.token)
|> put_req_header("content-type", "application/json")
res = res =
conn conn
@ -920,6 +929,7 @@ test "allow registration without an email", %{conn: conn, valid_params: valid_pa
res = res =
conn conn
|> put_req_header("content-type", "application/json")
|> Map.put(:remote_ip, {127, 0, 0, 7}) |> Map.put(:remote_ip, {127, 0, 0, 7})
|> post("/api/v1/accounts", Map.delete(valid_params, :email)) |> post("/api/v1/accounts", Map.delete(valid_params, :email))
@ -932,6 +942,7 @@ test "allow registration with an empty email", %{conn: conn, valid_params: valid
res = res =
conn conn
|> put_req_header("content-type", "application/json")
|> Map.put(:remote_ip, {127, 0, 0, 8}) |> Map.put(:remote_ip, {127, 0, 0, 8})
|> post("/api/v1/accounts", Map.put(valid_params, :email, "")) |> post("/api/v1/accounts", Map.put(valid_params, :email, ""))
@ -939,9 +950,12 @@ test "allow registration with an empty email", %{conn: conn, valid_params: valid
end end
test "returns forbidden if token is invalid", %{conn: conn, valid_params: valid_params} do test "returns forbidden if token is invalid", %{conn: conn, valid_params: valid_params} do
conn = put_req_header(conn, "authorization", "Bearer " <> "invalid-token") res =
conn
|> put_req_header("authorization", "Bearer " <> "invalid-token")
|> put_req_header("content-type", "multipart/form-data")
|> post("/api/v1/accounts", valid_params)
res = post(conn, "/api/v1/accounts", valid_params)
assert json_response(res, 403) == %{"error" => "Invalid credentials"} assert json_response(res, 403) == %{"error" => "Invalid credentials"}
end end
end end
@ -956,10 +970,12 @@ test "respects rate limit setting", %{conn: conn} do
conn conn
|> put_req_header("authorization", "Bearer " <> app_token.token) |> put_req_header("authorization", "Bearer " <> app_token.token)
|> Map.put(:remote_ip, {15, 15, 15, 15}) |> Map.put(:remote_ip, {15, 15, 15, 15})
|> put_req_header("content-type", "multipart/form-data")
for i <- 1..2 do for i <- 1..2 do
conn = conn =
post(conn, "/api/v1/accounts", %{ conn
|> post("/api/v1/accounts", %{
username: "#{i}lain", username: "#{i}lain",
email: "#{i}lain@example.org", email: "#{i}lain@example.org",
password: "PlzDontHackLain", password: "PlzDontHackLain",

View File

@ -18,11 +18,11 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
test "it registers a new user and returns the user." do test "it registers a new user and returns the user." do
data = %{ data = %{
"nickname" => "lain", :nickname => "lain",
"email" => "lain@wired.jp", :email => "lain@wired.jp",
"fullname" => "lain iwakura", :fullname => "lain iwakura",
"password" => "bear", :password => "bear",
"confirm" => "bear" :confirm => "bear"
} }
{:ok, user} = TwitterAPI.register_user(data) {:ok, user} = TwitterAPI.register_user(data)
@ -35,12 +35,12 @@ test "it registers a new user and returns the user." do
test "it registers a new user with empty string in bio and returns the user." do test "it registers a new user with empty string in bio and returns the user." do
data = %{ data = %{
"nickname" => "lain", :nickname => "lain",
"email" => "lain@wired.jp", :email => "lain@wired.jp",
"fullname" => "lain iwakura", :fullname => "lain iwakura",
"bio" => "", :bio => "",
"password" => "bear", :password => "bear",
"confirm" => "bear" :confirm => "bear"
} }
{:ok, user} = TwitterAPI.register_user(data) {:ok, user} = TwitterAPI.register_user(data)
@ -60,12 +60,12 @@ test "it sends confirmation email if :account_activation_required is specified i
end end
data = %{ data = %{
"nickname" => "lain", :nickname => "lain",
"email" => "lain@wired.jp", :email => "lain@wired.jp",
"fullname" => "lain iwakura", :fullname => "lain iwakura",
"bio" => "", :bio => "",
"password" => "bear", :password => "bear",
"confirm" => "bear" :confirm => "bear"
} }
{:ok, user} = TwitterAPI.register_user(data) {:ok, user} = TwitterAPI.register_user(data)
@ -87,23 +87,23 @@ test "it sends confirmation email if :account_activation_required is specified i
test "it registers a new user and parses mentions in the bio" do test "it registers a new user and parses mentions in the bio" do
data1 = %{ data1 = %{
"nickname" => "john", :nickname => "john",
"email" => "john@gmail.com", :email => "john@gmail.com",
"fullname" => "John Doe", :fullname => "John Doe",
"bio" => "test", :bio => "test",
"password" => "bear", :password => "bear",
"confirm" => "bear" :confirm => "bear"
} }
{:ok, user1} = TwitterAPI.register_user(data1) {:ok, user1} = TwitterAPI.register_user(data1)
data2 = %{ data2 = %{
"nickname" => "lain", :nickname => "lain",
"email" => "lain@wired.jp", :email => "lain@wired.jp",
"fullname" => "lain iwakura", :fullname => "lain iwakura",
"bio" => "@john test", :bio => "@john test",
"password" => "bear", :password => "bear",
"confirm" => "bear" :confirm => "bear"
} }
{:ok, user2} = TwitterAPI.register_user(data2) {:ok, user2} = TwitterAPI.register_user(data2)
@ -123,13 +123,13 @@ test "returns user on success" do
{:ok, invite} = UserInviteToken.create_invite() {:ok, invite} = UserInviteToken.create_invite()
data = %{ data = %{
"nickname" => "vinny", :nickname => "vinny",
"email" => "pasta@pizza.vs", :email => "pasta@pizza.vs",
"fullname" => "Vinny Vinesauce", :fullname => "Vinny Vinesauce",
"bio" => "streamer", :bio => "streamer",
"password" => "hiptofbees", :password => "hiptofbees",
"confirm" => "hiptofbees", :confirm => "hiptofbees",
"token" => invite.token :token => invite.token
} }
{:ok, user} = TwitterAPI.register_user(data) {:ok, user} = TwitterAPI.register_user(data)
@ -145,13 +145,13 @@ test "returns user on success" do
test "returns error on invalid token" do test "returns error on invalid token" do
data = %{ data = %{
"nickname" => "GrimReaper", :nickname => "GrimReaper",
"email" => "death@reapers.afterlife", :email => "death@reapers.afterlife",
"fullname" => "Reaper Grim", :fullname => "Reaper Grim",
"bio" => "Your time has come", :bio => "Your time has come",
"password" => "scythe", :password => "scythe",
"confirm" => "scythe", :confirm => "scythe",
"token" => "DudeLetMeInImAFairy" :token => "DudeLetMeInImAFairy"
} }
{:error, msg} = TwitterAPI.register_user(data) {:error, msg} = TwitterAPI.register_user(data)
@ -165,13 +165,13 @@ test "returns error on expired token" do
UserInviteToken.update_invite!(invite, used: true) UserInviteToken.update_invite!(invite, used: true)
data = %{ data = %{
"nickname" => "GrimReaper", :nickname => "GrimReaper",
"email" => "death@reapers.afterlife", :email => "death@reapers.afterlife",
"fullname" => "Reaper Grim", :fullname => "Reaper Grim",
"bio" => "Your time has come", :bio => "Your time has come",
"password" => "scythe", :password => "scythe",
"confirm" => "scythe", :confirm => "scythe",
"token" => invite.token :token => invite.token
} }
{:error, msg} = TwitterAPI.register_user(data) {:error, msg} = TwitterAPI.register_user(data)
@ -186,16 +186,16 @@ test "returns error on expired token" do
setup do setup do
data = %{ data = %{
"nickname" => "vinny", :nickname => "vinny",
"email" => "pasta@pizza.vs", :email => "pasta@pizza.vs",
"fullname" => "Vinny Vinesauce", :fullname => "Vinny Vinesauce",
"bio" => "streamer", :bio => "streamer",
"password" => "hiptofbees", :password => "hiptofbees",
"confirm" => "hiptofbees" :confirm => "hiptofbees"
} }
check_fn = fn invite -> check_fn = fn invite ->
data = Map.put(data, "token", invite.token) data = Map.put(data, :token, invite.token)
{:ok, user} = TwitterAPI.register_user(data) {:ok, user} = TwitterAPI.register_user(data)
fetched_user = User.get_cached_by_nickname("vinny") fetched_user = User.get_cached_by_nickname("vinny")
@ -250,13 +250,13 @@ test "returns user on success, after him registration fails" do
UserInviteToken.update_invite!(invite, uses: 99) UserInviteToken.update_invite!(invite, uses: 99)
data = %{ data = %{
"nickname" => "vinny", :nickname => "vinny",
"email" => "pasta@pizza.vs", :email => "pasta@pizza.vs",
"fullname" => "Vinny Vinesauce", :fullname => "Vinny Vinesauce",
"bio" => "streamer", :bio => "streamer",
"password" => "hiptofbees", :password => "hiptofbees",
"confirm" => "hiptofbees", :confirm => "hiptofbees",
"token" => invite.token :token => invite.token
} }
{:ok, user} = TwitterAPI.register_user(data) {:ok, user} = TwitterAPI.register_user(data)
@ -269,13 +269,13 @@ test "returns user on success, after him registration fails" do
AccountView.render("show.json", %{user: fetched_user}) AccountView.render("show.json", %{user: fetched_user})
data = %{ data = %{
"nickname" => "GrimReaper", :nickname => "GrimReaper",
"email" => "death@reapers.afterlife", :email => "death@reapers.afterlife",
"fullname" => "Reaper Grim", :fullname => "Reaper Grim",
"bio" => "Your time has come", :bio => "Your time has come",
"password" => "scythe", :password => "scythe",
"confirm" => "scythe", :confirm => "scythe",
"token" => invite.token :token => invite.token
} }
{:error, msg} = TwitterAPI.register_user(data) {:error, msg} = TwitterAPI.register_user(data)
@ -292,13 +292,13 @@ test "returns user on success" do
{:ok, invite} = UserInviteToken.create_invite(%{expires_at: Date.utc_today(), max_use: 100}) {:ok, invite} = UserInviteToken.create_invite(%{expires_at: Date.utc_today(), max_use: 100})
data = %{ data = %{
"nickname" => "vinny", :nickname => "vinny",
"email" => "pasta@pizza.vs", :email => "pasta@pizza.vs",
"fullname" => "Vinny Vinesauce", :fullname => "Vinny Vinesauce",
"bio" => "streamer", :bio => "streamer",
"password" => "hiptofbees", :password => "hiptofbees",
"confirm" => "hiptofbees", :confirm => "hiptofbees",
"token" => invite.token :token => invite.token
} }
{:ok, user} = TwitterAPI.register_user(data) {:ok, user} = TwitterAPI.register_user(data)
@ -317,13 +317,13 @@ test "error after max uses" do
UserInviteToken.update_invite!(invite, uses: 99) UserInviteToken.update_invite!(invite, uses: 99)
data = %{ data = %{
"nickname" => "vinny", :nickname => "vinny",
"email" => "pasta@pizza.vs", :email => "pasta@pizza.vs",
"fullname" => "Vinny Vinesauce", :fullname => "Vinny Vinesauce",
"bio" => "streamer", :bio => "streamer",
"password" => "hiptofbees", :password => "hiptofbees",
"confirm" => "hiptofbees", :confirm => "hiptofbees",
"token" => invite.token :token => invite.token
} }
{:ok, user} = TwitterAPI.register_user(data) {:ok, user} = TwitterAPI.register_user(data)
@ -335,13 +335,13 @@ test "error after max uses" do
AccountView.render("show.json", %{user: fetched_user}) AccountView.render("show.json", %{user: fetched_user})
data = %{ data = %{
"nickname" => "GrimReaper", :nickname => "GrimReaper",
"email" => "death@reapers.afterlife", :email => "death@reapers.afterlife",
"fullname" => "Reaper Grim", :fullname => "Reaper Grim",
"bio" => "Your time has come", :bio => "Your time has come",
"password" => "scythe", :password => "scythe",
"confirm" => "scythe", :confirm => "scythe",
"token" => invite.token :token => invite.token
} }
{:error, msg} = TwitterAPI.register_user(data) {:error, msg} = TwitterAPI.register_user(data)
@ -355,13 +355,13 @@ test "returns error on overdue date" do
UserInviteToken.create_invite(%{expires_at: Date.add(Date.utc_today(), -1), max_use: 100}) UserInviteToken.create_invite(%{expires_at: Date.add(Date.utc_today(), -1), max_use: 100})
data = %{ data = %{
"nickname" => "GrimReaper", :nickname => "GrimReaper",
"email" => "death@reapers.afterlife", :email => "death@reapers.afterlife",
"fullname" => "Reaper Grim", :fullname => "Reaper Grim",
"bio" => "Your time has come", :bio => "Your time has come",
"password" => "scythe", :password => "scythe",
"confirm" => "scythe", :confirm => "scythe",
"token" => invite.token :token => invite.token
} }
{:error, msg} = TwitterAPI.register_user(data) {:error, msg} = TwitterAPI.register_user(data)
@ -377,13 +377,13 @@ test "returns error on with overdue date and after max" do
UserInviteToken.update_invite!(invite, uses: 100) UserInviteToken.update_invite!(invite, uses: 100)
data = %{ data = %{
"nickname" => "GrimReaper", :nickname => "GrimReaper",
"email" => "death@reapers.afterlife", :email => "death@reapers.afterlife",
"fullname" => "Reaper Grim", :fullname => "Reaper Grim",
"bio" => "Your time has come", :bio => "Your time has come",
"password" => "scythe", :password => "scythe",
"confirm" => "scythe", :confirm => "scythe",
"token" => invite.token :token => invite.token
} }
{:error, msg} = TwitterAPI.register_user(data) {:error, msg} = TwitterAPI.register_user(data)
@ -395,11 +395,11 @@ test "returns error on with overdue date and after max" do
test "it returns the error on registration problems" do test "it returns the error on registration problems" do
data = %{ data = %{
"nickname" => "lain", :nickname => "lain",
"email" => "lain@wired.jp", :email => "lain@wired.jp",
"fullname" => "lain iwakura", :fullname => "lain iwakura",
"bio" => "close the world.", :bio => "close the world.",
"password" => "bear" :password => "bear"
} }
{:error, error_object} = TwitterAPI.register_user(data) {:error, error_object} = TwitterAPI.register_user(data)