Skip to content

Instantly share code, notes, and snippets.

@younesmln
Created August 20, 2016 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save younesmln/fe4a55ce9d2af796f99c75943c5768cd to your computer and use it in GitHub Desktop.
Save younesmln/fe4a55ce9d2af796f99c75943c5768cd to your computer and use it in GitHub Desktop.
defmodule Trello.AuthControllerTest do
use Trello.ConnCase
alias Trello.User
@valid_attrs %{email: "test@test.fr", f_name: "younes", l_name: "some content", password: "1234"}
setup %{conn: conn} do
{:ok, conn: put_req_header(conn, "accept", "application/json")}
end
test "login with invalid informations", %{conn: conn} do
credentials = %{login: "user.email", password: "dummy"}
conn = post(conn, auth_path(conn, :create), user: credentials)
assert json_response(conn, :unprocessable_entity) == Trello.AuthView.render("error.json")
end
test "login with valid informations and get a token", %{conn: conn} do
user = User.changeset(%User{}, @valid_attrs) |> Repo.insert!
credentials = %{login: user.email, password: user.password}
conn = post(conn, auth_path(conn, :create), user: credentials)
assert json_response(conn, 200)["token"]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment