Skip to content

Instantly share code, notes, and snippets.

@hassox
Forked from faizaanshamsi/Test
Last active November 19, 2015 23:20
Show Gist options
  • Save hassox/7e15da64a9c3c9d18805 to your computer and use it in GitHub Desktop.
Save hassox/7e15da64a9c3c9d18805 to your computer and use it in GitHub Desktop.
%{guardian_default_claims: %{"aud" => "token", "exp" => 1448147286,
"iat" => 1447974486, "iss" => "DiffGeneratorApi",
"jti" => "17a5d7bf-0fb7-4a18-b85e-05c835b37046", "pem" => %{},
"sub" => "User:913"},
guardian_default_jwt: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJVc2VyOjkxMyIsInBlbSI6e30sImp0aSI6IjE3YTVkN2JmLTBmYjctNGExOC1iODVlLTA1YzgzNWIzNzA0NiIsImlzcyI6IkRpZmZHZW5lcmF0b3JBcGkiLCJpYXQiOjE0NDc5NzQ0ODYsImV4cCI6MTQ0ODE0NzI4NiwiYXVkIjoidG9rZW4ifQ.8Pq3tNjg1VNRQjXmEhdTxyp224V9PKEr0If6g1mupmE",
guardian_default_resource: %DiffGeneratorApi.User{__meta__: #Ecto.Schema.Metadata<:loaded>,
biography: nil, company: nil, email: "faizaan@nd.com",
encrypted_password: "$2b$04$aHOqkBP5efibcpn6kS417.euB6SCTwLVplbCn13U8cQOz6/c1wUm6",
first_name: nil, id: 914, inserted_at: #Ecto.DateTime<2015-11-19T23:08:06Z>,
is_financial_professional: true, last_name: nil, password: "password",
role: "client", title: nil,
updated_at: #Ecto.DateTime<2015-11-19T23:08:06Z>},
guardian_failure: {:error, :no_session}}
@also_valid_attrs %{email: "fas@nd.com", role: "client", is_financial_professional: true, password: "password"}
setup do
changeset = User.changeset(%User{}, @also_valid_attrs)
user = Repo.insert! changeset
{ :ok, jwt, full_claims } = Guardian.Plug.encode_and_sign(user, :api)
conn = conn()
|> put_req_header("accept", "application/vnd.api+json")
|> put_req_header("authorization", jwt) # set a realm here if you need one
{:ok, conn: conn, user: user, jwt: jwt, claims: full_claims}
end
test "shows chosen resource", %{conn: conn} do
user = Repo.insert! User.changeset(%User{}, @valid_attrs)
conn = get conn, user_path(conn, :show, user)
conn = Guardian.Plug.set_current_resource(conn, user)
require IEx
IEx.pry
assert json_response(conn, 200)["data"]["attributes"] == %{"id" => user.id,
"biography" => user.biography,
"company" => user.company,
"email" => user.email,
"first_name" => user.first_name,
"is_financial_professional" => user.is_financial_professional,
"last_name" => user.last_name,
"title" => user.title,
"role" => user.role}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment