This file contains hidden or 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
| $ mix test test/contexts | |
| . | |
| Finished in 0.05 seconds | |
| 1 test, 0 failures | |
| Randomized with seed 163288 |
This file contains hidden or 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
| $ mix test | |
| ... | |
| 1) test inviting a user responds with the new user (MyApp.UserController.InviteTest) | |
| test/controllers/user_controller/invite_test.exs:4 | |
| ** (FunctionClauseError) no function clause matching in MyApp.Users.Invite.call/1 | |
| stacktrace: | |
| (my_app) lib/my_app/contexts/users/invite.ex:8: MyApp.Users.Invite.call(%{"email" => "alice@example.com"}) | |
| (my_app) web/controllers/user_controller.ex:5: MyApp.UserController.create/2 | |
| (my_app) web/controllers/user_controller.ex:1: MyApp.UserController.action/2 |
This file contains hidden or 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
| $ mix test | |
| Compiling 1 file (.ex) | |
| warning: variable user is unused | |
| web/controllers/user_controller.ex:6 | |
| .... | |
| 1) test inviting a user responds with the new user (MyApp.UserController.InviteTest) | |
| test/controllers/user_controller/invite_test.exs:4 | |
| Expected truthy, got false |
This file contains hidden or 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
| defmodule MyApp.UserController do | |
| use MyApp.Web, :controller | |
| def create(conn, params) do | |
| attrs = %{email: params["email"]} | |
| {:ok, user} = MyApp.Users.Invite.call(attrs) | |
| {:ok, body} = %{ | |
| id: user.id, | |
| email: user.email |
This file contains hidden or 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
| $ mix test | |
| Compiling 1 file (.ex) | |
| ..... | |
| Finished in 0.08 seconds | |
| 5 tests, 0 failures | |
| Randomized with seed 174980 |
This file contains hidden or 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
| test "invalid email gives a 400 response" do | |
| conn = | |
| build_conn | |
| |> post("/users", email: "Alice and Bob") | |
| body = conn |> response(400) |> Poison.decode! | |
| assert body["message"] == "email is invalid" | |
| end |
This file contains hidden or 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
| test "it handles invalid email" do | |
| {:error, :invalid_email} = Invite.call(%{email: "Alice and Bob"}) | |
| end |
This file contains hidden or 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
| def call(%{email: email}) do | |
| with :ok <- validate_email(email) do | |
| |> build_changeset | |
| |> create_user | |
| end | |
| end | |
| #... |
This file contains hidden or 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
| defmodule MyApp.UserController do | |
| use MyApp.Web, :controller | |
| def create(conn, params) do | |
| attrs = %{email: params["email"]} | |
| case MyApp.Users.Invite.call(attrs) do | |
| {:ok, user} -> | |
| render_user(conn, user) | |
| {:error, :invalid_email} -> |
This file contains hidden or 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
| defmodule MyApp.UserController do | |
| use MyApp.Web, :controller | |
| def create(conn, params) do | |
| attrs = %{email: params["email"]} | |
| case MyApp.Users.Invite.call(attrs) do | |
| {:ok, user} -> | |
| render_user(conn, user) | |
| {:error, :invalid_email} -> |