1
0
mirror of https://github.com/danbee/chess synced 2025-03-04 08:39:06 +00:00
chess/test/features/session_test.exs
2018-03-05 10:19:47 -05:00

65 lines
2.0 KiB
Elixir

defmodule Chess.SessionTest do
use ChessWeb.FeatureCase
import Wallaby.Query
import Chess.Factory
test "user cannot log in with incorrect email", %{session: session} do
insert(:user, %{email: "link@hyrule.kingdom", password: "ilovezelda"})
session
|> visit("/")
|> click(css(".user-nav a", text: "Log in"))
|> fill_in(text_field("Email"), with: "link@example.com")
|> fill_in(text_field("Password"), with: "ilovezelda")
|> click(button("Log in"))
assert session |> has_text?("Bad email or password")
end
test "user cannot log in with incorrect password", %{session: session} do
insert(:user, %{email: "link@hyrule.kingdom", password: "ilovezelda"})
session
|> visit("/")
|> click(css(".user-nav a", text: "Log in"))
|> fill_in(text_field("Email"), with: "link@hyrule.kingdom")
|> fill_in(text_field("Password"), with: "calamityganon")
|> click(button("Log in"))
assert session |> has_text?("Bad email or password")
end
test "user can log in with correct details", %{session: session} do
insert(:user, %{email: "link@hyrule.kingdom", password: "ilovezelda"})
session
|> visit("/")
|> click(css(".user-nav a", text: "Log in"))
|> fill_in(text_field("Email"), with: "link@hyrule.kingdom")
|> fill_in(text_field("Password"), with: "ilovezelda")
|> click(button("Log in"))
assert session |> has_text?("You are logged in")
assert session |> has_text?("Listing games")
assert session |> has_text?("link@hyrule.kingdom")
end
test "user can log out", %{session: session} do
insert(:user, %{email: "link@hyrule.kingdom", password: "ilovezelda"})
session
|> visit("/")
|> click(css(".user-nav a", text: "Log in"))
|> fill_in(text_field("Email"), with: "link@hyrule.kingdom")
|> fill_in(text_field("Password"), with: "ilovezelda")
|> click(button("Log in"))
session
|> visit("/")
|> click(link("Log out"))
assert session |> has_text?("You are logged out")
end
end