Skip to content

Commit

Permalink
create AppTest helper functions for #65
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Sep 30, 2020
1 parent b5baf20 commit 4a05c53
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions test/app/person_test.exs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
defmodule App.CtxTest do
defmodule App.PersonTest do
use App.DataCase
alias App.Person

describe "people" do
@valid_attrs %{
status: 1,
status: 1
}
@update_attrs %{
status: 2
Expand Down
1 change: 1 addition & 0 deletions test/support/data_case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ defmodule App.DataCase do
import Ecto.Changeset
import Ecto.Query
import App.DataCase
import AppTest
end
end

Expand Down
37 changes: 37 additions & 0 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -1,2 +1,39 @@
ExUnit.start()
Ecto.Adapters.SQL.Sandbox.mode(App.Repo, :manual)
import Plug.Conn
import Phoenix.ConnTest

defmodule AppTest do
def person_data do
rand = :rand.uniform(1_000_000)
%{
email: "alex+#{rand}@gmail.com",
givenName: "Alex",
auth_provider: "email",
picture: "https://avatars3.githubusercontent.com/u/10835816",
status: 1,
app_id: 42
}
end

def create_person(data) do
App.Person.create_person(data)
end

def create_person do
data = person_data()
create_person(data)
end

def person_login() do
data = person_data()
person = create_person(data)
IO.inspect(person, label: "person:20")
conn = build_conn()
|> fetch_session
# IO.inspect(conn, label: "conn:22")
merged = Map.merge(data, %{id: person.id})
IO.inspect(merged, label: "merged:24")
{:ok, conn: AuthPlug.create_jwt_session(conn, merged)}
end
end

0 comments on commit 4a05c53

Please sign in to comment.