Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
goncalotomas committed Jan 25, 2024
1 parent 51a24a1 commit cd8a81c
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 8 deletions.
7 changes: 6 additions & 1 deletion lib/galaxies/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/galaxies_web/live/player_settings_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/galaxies/accounts_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/galaxies_web/live/player_registration_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion test/support/fixtures/accounts_fixtures.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit cd8a81c

Please sign in to comment.