forked from shibao/cannery
		
	fix tests
This commit is contained in:
		
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -3,6 +3,6 @@ defmodule LokalWeb.PageControllerTest do
 | 
			
		||||
 | 
			
		||||
  test "GET /", %{conn: conn} do
 | 
			
		||||
    conn = get(conn, "/")
 | 
			
		||||
    assert html_response(conn, 200) =~ "Welcome to Phoenix!"
 | 
			
		||||
    assert html_response(conn, 200) =~ "Welcome to Lokal"
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
@@ -140,7 +140,7 @@ defmodule LokalWeb.UserAuthTest do
 | 
			
		||||
 | 
			
		||||
    test "stores the path to redirect to on GET", %{conn: conn} do
 | 
			
		||||
      halted_conn =
 | 
			
		||||
        %{conn | request_path: "/foo", query_string: ""}
 | 
			
		||||
        %{conn | path_info: ["foo"], query_string: ""}
 | 
			
		||||
        |> fetch_flash()
 | 
			
		||||
        |> UserAuth.require_authenticated_user([])
 | 
			
		||||
 | 
			
		||||
@@ -148,7 +148,7 @@ defmodule LokalWeb.UserAuthTest do
 | 
			
		||||
      assert get_session(halted_conn, :user_return_to) == "/foo"
 | 
			
		||||
 | 
			
		||||
      halted_conn =
 | 
			
		||||
        %{conn | request_path: "/foo", query_string: "bar=baz"}
 | 
			
		||||
        %{conn | path_info: ["foo"], query_string: "bar=baz"}
 | 
			
		||||
        |> fetch_flash()
 | 
			
		||||
        |> UserAuth.require_authenticated_user([])
 | 
			
		||||
 | 
			
		||||
@@ -156,7 +156,7 @@ defmodule LokalWeb.UserAuthTest do
 | 
			
		||||
      assert get_session(halted_conn, :user_return_to) == "/foo?bar=baz"
 | 
			
		||||
 | 
			
		||||
      halted_conn =
 | 
			
		||||
        %{conn | request_path: "/foo?bar", method: "POST"}
 | 
			
		||||
        %{conn | path_info: ["foo"], query_string: "bar", method: "POST"}
 | 
			
		||||
        |> fetch_flash()
 | 
			
		||||
        |> UserAuth.require_authenticated_user([])
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -13,7 +13,7 @@ defmodule LokalWeb.UserConfirmationControllerTest do
 | 
			
		||||
    test "renders the confirmation page", %{conn: conn} do
 | 
			
		||||
      conn = get(conn, Routes.user_confirmation_path(conn, :new))
 | 
			
		||||
      response = html_response(conn, 200)
 | 
			
		||||
      assert response =~ "<h1>Resend confirmation instructions</h1>"
 | 
			
		||||
      assert response =~ "Resend confirmation instructions"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,7 @@ defmodule LokalWeb.UserRegistrationControllerTest do
 | 
			
		||||
    test "renders registration page", %{conn: conn} do
 | 
			
		||||
      conn = get(conn, Routes.user_registration_path(conn, :new))
 | 
			
		||||
      response = html_response(conn, 200)
 | 
			
		||||
      assert response =~ "<h1>Register</h1>"
 | 
			
		||||
      assert response =~ "Register"
 | 
			
		||||
      assert response =~ "Log in</a>"
 | 
			
		||||
      assert response =~ "Register</a>"
 | 
			
		||||
    end
 | 
			
		||||
@@ -46,7 +46,7 @@ defmodule LokalWeb.UserRegistrationControllerTest do
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
      response = html_response(conn, 200)
 | 
			
		||||
      assert response =~ "<h1>Register</h1>"
 | 
			
		||||
      assert response =~ "Register"
 | 
			
		||||
      assert response =~ "must have the @ sign and no spaces"
 | 
			
		||||
      assert response =~ "should be at least 12 character"
 | 
			
		||||
    end
 | 
			
		||||
 
 | 
			
		||||
@@ -13,7 +13,7 @@ defmodule LokalWeb.UserResetPasswordControllerTest do
 | 
			
		||||
    test "renders the reset password page", %{conn: conn} do
 | 
			
		||||
      conn = get(conn, Routes.user_reset_password_path(conn, :new))
 | 
			
		||||
      response = html_response(conn, 200)
 | 
			
		||||
      assert response =~ "<h1>Forgot your password?</h1>"
 | 
			
		||||
      assert response =~ "Forgot your password?"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
@@ -54,7 +54,7 @@ defmodule LokalWeb.UserResetPasswordControllerTest do
 | 
			
		||||
 | 
			
		||||
    test "renders reset password", %{conn: conn, token: token} do
 | 
			
		||||
      conn = get(conn, Routes.user_reset_password_path(conn, :edit, token))
 | 
			
		||||
      assert html_response(conn, 200) =~ "<h1>Reset password</h1>"
 | 
			
		||||
      assert html_response(conn, 200) =~ "Reset password"
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    test "does not render reset password with invalid token", %{conn: conn} do
 | 
			
		||||
