-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f25794
commit 12bb586
Showing
10 changed files
with
173 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
defmodule Rocketpay.Users.CreateTest do | ||
use Rocketpay.DataCase, async: true | ||
|
||
alias Rocketpay.User | ||
alias Rocketpay.Users.Create | ||
|
||
describe "call/1" do | ||
test "when all params are valid, returns an user" do | ||
params = %{ | ||
name: "fabio", | ||
password: "123456", | ||
nickname: "fabiobarboza", | ||
email: "[email protected]", | ||
age: 27 | ||
} | ||
|
||
{:ok, %User{id: user_id}} = Create.call(params) | ||
user = Repo.get(User, user_id) | ||
|
||
assert %User{name: "fabio", age: 27, id: ^user_id} = user | ||
end | ||
|
||
test "when there are invalid params, returns an error" do | ||
params = %{ | ||
name: "fabio", | ||
nickname: "fabiobarboza", | ||
email: "[email protected]", | ||
age: 15 | ||
} | ||
|
||
{:error, changeset} = Create.call(params) | ||
|
||
expected_response = %{ | ||
age: ["must be greater than or equal to 18"], | ||
password: ["can't be blank"] | ||
} | ||
|
||
assert errors_on(changeset) == expected_response | ||
end | ||
end | ||
end |
50 changes: 50 additions & 0 deletions
50
test/rocketpay_web/controllers/accounts_controller_test.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
defmodule RocketpayWeb.AccountsControllerTest do | ||
use RocketpayWeb.ConnCase, async: true | ||
|
||
alias Rocketpay.{Account, User} | ||
|
||
describe "deposit/2" do | ||
setup %{conn: conn} do | ||
params = %{ | ||
name: "fabio", | ||
password: "123456", | ||
nickname: "fabiobarboza", | ||
email: "[email protected]", | ||
age: 27 | ||
} | ||
|
||
{:ok, %User{account: %Account{id: account_id}}} = Rocketpay.create_user(params) | ||
|
||
conn = put_req_header(conn, "authorization", "Basic YmFuYW5hOjEyMzQ1Ng==") | ||
|
||
{:ok, conn: conn, account_id: account_id} | ||
end | ||
|
||
test "when all params are valid, make the deposit", %{conn: conn, account_id: account_id} do | ||
params = %{"value" => "50.00"} | ||
|
||
response = | ||
conn | ||
|> post(Routes.accounts_path(conn, :deposit, account_id, params)) | ||
|> json_response(:ok) | ||
|
||
assert %{ | ||
"account" => %{"balance" => "50.00", "id" => _id}, | ||
"message" => "Ballance changed successfully" | ||
} = response | ||
end | ||
|
||
test "when there are invalid params, return an error", %{conn: conn, account_id: account_id} do | ||
params = %{"value" => "invalid"} | ||
|
||
response = | ||
conn | ||
|> post(Routes.accounts_path(conn, :deposit, account_id, params)) | ||
|> json_response(:bad_request) | ||
|
||
expected_response = %{"message" => "Invalid deposit value!"} | ||
|
||
assert response == expected_response | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
defmodule RocketpayWeb.UsersViewTest do | ||
use RocketpayWeb.ConnCase, async: true | ||
|
||
import Phoenix.View | ||
|
||
alias Rocketpay.{Account, User} | ||
alias RocketpayWeb.UsersView | ||
|
||
test "renders create.json" do | ||
params = %{ | ||
name: "fabio", | ||
password: "123456", | ||
nickname: "fabiobarboza", | ||
email: "[email protected]", | ||
age: 27 | ||
} | ||
|
||
{:ok, %User{id: user_id, account: %Account{id: account_id}} = user} = | ||
Rocketpay.create_user(params) | ||
|
||
response = render(UsersView, "create.json", user: user) | ||
|
||
expected_response = %{ | ||
message: "User created", | ||
user: %{ | ||
account: %{ | ||
balance: Decimal.new("0.00"), | ||
id: account_id | ||
}, | ||
id: user_id, | ||
name: "fabio", | ||
nickname: "fabiobarboza" | ||
} | ||
} | ||
|
||
assert response == expected_response | ||
end | ||
end |