From 4a05c537cb5b7a46a7bc1bb183fc213b748ed5c1 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Wed, 30 Sep 2020 17:21:35 +0100 Subject: [PATCH] create AppTest helper functions for #65 --- test/app/person_test.exs | 4 ++-- test/support/data_case.ex | 1 + test/test_helper.exs | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/test/app/person_test.exs b/test/app/person_test.exs index 11184877..51247943 100644 --- a/test/app/person_test.exs +++ b/test/app/person_test.exs @@ -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 diff --git a/test/support/data_case.ex b/test/support/data_case.ex index d5188cbb..9ddeb40a 100644 --- a/test/support/data_case.ex +++ b/test/support/data_case.ex @@ -22,6 +22,7 @@ defmodule App.DataCase do import Ecto.Changeset import Ecto.Query import App.DataCase + import AppTest end end diff --git a/test/test_helper.exs b/test/test_helper.exs index 4fe7a40f..675b3b33 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -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 \ No newline at end of file