From cd8a81ced0e4ee224b19c47e6ab7d00b6f342348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Tom=C3=A1s?= Date: Thu, 25 Jan 2024 19:34:09 +0000 Subject: [PATCH] fix tests --- lib/galaxies/accounts.ex | 7 ++++++- .../live/player_confirmation_instructions_live.ex | 2 +- lib/galaxies_web/live/player_settings_live.ex | 1 + test/galaxies/accounts_test.exs | 2 +- .../controllers/player_session_controller_test.exs | 2 +- test/galaxies_web/live/player_registration_live_test.exs | 6 +++--- test/support/fixtures/accounts_fixtures.ex | 3 ++- 7 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/galaxies/accounts.ex b/lib/galaxies/accounts.ex index 5240a57..577cd26 100644 --- a/lib/galaxies/accounts.ex +++ b/lib/galaxies/accounts.ex @@ -76,11 +76,16 @@ defmodule Galaxies.Accounts do """ def register_player(attrs) do home_planet_id = Ecto.UUID.generate() + attrs = + Enum.reduce(attrs, %{}, fn + {key, value}, acc when is_atom(key) -> Map.put(acc, key, value) + {key, value}, acc when is_binary(key) -> Map.put(acc, String.to_existing_atom(key), value) + end) player_changeset = Player.registration_changeset( %Player{}, - Map.put(attrs, "current_planet_id", home_planet_id) + Map.put(attrs, :current_planet_id, home_planet_id) ) Ecto.Multi.new() diff --git a/lib/galaxies_web/live/player_confirmation_instructions_live.ex b/lib/galaxies_web/live/player_confirmation_instructions_live.ex index 5847be7..8ae9f6d 100644 --- a/lib/galaxies_web/live/player_confirmation_instructions_live.ex +++ b/lib/galaxies_web/live/player_confirmation_instructions_live.ex @@ -29,7 +29,7 @@ defmodule GalaxiesWeb.PlayerConfirmationInstructionsLive do end def mount(_params, _session, socket) do - {:ok, assign(socket, form: to_form(%{}, as: "player"))} + {:ok, assign(socket, form: to_form(%{}, as: "player")), layout: {GalaxiesWeb.Layouts, :single}} end def handle_event("send_instructions", %{"player" => %{"email" => email}}, socket) do diff --git a/lib/galaxies_web/live/player_settings_live.ex b/lib/galaxies_web/live/player_settings_live.ex index 48fd3b3..4dc3d45 100644 --- a/lib/galaxies_web/live/player_settings_live.ex +++ b/lib/galaxies_web/live/player_settings_live.ex @@ -116,6 +116,7 @@ defmodule GalaxiesWeb.PlayerSettingsLive do socket = socket + |> assign(:current_planet, Accounts.get_active_planet(socket.assigns.current_player)) |> assign(:current_password, nil) |> assign(:email_form_current_password, nil) |> assign(:username_form_current_password, nil) diff --git a/test/galaxies/accounts_test.exs b/test/galaxies/accounts_test.exs index 5743ccd..4783132 100644 --- a/test/galaxies/accounts_test.exs +++ b/test/galaxies/accounts_test.exs @@ -94,7 +94,7 @@ defmodule Galaxies.AccountsTest do test "registers players with a hashed password" do email = unique_player_email() - {:ok, player} = Accounts.register_player(valid_player_attributes(email: email)) + {:ok, %{player: player}} = Accounts.register_player(valid_player_attributes(email: email)) assert player.email == email assert is_binary(player.hashed_password) assert is_nil(player.confirmed_at) diff --git a/test/galaxies_web/controllers/player_session_controller_test.exs b/test/galaxies_web/controllers/player_session_controller_test.exs index 61b4a42..49f4f15 100644 --- a/test/galaxies_web/controllers/player_session_controller_test.exs +++ b/test/galaxies_web/controllers/player_session_controller_test.exs @@ -20,7 +20,7 @@ defmodule GalaxiesWeb.PlayerSessionControllerTest do # Now do a logged in request and assert on the menu conn = get(conn, ~p"/overview") response = html_response(conn, 200) - assert response =~ player.email + assert response =~ player.username assert response =~ ~p"/players/settings" assert response =~ ~p"/players/log_out" end diff --git a/test/galaxies_web/live/player_registration_live_test.exs b/test/galaxies_web/live/player_registration_live_test.exs index 89219cc..1e36260 100644 --- a/test/galaxies_web/live/player_registration_live_test.exs +++ b/test/galaxies_web/live/player_registration_live_test.exs @@ -40,8 +40,8 @@ defmodule GalaxiesWeb.PlayerRegistrationLiveTest do test "creates account and logs the player in", %{conn: conn} do {:ok, lv, _html} = live(conn, ~p"/players/register") - email = unique_player_email() - form = form(lv, "#registration_form", player: valid_player_attributes(email: email)) + username = unique_player_username() + form = form(lv, "#registration_form", player: valid_player_attributes(username: username)) render_submit(form) conn = follow_trigger_action(form, conn) @@ -50,7 +50,7 @@ defmodule GalaxiesWeb.PlayerRegistrationLiveTest do # Now do a logged in request and assert on the menu conn = get(conn, "/overview") response = html_response(conn, 200) - assert response =~ email + assert response =~ username assert response =~ "Settings" assert response =~ "Log out" end diff --git a/test/support/fixtures/accounts_fixtures.ex b/test/support/fixtures/accounts_fixtures.ex index faa29ab..7ec226d 100644 --- a/test/support/fixtures/accounts_fixtures.ex +++ b/test/support/fixtures/accounts_fixtures.ex @@ -13,11 +13,12 @@ defmodule Galaxies.AccountsFixtures do username: unique_player_username(), email: unique_player_email(), password: valid_player_password() + # current_planet_id: "#{System.unique_integer()}" }) end def player_fixture(attrs \\ %{}) do - {:ok, player} = + {:ok, %{player: player}} = attrs |> valid_player_attributes() |> Galaxies.Accounts.register_player()