@@ -99,7 +99,7 @@ defmodule LokalWeb.UserResetPasswordControllerTest do
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
      response = html_response(conn, 200)
 | 
			
		||||
      assert response =~ "<h1>Reset password</h1>"
 | 
			
		||||
      assert response =~ "Reset password"
 | 
			
		||||
      assert response =~ "should be at least 12 character(s)"
 | 
			
		||||
      assert response =~ "does not match password"
 | 
			
		||||
    end
 | 
			
		||||
 
 | 
			
		||||
@@ -11,9 +11,8 @@ defmodule LokalWeb.UserSessionControllerTest do
 | 
			
		||||
    test "renders log in page", %{conn: conn} do
 | 
			
		||||
      conn = get(conn, Routes.user_session_path(conn, :new))
 | 
			
		||||
      response = html_response(conn, 200)
 | 
			
		||||
      assert response =~ "<h1>Log in</h1>"
 | 
			
		||||
      assert response =~ "Log in</a>"
 | 
			
		||||
      assert response =~ "Register</a>"
 | 
			
		||||
      assert response =~ "Log in"
 | 
			
		||||
      assert response =~ "Register"
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    test "redirects if already logged in", %{conn: conn, user: user} do
 | 
			
		||||
@@ -75,7 +74,7 @@ defmodule LokalWeb.UserSessionControllerTest do
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
      response = html_response(conn, 200)
 | 
			
		||||
      assert response =~ "<h1>Log in</h1>"
 | 
			
		||||
      assert response =~ "Log in"
 | 
			
		||||
      assert response =~ "Invalid email or password"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,7 @@ defmodule LokalWeb.UserSettingsControllerTest do
 | 
			
		||||
    test "renders settings page", %{conn: conn} do
 | 
			
		||||
      conn = get(conn, Routes.user_settings_path(conn, :edit))
 | 
			
		||||
      response = html_response(conn, 200)
 | 
			
		||||
      assert response =~ "<h1>Settings</h1>"
 | 
			
		||||
      assert response =~ "Settings"
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    test "redirects if user is not logged in" do
 | 
			
		||||
@@ -50,7 +50,7 @@ defmodule LokalWeb.UserSettingsControllerTest do
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
      response = html_response(old_password_conn, 200)
 | 
			
		||||
      assert response =~ "<h1>Settings</h1>"
 | 
			
		||||
      assert response =~ "Settings"
 | 
			
		||||
      assert response =~ "should be at least 12 character(s)"
 | 
			
		||||
      assert response =~ "does not match password"
 | 
			
		||||
      assert response =~ "is not valid"
 | 
			
		||||
@@ -83,7 +83,7 @@ defmodule LokalWeb.UserSettingsControllerTest do
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
      response = html_response(conn, 200)
 | 
			
		||||
      assert response =~ "<h1>Settings</h1>"
 | 
			
		||||
      assert response =~ "Settings"
 | 
			
		||||
      assert response =~ "must have the @ sign and no spaces"
 | 
			
		||||
      assert response =~ "is not valid"
 | 
			
		||||
    end
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,7 @@ defmodule LokalWeb.PageLiveTest do
 | 
			
		||||
 | 
			
		||||
  test "disconnected and connected render", %{conn: conn} do
 | 
			
		||||
    {:ok, page_live, disconnected_html} = live(conn, "/")
 | 
			
		||||
    assert disconnected_html =~ "Welcome to Phoenix!"
 | 
			
		||||
    assert render(page_live) =~ "Welcome to Phoenix!"
 | 
			
		||||
    assert disconnected_html =~ "Welcome to Lokal"
 | 
			
		||||
    assert render(page_live) =~ "Welcome to Lokal"
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
@@ -7,27 +7,6 @@ defmodule Lokal.AccountsFixtures do
 | 
			
		||||
  def unique_user_email, do: "user#{System.unique_integer()}@example.com"
 | 
			
		||||
  def valid_user_password, do: "hello world!"
 | 
			
		||||
 | 
			
		||||
  def user_fixture(attrs \\ %{}) do
 | 
			
		||||
    {:ok, user} =
 | 
			
		||||
      attrs
 | 
			
		||||
      |> Enum.into(%{
 | 
			
		||||
        email: unique_user_email(),
 | 
			
		||||
        password: valid_user_password()
 | 
			
		||||
      })
 | 
			
		||||
      |> Lokal.Accounts.register_user()
 | 
			
		||||
 | 
			
		||||
    user
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def extract_user_token(fun) do
 | 
			
		||||
    {:ok, captured} = fun.(&"[TOKEN]#{&1}[TOKEN]")
 | 
			
		||||
    [_, token, _] = String.split(captured.body, "[TOKEN]")
 | 
			
		||||
    token
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def unique_user_email, do: "user#{System.unique_integer()}@example.com"
 | 
			
		||||
  def valid_user_password, do: "hello world!"
 | 
			
		||||
 | 
			
		||||
  def valid_user_attributes(attrs \\ %{}) do
 | 
			
		||||
    Enum.into(attrs, %{
 | 
			
		||||
      email: unique_user_email(),
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user