add accounts doctests

This commit is contained in:
2023-01-29 14:30:42 -05:00
committed by oliviasculley
parent 6dbadc58ae
commit 737484c36e
11 changed files with 245 additions and 153 deletions

View File

@ -10,6 +10,8 @@ defmodule Lokal.AccountsTest do
@moduletag :accounts_test
doctest Accounts, import: true
describe "get_user_by_email/1" do
test "does not return the user if the email does not exist" do
refute Accounts.get_user_by_email("unknown@example.com")
@ -104,7 +106,7 @@ defmodule Lokal.AccountsTest do
describe "change_user_registration/2" do
test "returns a changeset" do
assert %Changeset{} = changeset = Accounts.change_user_registration(%User{})
assert %Changeset{} = changeset = Accounts.change_user_registration()
assert changeset.required == [:password, :email]
end
@ -112,8 +114,7 @@ defmodule Lokal.AccountsTest do
email = unique_user_email()
password = valid_user_password()
changeset =
Accounts.change_user_registration(%User{}, %{"email" => email, "password" => password})
changeset = Accounts.change_user_registration(%{"email" => email, "password" => password})
assert changeset.valid?
assert get_change(changeset, :email) == email

View File

@ -3,7 +3,7 @@ defmodule Lokal.Fixtures do
This module defines test helpers for creating entities
"""
alias Lokal.{Accounts, Accounts.User, Email}
alias Lokal.{Accounts, Accounts.User, Email, Repo}
def unique_user_email, do: "user#{System.unique_integer()}@example.com"
def valid_user_password, do: "hello world!"
@ -26,11 +26,12 @@ defmodule Lokal.Fixtures do
attrs
|> Enum.into(%{
"email" => unique_user_email(),
"password" => valid_user_password(),
"role" => "admin"
"password" => valid_user_password()
})
|> Accounts.register_user()
|> unwrap_ok_tuple()
|> User.role_changeset(:admin)
|> Repo.update!()
end
def extract_user_token(fun) do