From 05efa59557d6e93c78700f1d999f4143c4f839ad Mon Sep 17 00:00:00 2001 From: Toby Archer Date: Fri, 25 Aug 2023 15:53:06 +0200 Subject: [PATCH] revert to contorller, update sdk --- elixir-ory-network/config/config.exs | 3 +- elixir-ory-network/config/dev.exs | 5 +- elixir-ory-network/lib/example_web.ex | 1 - .../lib/example_web/components/flow.ex | 4 +- .../controllers/auth_html/login.html.heex | 1 - .../auth_html/registration.html.heex | 1 - elixir-ory-network/lib/example_web/helpers.ex | 1 - elixir-ory-network/lib/example_web/router.ex | 5 +- elixir-ory-network/mix.exs | 2 +- elixir-ory-network/mix.lock | 2 +- .../test/example_web/live/auth_live_test.exs | 108 ++++++++++++++++++ 11 files changed, 120 insertions(+), 13 deletions(-) create mode 100644 elixir-ory-network/test/example_web/live/auth_live_test.exs diff --git a/elixir-ory-network/config/config.exs b/elixir-ory-network/config/config.exs index 79484f3e..34f950df 100644 --- a/elixir-ory-network/config/config.exs +++ b/elixir-ory-network/config/config.exs @@ -10,8 +10,7 @@ import Config config :example, ecto_repos: [Example.Repo] -config :example, Example.Repo, - database: "priv/database.db" +config :example, Example.Repo, database: "priv/database.db" # Configures the endpoint config :example, ExampleWeb.Endpoint, diff --git a/elixir-ory-network/config/dev.exs b/elixir-ory-network/config/dev.exs index fa88d46c..bca76ed2 100644 --- a/elixir-ory-network/config/dev.exs +++ b/elixir-ory-network/config/dev.exs @@ -1,9 +1,10 @@ import Config - # Configure your Ory Network URL config :ory_client, - :base_url, "http://localhost:3000/.ory" # Via ory proxy + # Via ory proxy + :base_url, + "http://localhost:3000/.ory" # For development, we disable any cache and enable # debugging and code reloading. diff --git a/elixir-ory-network/lib/example_web.ex b/elixir-ory-network/lib/example_web.ex index 9c9f1326..b6bb1ac0 100644 --- a/elixir-ory-network/lib/example_web.ex +++ b/elixir-ory-network/lib/example_web.ex @@ -45,7 +45,6 @@ defmodule ExampleWeb do import Plug.Conn import ExampleWeb.Gettext - unquote(verified_routes()) end end diff --git a/elixir-ory-network/lib/example_web/components/flow.ex b/elixir-ory-network/lib/example_web/components/flow.ex index f453c958..569da0eb 100644 --- a/elixir-ory-network/lib/example_web/components/flow.ex +++ b/elixir-ory-network/lib/example_web/components/flow.ex @@ -9,7 +9,9 @@ defmodule ExampleWeb.Flow do # TODO(@tobbbles): Figure out if this can be dynamically set up as a type union from Ory LoginFlow and RegistratinFlow attr :flow, :map, required: true - def flow(assigns) do + def flow(assigns) when not is_nil(assigns.flow) do + IO.inspect(assigns) + ~H""" <.ui_message_group flow={@flow} /> diff --git a/elixir-ory-network/lib/example_web/controllers/auth_html/login.html.heex b/elixir-ory-network/lib/example_web/controllers/auth_html/login.html.heex index ac093fb2..29358f11 100644 --- a/elixir-ory-network/lib/example_web/controllers/auth_html/login.html.heex +++ b/elixir-ory-network/lib/example_web/controllers/auth_html/login.html.heex @@ -3,4 +3,3 @@ - diff --git a/elixir-ory-network/lib/example_web/controllers/auth_html/registration.html.heex b/elixir-ory-network/lib/example_web/controllers/auth_html/registration.html.heex index fb7d29b5..ed742d7b 100644 --- a/elixir-ory-network/lib/example_web/controllers/auth_html/registration.html.heex +++ b/elixir-ory-network/lib/example_web/controllers/auth_html/registration.html.heex @@ -3,4 +3,3 @@ - diff --git a/elixir-ory-network/lib/example_web/helpers.ex b/elixir-ory-network/lib/example_web/helpers.ex index ea13ca2a..56ffe909 100644 --- a/elixir-ory-network/lib/example_web/helpers.ex +++ b/elixir-ory-network/lib/example_web/helpers.ex @@ -1,5 +1,4 @@ defmodule ExampleWeb.Helpers do - @doc """ Helper function to format request cookie map into string """ diff --git a/elixir-ory-network/lib/example_web/router.ex b/elixir-ory-network/lib/example_web/router.ex index 76661985..76dc8014 100644 --- a/elixir-ory-network/lib/example_web/router.ex +++ b/elixir-ory-network/lib/example_web/router.ex @@ -20,13 +20,14 @@ defmodule ExampleWeb.Router do pipe_through(:browser) get("/", PageController, :home) + end scope "/auth", ExampleWeb do pipe_through(:browser) - get("/login", AuthController, :login) - get("/register", AuthController, :registration) + get "/login", AuthController, :login + get "/register", AuthController, :registration end # Other scopes may use custom stacks. diff --git a/elixir-ory-network/mix.exs b/elixir-ory-network/mix.exs index 15207a33..b0f0e543 100644 --- a/elixir-ory-network/mix.exs +++ b/elixir-ory-network/mix.exs @@ -51,7 +51,7 @@ defmodule Example.MixProject do # {:ory_client, "~> 1.1.42"} {:ory_client, - git: "https://github.com/tobbbles/sdk.git", ref: "master", subdir: "clients/client/elixir"}, + git: "https://github.com/tobbbles/sdk.git", ref: "master", subdir: "clients/client/elixir"} ] end diff --git a/elixir-ory-network/mix.lock b/elixir-ory-network/mix.lock index 6d2e4626..fcac8fbe 100644 --- a/elixir-ory-network/mix.lock +++ b/elixir-ory-network/mix.lock @@ -18,7 +18,7 @@ "gettext": {:hex, :gettext, "0.22.3", "c8273e78db4a0bb6fba7e9f0fd881112f349a3117f7f7c598fa18c66c888e524", [:mix], [{:expo, "~> 0.4.0", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "935f23447713954a6866f1bb28c3a878c4c011e802bcd68a726f5e558e4b64bd"}, "jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"}, "mime": {:hex, :mime, "2.0.5", "dc34c8efd439abe6ae0343edbb8556f4d63f178594894720607772a041b04b02", [:mix], [], "hexpm", "da0d64a365c45bc9935cc5c8a7fc5e49a0e0f9932a761c55d6c52b142780a05c"}, - "ory_client": {:git, "https://github.com/tobbbles/sdk.git", "0bb32fa34f2cb62b27be7984a9f7ae6c468206c8", [ref: "master", subdir: "clients/client/elixir"]}, + "ory_client": {:git, "https://github.com/tobbbles/sdk.git", "c182ac6820a1620e115f40268ff0775cc4a2fc0c", [ref: "master", subdir: "clients/client/elixir"]}, "phoenix": {:hex, :phoenix, "1.7.6", "61f0625af7c1d1923d582470446de29b008c0e07ae33d7a3859ede247ddaf59a", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:websock_adapter, "~> 0.5.3", [hex: :websock_adapter, repo: "hexpm", optional: false]}], "hexpm", "f6b4be7780402bb060cbc6e83f1b6d3f5673b674ba73cc4a7dd47db0322dfb88"}, "phoenix_ecto": {:hex, :phoenix_ecto, "4.4.2", "b21bd01fdeffcfe2fab49e4942aa938b6d3e89e93a480d4aee58085560a0bc0d", [:mix], [{:ecto, "~> 3.5", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "70242edd4601d50b69273b057ecf7b684644c19ee750989fd555625ae4ce8f5d"}, "phoenix_html": {:hex, :phoenix_html, "3.3.1", "4788757e804a30baac6b3fc9695bf5562465dd3f1da8eb8460ad5b404d9a2178", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "bed1906edd4906a15fd7b412b85b05e521e1f67c9a85418c55999277e553d0d3"}, diff --git a/elixir-ory-network/test/example_web/live/auth_live_test.exs b/elixir-ory-network/test/example_web/live/auth_live_test.exs new file mode 100644 index 00000000..5d793064 --- /dev/null +++ b/elixir-ory-network/test/example_web/live/auth_live_test.exs @@ -0,0 +1,108 @@ +defmodule ExampleWeb.AuthLiveTest do + use ExampleWeb.ConnCase + + import Phoenix.LiveViewTest + import Example.AccountsFixtures + + @create_attrs %{} + @update_attrs %{} + @invalid_attrs %{} + + defp create_auth(_) do + auth = auth_fixture() + %{auth: auth} + end + + describe "Index" do + setup [:create_auth] + + test "lists all auth", %{conn: conn} do + {:ok, _index_live, html} = live(conn, ~p"/auth") + + assert html =~ "Listing Auth" + end + + test "saves new auth", %{conn: conn} do + {:ok, index_live, _html} = live(conn, ~p"/auth") + + assert index_live |> element("a", "New Auth") |> render_click() =~ + "New Auth" + + assert_patch(index_live, ~p"/auth/new") + + assert index_live + |> form("#auth-form", auth: @invalid_attrs) + |> render_change() =~ "can't be blank" + + assert index_live + |> form("#auth-form", auth: @create_attrs) + |> render_submit() + + assert_patch(index_live, ~p"/auth") + + html = render(index_live) + assert html =~ "Auth created successfully" + end + + test "updates auth in listing", %{conn: conn, auth: auth} do + {:ok, index_live, _html} = live(conn, ~p"/auth") + + assert index_live |> element("#auth-#{auth.id} a", "Edit") |> render_click() =~ + "Edit Auth" + + assert_patch(index_live, ~p"/auth/#{auth}/edit") + + assert index_live + |> form("#auth-form", auth: @invalid_attrs) + |> render_change() =~ "can't be blank" + + assert index_live + |> form("#auth-form", auth: @update_attrs) + |> render_submit() + + assert_patch(index_live, ~p"/auth") + + html = render(index_live) + assert html =~ "Auth updated successfully" + end + + test "deletes auth in listing", %{conn: conn, auth: auth} do + {:ok, index_live, _html} = live(conn, ~p"/auth") + + assert index_live |> element("#auth-#{auth.id} a", "Delete") |> render_click() + refute has_element?(index_live, "#auth-#{auth.id}") + end + end + + describe "Show" do + setup [:create_auth] + + test "displays auth", %{conn: conn, auth: auth} do + {:ok, _show_live, html} = live(conn, ~p"/auth/#{auth}") + + assert html =~ "Show Auth" + end + + test "updates auth within modal", %{conn: conn, auth: auth} do + {:ok, show_live, _html} = live(conn, ~p"/auth/#{auth}") + + assert show_live |> element("a", "Edit") |> render_click() =~ + "Edit Auth" + + assert_patch(show_live, ~p"/auth/#{auth}/show/edit") + + assert show_live + |> form("#auth-form", auth: @invalid_attrs) + |> render_change() =~ "can't be blank" + + assert show_live + |> form("#auth-form", auth: @update_attrs) + |> render_submit() + + assert_patch(show_live, ~p"/auth/#{auth}") + + html = render(show_live) + assert html =~ "Auth updated successfully" + end + end +end