Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Nelson committed Oct 20, 2023
1 parent 47a5919 commit f516052
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
7 changes: 7 additions & 0 deletions lib/factory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ defmodule LaunchCart.Factory do
}
end

def unconfirmed_user_factory() do
%User{
email: Internet.email(),
hashed_password: Bcrypt.hash_pwd_salt("password")
}
end

def stripe_account_factory() do
%StripeAccount{
name: "My account",
Expand Down
18 changes: 11 additions & 7 deletions test/launch_cart/accounts_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ defmodule LaunchCart.AccountsTest do

assert %User{id: ^id} = Accounts.get_user_by_email_and_password(user.email, "password")
end

end

describe "get_user!/1" do
Expand Down Expand Up @@ -85,15 +84,21 @@ defmodule LaunchCart.AccountsTest do
email = unique_user_email()

{:ok, %User{id: user_id} = user} =
Accounts.register_user(%{email: email, notes: "I want to build something cool"})
Accounts.register_user(%{
email: email,
notes: "I want to build something cool",
password: "Password1234",
password_confirmation: "Password1234"
})

assert {:ok, %User{id: ^user_id, active?: true}} = Accounts.activate_user(user)
end

describe "change_user_registration/2" do
test "returns a changeset" do
assert %Ecto.Changeset{} = changeset = Accounts.change_user_registration(%User{})
assert changeset.required == [:email]
assert :password in changeset.required
assert :email in changeset.required
end

test "allows fields to be set" do
Expand All @@ -102,7 +107,7 @@ defmodule LaunchCart.AccountsTest do
changeset =
Accounts.change_user_registration(
%User{},
%{email: email}
%{email: email, password: "Password1234", password_confirmation: "Password1234"}
)

assert changeset.valid?
Expand Down Expand Up @@ -203,7 +208,6 @@ defmodule LaunchCart.AccountsTest do
assert changed_user.email != user.email
assert changed_user.email == email
assert changed_user.confirmed_at
assert changed_user.confirmed_at != user.confirmed_at
refute Repo.get_by(UserToken, user_id: user.id)
end

Expand Down Expand Up @@ -355,7 +359,7 @@ defmodule LaunchCart.AccountsTest do

describe "deliver_user_confirmation_instructions/2" do
setup do
%{user: insert(:user)}
%{user: insert(:unconfirmed_user)}
end

test "sends token through notification", %{user: user} do
Expand All @@ -374,7 +378,7 @@ defmodule LaunchCart.AccountsTest do

describe "confirm_user/1" do
setup do
user = insert(:user)
user = insert(:unconfirmed_user)

token =
extract_user_token(fn url ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule LaunchCartWeb.UserConfirmationControllerTest do
import LaunchCart.Factory

setup do
%{user: insert(:user)}
%{user: insert(:unconfirmed_user)}
end

describe "GET /users/confirm" do
Expand Down

0 comments on commit f516052

Please sign in to comment.