Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
ksevelyar committed Jul 13, 2024
1 parent 65e5f02 commit 75a718b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/habits/users/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defmodule Habits.Users.User do
defp validate_handle(changeset) do
changeset
|> validate_required([:handle])
|> validate_format(:handle, ~r/^[^\s]+@[^\s]+$/, message: "must have the @ sign and no spaces")
|> validate_format(:handle, ~r/^[^\s]+$/, message: "must have no spaces")
|> validate_length(:handle, min: 3, max: 20)
|> unsafe_validate_unique(:handle, Habits.Repo)
|> unique_constraint(:handle)
Expand Down
1 change: 0 additions & 1 deletion lib/habits_web/controllers/user_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ defmodule HabitsWeb.UserController do
with {:ok, %User{} = user} <- Users.create_user(user_params) do
conn
|> put_status(:created)
|> put_resp_header("location", ~p"/api/users/#{user}")
|> render(:show, user: user)
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/habits_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ defmodule HabitsWeb.Router do
plug :accepts, ["json"]
end

scope "/api", HabitsWeb do
scope "/", HabitsWeb do
pipe_through :api

resources "/users", UserController, only: [:create]
end

# Enable LiveDashboard and Swoosh mailbox preview in development
Expand Down
17 changes: 7 additions & 10 deletions test/habits/users_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,25 @@ defmodule Habits.UsersTest do
end

test "create_user/1 with valid data creates a user" do
valid_attrs = %{handle: "some handle", email: "some email", hashed_password: "some hashed_password", confirmed_at: ~N[2024-07-05 19:47:00]}
valid_attrs = %{handle: "handle", email: "some@email", password: "some password"}

assert {:ok, %User{} = user} = Users.create_user(valid_attrs)
assert user.handle == "some handle"
assert user.email == "some email"
assert user.hashed_password == "some hashed_password"
assert user.confirmed_at == ~N[2024-07-05 19:47:00]
assert user.handle == "handle"
assert user.email == "some@email"
end

test "create_user/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Users.create_user(@invalid_attrs)
end

@tag :skip
test "update_user/2 with valid data updates the user" do
user = user_fixture()
update_attrs = %{handle: "some updated handle", email: "some updated email", hashed_password: "some updated hashed_password", confirmed_at: ~N[2024-07-06 19:47:00]}
update_attrs = %{handle: "updated_handle", email: "updated@email"}

assert {:ok, %User{} = user} = Users.update_user(user, update_attrs)
assert user.handle == "some updated handle"
assert user.email == "some updated email"
assert user.hashed_password == "some updated hashed_password"
assert user.confirmed_at == ~N[2024-07-06 19:47:00]
assert user.handle == "updated_handle"
assert user.email == "updated@email"
end

test "update_user/2 with invalid data returns error changeset" do
Expand Down
7 changes: 3 additions & 4 deletions test/support/fixtures/users_fixtures.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ defmodule Habits.UsersFixtures do
{:ok, user} =
attrs
|> Enum.into(%{
confirmed_at: ~N[2024-07-05 19:47:00],
email: "some email",
handle: "some handle",
hashed_password: "some hashed_password"
email: "some@email",
handle: "handle",
password: "123456789🐗abc"
})
|> Habits.Users.create_user()

Expand Down

0 comments on commit 75a718b

Please sign in to comment.