Skip to content
Snippets Groups Projects
Commit a7f1f039 authored by mdmuradalahi's avatar mdmuradalahi
Browse files

5.3_TDD

parent 0972414f
No related branches found
No related tags found
No related merge requests found
Pipeline #47147 failed
......@@ -16,7 +16,7 @@ config :proptracker, Proptracker.Repo,
# We don't run a server during test. If one is required,
# you can enable the server option below.
config :proptracker, ProptrackerWeb.Endpoint,
http: [ip: {127, 0, 0, 1}, port: 4000],
http: [ip: {127, 0, 0, 1}, port: 4001],
secret_key_base: "iHDmR++9wq05btCX44LZWV6tfBprf9xTg5mr+vNSW0mM8G5Y2lH2RTHrWVisVwHL",
server: true
......@@ -37,5 +37,5 @@ config :phoenix_live_view,
enable_expensive_runtime_checks: true
# Hound Configuration
config :hound, driver: "chrome_driver", port: 58968 # update the port according to your local chrome_drive message
config :hound, driver: "chrome_driver", port: 62493 # update the port according to your local chrome_drive message
config :proptracker, sql_sandbox: true
defmodule ProptrackerWeb.SessionControllerTest do
use ProptrackerWeb.ConnCase
alias Proptracker.Accounts.User
alias Proptracker.Repo
@valid_user_attrs %{
name: "Test User",
username: "test_user",
password: "password123",
date_of_birth: ~D[1995-01-01],
phone_number: "123456789"
}
# Helper to create a user in the database
defp create_user(_) do
{:ok, user} = Repo.insert(%User{} |> User.changeset(@valid_user_attrs))
%{user: user}
end
describe "User login" do
setup [:create_user]
test "successful login redirects to advertisements page", %{conn: conn, user: user} do
# Simulate a POST request to the login endpoint
conn = post(conn, "/login", user: %{username: user.username, password: user.password})
# Assert the user is redirected to the advertisements page
assert redirected_to(conn) == "/advertisements"
# Assert a flash message is set
assert get_flash(conn, :info) == "Logged in successfully."
# Assert the session contains the user ID
assert get_session(conn, :user_id) == user.id
end
test "failed login due to invalid credentials", %{conn: conn} do
# Simulate a POST request to the login endpoint with incorrect credentials
conn = post(conn, "/login", user: %{username: "wrong_username", password: "wrong_password"})
# Assert the response renders the login page
assert html_response(conn, 200) =~ "Invalid username or password."
# Assert a flash error message is set
assert get_flash(conn, :error) == "Invalid username or password."
# Assert the session does not contain a user ID
refute get_session(conn, :user_id)
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment