Skip to content
Snippets Groups Projects

Resolve "FR-03: User Logout"

Merged shyngys requested to merge 13-fr-03-user-logout into main
10 files
+ 218
23
Compare changes
  • Side-by-side
  • Inline
Files
10
+ 79
0
defmodule UserLogoutContext do
use WhiteBread.Context
use Hound.Helpers
alias PropTrackr.Accounts
alias PropTrackr.Repo
alias PropTrackr.Accounts.User
scenario_starting_state fn _state ->
Ecto.Adapters.SQL.Sandbox.checkout(PropTrackr.Repo)
Ecto.Adapters.SQL.Sandbox.mode(PropTrackr.Repo, {:shared, self()})
Hound.start_session()
%{}
end
scenario_finalize fn _status, _state ->
Ecto.Adapters.SQL.Sandbox.checkin(PropTrackr.Repo)
Hound.end_session()
end
given_ ~r/^there exists following accounts$/, fn state, %{table_data: table} ->
table
|> Enum.map(fn user_details -> User.changeset(%User{}, user_details) end)
|> Enum.each(fn changeset -> Repo.insert!(changeset) end)
existing_user = List.first(table)
{
:ok,
state
|> Map.put(:email, existing_user[:email])
|> Map.put(:password, existing_user[:password])
}
end
given_ ~r/^I am logged in$/, fn state ->
navigate_to("/login")
fill_field({:id, "email"}, state[:email])
fill_field({:id, "password"}, state[:password])
click({:id, "login_button"})
assert visible_in_page? ~r"Successfully logged in!"
assert current_path() == "/"
navigate_to("/users")
{:ok, state}
end
when_ ~r/^I click the logout button$/, fn state ->
click({:id, "logout_button"})
{:ok, state}
end
then_ ~r/^I should be logged out$/, fn state ->
assert visible_in_page? ~r"You are successfully logged out"
{:ok, state}
end
and_ ~r/^I should be redirected to the home page$/, fn state ->
assert current_path() == "/"
{:ok, state}
end
given_ ~r/^I am not logged in$/, fn state ->
navigate_to("/")
{:ok, state}
end
when_ ~r/^I try to access the logout functionality$/, fn state ->
navigate_to("/logout")
{:ok, state}
end
then_ ~r/^I should see an error message$/, fn state ->
assert visible_in_page? ~r"You are not logged in"
{:ok, state}
end
end
Loading