This commit is contained in:
parent
64320dbdae
commit
5a41d8b3e7
@ -11,11 +11,11 @@ defmodule Memex.InvitesTest do
|
||||
@moduletag :invites_test
|
||||
|
||||
@valid_attrs %{
|
||||
"name" => "some name"
|
||||
name: "some name"
|
||||
}
|
||||
@invalid_attrs %{
|
||||
"name" => nil,
|
||||
"token" => nil
|
||||
name: nil,
|
||||
token: nil
|
||||
}
|
||||
|
||||
describe "invites" do
|
||||
@ -57,7 +57,7 @@ defmodule Memex.InvitesTest do
|
||||
|
||||
assert {:ok, _user} =
|
||||
Accounts.register_user(
|
||||
%{"email" => unique_user_email(), "password" => valid_user_password()},
|
||||
%{email: unique_user_email(), password: valid_user_password()},
|
||||
token
|
||||
)
|
||||
|
||||
@ -65,7 +65,7 @@ defmodule Memex.InvitesTest do
|
||||
|
||||
assert {:ok, _user} =
|
||||
Accounts.register_user(
|
||||
%{"email" => unique_user_email(), "password" => valid_user_password()},
|
||||
%{email: unique_user_email(), password: valid_user_password()},
|
||||
token
|
||||
)
|
||||
|
||||
@ -81,13 +81,13 @@ defmodule Memex.InvitesTest do
|
||||
|
||||
assert {:ok, _user} =
|
||||
Accounts.register_user(
|
||||
%{"email" => unique_user_email(), "password" => valid_user_password()},
|
||||
%{email: unique_user_email(), password: valid_user_password()},
|
||||
token
|
||||
)
|
||||
|
||||
assert {:ok, _user} =
|
||||
Accounts.register_user(
|
||||
%{"email" => unique_user_email(), "password" => valid_user_password()},
|
||||
%{email: unique_user_email(), password: valid_user_password()},
|
||||
another_token
|
||||
)
|
||||
|
||||
@ -97,7 +97,7 @@ defmodule Memex.InvitesTest do
|
||||
|
||||
assert {:ok, _user} =
|
||||
Accounts.register_user(
|
||||
%{"email" => unique_user_email(), "password" => valid_user_password()},
|
||||
%{email: unique_user_email(), password: valid_user_password()},
|
||||
token
|
||||
)
|
||||
|
||||
@ -138,10 +138,7 @@ defmodule Memex.InvitesTest do
|
||||
|
||||
test "create_invite/1 with valid data creates an unlimited invite",
|
||||
%{current_user: current_user} do
|
||||
assert {:ok, %Invite{} = invite} =
|
||||
Invites.create_invite(current_user, %{
|
||||
"name" => "some name"
|
||||
})
|
||||
assert {:ok, %Invite{} = invite} = Invites.create_invite(current_user, %{name: "some name"})
|
||||
|
||||
assert invite.name == "some name"
|
||||
end
|
||||
@ -149,10 +146,7 @@ defmodule Memex.InvitesTest do
|
||||
test "create_invite/1 with valid data creates a limited invite",
|
||||
%{current_user: current_user} do
|
||||
assert {:ok, %Invite{} = invite} =
|
||||
Invites.create_invite(current_user, %{
|
||||
"name" => "some name",
|
||||
"uses_left" => 10
|
||||
})
|
||||
Invites.create_invite(current_user, %{name: "some name", uses_left: 10})
|
||||
|
||||
assert invite.name == "some name"
|
||||
assert invite.uses_left == 10
|
||||
@ -168,7 +162,7 @@ defmodule Memex.InvitesTest do
|
||||
assert {:ok, %Invite{} = new_invite} =
|
||||
Invites.update_invite(
|
||||
invite,
|
||||
%{"name" => "some updated name", "uses_left" => 5},
|
||||
%{name: "some updated name", uses_left: 5},
|
||||
current_user
|
||||
)
|
||||
|
||||
@ -183,7 +177,7 @@ defmodule Memex.InvitesTest do
|
||||
assert {:ok, %Invite{} = new_invite} =
|
||||
Invites.update_invite(
|
||||
invite,
|
||||
%{"name" => "some updated name", "uses_left" => nil},
|
||||
%{name: "some updated name", uses_left: nil},
|
||||
current_user
|
||||
)
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
defmodule Memex.ContextsTest do
|
||||
use Memex.DataCase
|
||||
import Memex.ContextsFixtures
|
||||
import Memex.Fixtures
|
||||
alias Memex.{Contexts, Contexts.Context}
|
||||
@moduletag :contexts_test
|
||||
@invalid_attrs %{content: nil, tag: nil, slug: nil, visibility: nil}
|
||||
@ -152,10 +152,10 @@ defmodule Memex.ContextsTest do
|
||||
|
||||
test "create_context/1 with valid data creates a context", %{user: user} do
|
||||
valid_attrs = %{
|
||||
"content" => "some content",
|
||||
"tags_string" => "tag1,tag2",
|
||||
"slug" => "some-slug",
|
||||
"visibility" => :public
|
||||
content: "some content",
|
||||
tags_string: "tag1,tag2",
|
||||
slug: "some-slug",
|
||||
visibility: :public
|
||||
}
|
||||
|
||||
assert {:ok, %Context{} = context} = Contexts.create_context(valid_attrs, user)
|
||||
@ -173,10 +173,10 @@ defmodule Memex.ContextsTest do
|
||||
context = context_fixture(user)
|
||||
|
||||
update_attrs = %{
|
||||
"content" => "some updated content",
|
||||
"tags_string" => "tag1,tag2",
|
||||
"slug" => "some-updated-slug",
|
||||
"visibility" => :private
|
||||
content: "some updated content",
|
||||
tags_string: "tag1,tag2",
|
||||
slug: "some-updated-slug",
|
||||
visibility: :private
|
||||
}
|
||||
|
||||
assert {:ok, %Context{} = context} = Contexts.update_context(context, update_attrs, user)
|
||||
|
@ -1,6 +1,6 @@
|
||||
defmodule Memex.NotesTest do
|
||||
use Memex.DataCase
|
||||
import Memex.NotesFixtures
|
||||
import Memex.Fixtures
|
||||
alias Memex.{Notes, Notes.Note}
|
||||
@moduletag :notes_test
|
||||
@invalid_attrs %{content: nil, tag: nil, slug: nil, visibility: nil}
|
||||
@ -154,10 +154,10 @@ defmodule Memex.NotesTest do
|
||||
|
||||
test "create_note/1 with valid data creates a note", %{user: user} do
|
||||
valid_attrs = %{
|
||||
"content" => "some content",
|
||||
"tags_string" => "tag1,tag2",
|
||||
"slug" => "some-slug",
|
||||
"visibility" => :public
|
||||
content: "some content",
|
||||
tags_string: "tag1,tag2",
|
||||
slug: "some-slug",
|
||||
visibility: :public
|
||||
}
|
||||
|
||||
assert {:ok, %Note{} = note} = Notes.create_note(valid_attrs, user)
|
||||
@ -175,10 +175,10 @@ defmodule Memex.NotesTest do
|
||||
note = note_fixture(user)
|
||||
|
||||
update_attrs = %{
|
||||
"content" => "some updated content",
|
||||
"tags_string" => "tag1,tag2",
|
||||
"slug" => "some-updated-slug",
|
||||
"visibility" => :private
|
||||
content: "some updated content",
|
||||
tags_string: "tag1,tag2",
|
||||
slug: "some-updated-slug",
|
||||
visibility: :private
|
||||
}
|
||||
|
||||
assert {:ok, %Note{} = note} = Notes.update_note(note, update_attrs, user)
|
||||
|
@ -1,6 +1,6 @@
|
||||
defmodule Memex.PipelinesTest do
|
||||
use Memex.DataCase
|
||||
import Memex.PipelinesFixtures
|
||||
import Memex.Fixtures
|
||||
alias Memex.{Pipelines, Pipelines.Pipeline}
|
||||
@moduletag :pipelines_test
|
||||
@invalid_attrs %{description: nil, tag: nil, slug: nil, visibility: nil}
|
||||
@ -154,10 +154,10 @@ defmodule Memex.PipelinesTest do
|
||||
|
||||
test "create_pipeline/1 with valid data creates a pipeline", %{user: user} do
|
||||
valid_attrs = %{
|
||||
"description" => "some description",
|
||||
"tags_string" => "tag1,tag2",
|
||||
"slug" => "some-slug",
|
||||
"visibility" => :public
|
||||
description: "some description",
|
||||
tags_string: "tag1,tag2",
|
||||
slug: "some-slug",
|
||||
visibility: :public
|
||||
}
|
||||
|
||||
assert {:ok, %Pipeline{} = pipeline} = Pipelines.create_pipeline(valid_attrs, user)
|
||||
@ -175,10 +175,10 @@ defmodule Memex.PipelinesTest do
|
||||
pipeline = pipeline_fixture(user)
|
||||
|
||||
update_attrs = %{
|
||||
"description" => "some updated description",
|
||||
"tags_string" => "tag1,tag2",
|
||||
"slug" => "some-updated-slug",
|
||||
"visibility" => :private
|
||||
description: "some updated description",
|
||||
tags_string: "tag1,tag2",
|
||||
slug: "some-updated-slug",
|
||||
visibility: :private
|
||||
}
|
||||
|
||||
assert {:ok, %Pipeline{} = pipeline} =
|
||||
|
@ -1,6 +1,6 @@
|
||||
defmodule Memex.StepsTest do
|
||||
use Memex.DataCase
|
||||
import Memex.{PipelinesFixtures, StepsFixtures}
|
||||
import Memex.Fixtures
|
||||
alias Memex.Pipelines.{Steps, Steps.Step}
|
||||
@moduletag :steps_test
|
||||
@invalid_attrs %{content: nil, title: nil}
|
||||
@ -37,8 +37,8 @@ defmodule Memex.StepsTest do
|
||||
|
||||
test "create_step/4 with valid data creates a step", %{pipeline: pipeline, user: user} do
|
||||
valid_attrs = %{
|
||||
"content" => "some content",
|
||||
"title" => "some title"
|
||||
content: "some content",
|
||||
title: "some title"
|
||||
}
|
||||
|
||||
assert {:ok, %Step{} = step} = Steps.create_step(valid_attrs, 0, pipeline, user)
|
||||
@ -55,8 +55,8 @@ defmodule Memex.StepsTest do
|
||||
step = step_fixture(0, pipeline, user)
|
||||
|
||||
update_attrs = %{
|
||||
"content" => "some updated content",
|
||||
"title" => "some updated title"
|
||||
content: "some updated content",
|
||||
title: "some updated title"
|
||||
}
|
||||
|
||||
assert {:ok, %Step{} = step} = Steps.update_step(step, update_attrs, user)
|
||||
|
@ -4,7 +4,7 @@ defmodule MemexWeb.ExportControllerTest do
|
||||
"""
|
||||
|
||||
use MemexWeb.ConnCase
|
||||
import Memex.{ContextsFixtures, NotesFixtures, PipelinesFixtures, StepsFixtures}
|
||||
import Memex.Fixtures
|
||||
|
||||
@moduletag :export_controller_test
|
||||
|
||||
|
@ -4,7 +4,6 @@ defmodule MemexWeb.UserAuthTest do
|
||||
"""
|
||||
|
||||
use MemexWeb.ConnCase, async: true
|
||||
import MemexWeb.Gettext
|
||||
alias Memex.Accounts
|
||||
alias MemexWeb.UserAuth
|
||||
|
||||
@ -45,7 +44,6 @@ defmodule MemexWeb.UserAuthTest do
|
||||
conn |> fetch_cookies() |> UserAuth.log_in_user(current_user, %{"remember_me" => "true"})
|
||||
|
||||
assert get_session(conn, :user_token) == conn.cookies[@remember_me_cookie]
|
||||
|
||||
assert %{value: signed_token, max_age: max_age} = conn.resp_cookies[@remember_me_cookie]
|
||||
assert signed_token != get_session(conn, :user_token)
|
||||
assert max_age == 5_184_000
|
||||
@ -148,7 +146,7 @@ defmodule MemexWeb.UserAuthTest do
|
||||
assert redirected_to(conn) == Routes.user_session_path(conn, :new)
|
||||
|
||||
assert get_flash(conn, :error) ==
|
||||
dgettext("errors", "You must confirm your account and log in to access this page.")
|
||||
"You must confirm your account and log in to access this page."
|
||||
end
|
||||
|
||||
test "stores the path to redirect to on GET", %{conn: conn} do
|
||||
|
@ -4,7 +4,6 @@ defmodule MemexWeb.UserConfirmationControllerTest do
|
||||
"""
|
||||
|
||||
use MemexWeb.ConnCase, async: true
|
||||
import MemexWeb.Gettext
|
||||
alias Memex.{Accounts, Repo}
|
||||
|
||||
@moduletag :user_confirmation_controller_test
|
||||
@ -17,7 +16,7 @@ defmodule MemexWeb.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 =~ dgettext("actions", "Resend confirmation instructions")
|
||||
assert response =~ "Resend confirmation instructions"
|
||||
end
|
||||
end
|
||||
|
||||
@ -26,17 +25,13 @@ defmodule MemexWeb.UserConfirmationControllerTest do
|
||||
test "sends a new confirmation token", %{conn: conn, user: user} do
|
||||
conn =
|
||||
post(conn, Routes.user_confirmation_path(conn, :create), %{
|
||||
"user" => %{"email" => user.email}
|
||||
user: %{email: user.email}
|
||||
})
|
||||
|
||||
assert redirected_to(conn) == "/"
|
||||
|
||||
assert get_flash(conn, :info) =~
|
||||
dgettext(
|
||||
"prompts",
|
||||
"If your email is in our system and it has not been confirmed yet, " <>
|
||||
"you will receive an email with instructions shortly."
|
||||
)
|
||||
"If your email is in our system and it has not been confirmed yet, you will receive an email with instructions shortly."
|
||||
|
||||
assert Repo.get_by!(Accounts.UserToken, user_id: user.id).context == "confirm"
|
||||
end
|
||||
@ -46,33 +41,25 @@ defmodule MemexWeb.UserConfirmationControllerTest do
|
||||
|
||||
conn =
|
||||
post(conn, Routes.user_confirmation_path(conn, :create), %{
|
||||
"user" => %{"email" => user.email}
|
||||
user: %{email: user.email}
|
||||
})
|
||||
|
||||
assert redirected_to(conn) == "/"
|
||||
|
||||
assert get_flash(conn, :info) =~
|
||||
dgettext(
|
||||
"prompts",
|
||||
"If your email is in our system and it has not been confirmed yet, " <>
|
||||
"you will receive an email with instructions shortly."
|
||||
)
|
||||
"If your email is in our system and it has not been confirmed yet, you will receive an email with instructions shortly."
|
||||
end
|
||||
|
||||
test "does not send confirmation token if email is invalid", %{conn: conn} do
|
||||
conn =
|
||||
post(conn, Routes.user_confirmation_path(conn, :create), %{
|
||||
"user" => %{"email" => "unknown@example.com"}
|
||||
user: %{email: "unknown@example.com"}
|
||||
})
|
||||
|
||||
assert redirected_to(conn) == "/"
|
||||
|
||||
assert get_flash(conn, :info) =~
|
||||
dgettext(
|
||||
"prompts",
|
||||
"If your email is in our system and it has not been confirmed yet, " <>
|
||||
"you will receive an email with instructions shortly."
|
||||
)
|
||||
"If your email is in our system and it has not been confirmed yet, you will receive an email with instructions shortly."
|
||||
|
||||
assert Repo.all(Accounts.UserToken) == []
|
||||
end
|
||||
@ -88,8 +75,7 @@ defmodule MemexWeb.UserConfirmationControllerTest do
|
||||
conn = get(conn, Routes.user_confirmation_path(conn, :confirm, token))
|
||||
assert redirected_to(conn) == "/"
|
||||
|
||||
assert get_flash(conn, :info) =~
|
||||
dgettext("prompts", "%{email} confirmed successfully", email: user.email)
|
||||
assert get_flash(conn, :info) =~ "#{user.email} confirmed successfully"
|
||||
|
||||
assert Accounts.get_user!(user.id).confirmed_at
|
||||
refute get_session(conn, :user_token)
|
||||
@ -98,9 +84,7 @@ defmodule MemexWeb.UserConfirmationControllerTest do
|
||||
# When not logged in
|
||||
conn = get(conn, Routes.user_confirmation_path(conn, :confirm, token))
|
||||
assert redirected_to(conn) == "/"
|
||||
|
||||
assert get_flash(conn, :error) =~
|
||||
dgettext("errors", "User confirmation link is invalid or it has expired")
|
||||
assert get_flash(conn, :error) =~ "User confirmation link is invalid or it has expired"
|
||||
|
||||
# When logged in
|
||||
conn =
|
||||
@ -115,9 +99,7 @@ defmodule MemexWeb.UserConfirmationControllerTest do
|
||||
test "does not confirm email with invalid token", %{conn: conn, user: user} do
|
||||
conn = get(conn, Routes.user_confirmation_path(conn, :confirm, "oops"))
|
||||
assert redirected_to(conn) == "/"
|
||||
|
||||
assert get_flash(conn, :error) =~
|
||||
dgettext("errors", "User confirmation link is invalid or it has expired")
|
||||
assert get_flash(conn, :error) =~ "User confirmation link is invalid or it has expired"
|
||||
|
||||
refute Accounts.get_user!(user.id).confirmed_at
|
||||
end
|
||||
|
@ -4,7 +4,6 @@ defmodule MemexWeb.UserRegistrationControllerTest do
|
||||
"""
|
||||
|
||||
use MemexWeb.ConnCase, async: true
|
||||
import MemexWeb.Gettext
|
||||
|
||||
@moduletag :user_registration_controller_test
|
||||
|
||||
@ -12,8 +11,8 @@ defmodule MemexWeb.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 =~ dgettext("actions", "register")
|
||||
assert response =~ dgettext("actions", "log in")
|
||||
assert response =~ "register"
|
||||
assert response =~ "log in"
|
||||
end
|
||||
|
||||
test "redirects if already logged in", %{conn: conn} do
|
||||
@ -29,11 +28,11 @@ defmodule MemexWeb.UserRegistrationControllerTest do
|
||||
|
||||
conn =
|
||||
post(conn, Routes.user_registration_path(conn, :create), %{
|
||||
"user" => valid_user_attributes(email: email)
|
||||
user: valid_user_attributes(email: email)
|
||||
})
|
||||
|
||||
assert get_session(conn, :phoenix_flash) == %{
|
||||
"info" => dgettext("prompts", "please check your email to verify your account")
|
||||
"info" => "please check your email to verify your account"
|
||||
}
|
||||
|
||||
assert redirected_to(conn) =~ "/"
|
||||
@ -42,11 +41,11 @@ defmodule MemexWeb.UserRegistrationControllerTest do
|
||||
test "render errors for invalid data", %{conn: conn} do
|
||||
conn =
|
||||
post(conn, Routes.user_registration_path(conn, :create), %{
|
||||
"user" => %{"email" => "with spaces", "password" => "too short"}
|
||||
user: %{email: "with spaces", password: "too short"}
|
||||
})
|
||||
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ gettext("register")
|
||||
assert response =~ "register"
|
||||
assert response =~ "must have the @ sign and no spaces"
|
||||
assert response =~ "should be at least 12 character"
|
||||
end
|
||||
|
@ -4,7 +4,6 @@ defmodule MemexWeb.UserResetPasswordControllerTest do
|
||||
"""
|
||||
|
||||
use MemexWeb.ConnCase, async: true
|
||||
import MemexWeb.Gettext
|
||||
alias Memex.{Accounts, Repo}
|
||||
|
||||
@moduletag :user_reset_password_controller_test
|
||||
@ -17,7 +16,7 @@ defmodule MemexWeb.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 =~ dgettext("actions", "forgot your password?")
|
||||
assert response =~ "forgot your password?"
|
||||
end
|
||||
end
|
||||
|
||||
@ -26,16 +25,13 @@ defmodule MemexWeb.UserResetPasswordControllerTest do
|
||||
test "sends a new reset password token", %{conn: conn, user: user} do
|
||||
conn =
|
||||
post(conn, Routes.user_reset_password_path(conn, :create), %{
|
||||
"user" => %{"email" => user.email}
|
||||
user: %{email: user.email}
|
||||
})
|
||||
|
||||
assert redirected_to(conn) == "/"
|
||||
|
||||
assert get_flash(conn, :info) =~
|
||||
dgettext(
|
||||
"prompts",
|
||||
"If your email is in our system, you will receive instructions to reset your password shortly."
|
||||
)
|
||||
|
||||
assert Repo.get_by!(Accounts.UserToken, user_id: user.id).context == "reset_password"
|
||||
end
|
||||
@ -43,16 +39,13 @@ defmodule MemexWeb.UserResetPasswordControllerTest do
|
||||
test "does not send reset password token if email is invalid", %{conn: conn} do
|
||||
conn =
|
||||
post(conn, Routes.user_reset_password_path(conn, :create), %{
|
||||
"user" => %{"email" => "unknown@example.com"}
|
||||
user: %{email: "unknown@example.com"}
|
||||
})
|
||||
|
||||
assert redirected_to(conn) == "/"
|
||||
|
||||
assert get_flash(conn, :info) =~
|
||||
dgettext(
|
||||
"prompts",
|
||||
"If your email is in our system, you will receive instructions to reset your password shortly."
|
||||
)
|
||||
|
||||
assert Repo.all(Accounts.UserToken) == []
|
||||
end
|
||||
@ -70,15 +63,13 @@ defmodule MemexWeb.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) =~ dgettext("actions", "Reset password")
|
||||
assert html_response(conn, 200) =~ "Reset password"
|
||||
end
|
||||
|
||||
test "does not render reset password with invalid token", %{conn: conn} do
|
||||
conn = get(conn, Routes.user_reset_password_path(conn, :edit, "oops"))
|
||||
assert redirected_to(conn) == "/"
|
||||
|
||||
assert get_flash(conn, :error) =~
|
||||
dgettext("errors", "Reset password link is invalid or it has expired")
|
||||
assert get_flash(conn, :error) =~ "Reset password link is invalid or it has expired"
|
||||
end
|
||||
end
|
||||
|
||||
@ -95,39 +86,37 @@ defmodule MemexWeb.UserResetPasswordControllerTest do
|
||||
test "resets password once", %{conn: conn, user: user, token: token} do
|
||||
conn =
|
||||
put(conn, Routes.user_reset_password_path(conn, :update, token), %{
|
||||
"user" => %{
|
||||
"password" => "new valid password",
|
||||
"password_confirmation" => "new valid password"
|
||||
user: %{
|
||||
password: "new valid password",
|
||||
password_confirmation: "new valid password"
|
||||
}
|
||||
})
|
||||
|
||||
assert redirected_to(conn) == Routes.user_session_path(conn, :new)
|
||||
refute get_session(conn, :user_token)
|
||||
assert get_flash(conn, :info) =~ dgettext("prompts", "Password reset successfully")
|
||||
assert get_flash(conn, :info) =~ "Password reset successfully"
|
||||
assert Accounts.get_user_by_email_and_password(user.email, "new valid password")
|
||||
end
|
||||
|
||||
test "does not reset password on invalid data", %{conn: conn, token: token} do
|
||||
conn =
|
||||
put(conn, Routes.user_reset_password_path(conn, :update, token), %{
|
||||
"user" => %{
|
||||
"password" => "too short",
|
||||
"password_confirmation" => "does not match"
|
||||
user: %{
|
||||
password: "too short",
|
||||
password_confirmation: "does not match"
|
||||
}
|
||||
})
|
||||
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ gettext("Reset password")
|
||||
assert response =~ dgettext("errors", "should be at least 12 character(s)")
|
||||
assert response =~ dgettext("errors", "does not match password")
|
||||
assert response =~ "Reset password"
|
||||
assert response =~ "should be at least 12 character(s)"
|
||||
assert response =~ "does not match password"
|
||||
end
|
||||
|
||||
test "does not reset password with invalid token", %{conn: conn} do
|
||||
conn = put(conn, Routes.user_reset_password_path(conn, :update, "oops"))
|
||||
assert redirected_to(conn) == "/"
|
||||
|
||||
assert get_flash(conn, :error) =~
|
||||
dgettext("errors", "Reset password link is invalid or it has expired")
|
||||
assert get_flash(conn, :error) =~ "Reset password link is invalid or it has expired"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -4,7 +4,6 @@ defmodule MemexWeb.UserSessionControllerTest do
|
||||
"""
|
||||
|
||||
use MemexWeb.ConnCase, async: true
|
||||
import MemexWeb.Gettext
|
||||
|
||||
@moduletag :user_session_controller_test
|
||||
|
||||
@ -16,7 +15,7 @@ defmodule MemexWeb.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 =~ dgettext("actions", "log in")
|
||||
assert response =~ "log in"
|
||||
end
|
||||
|
||||
test "redirects if already logged in", %{conn: conn, current_user: current_user} do
|
||||
@ -29,7 +28,7 @@ defmodule MemexWeb.UserSessionControllerTest do
|
||||
test "logs the user in", %{conn: conn, current_user: current_user} do
|
||||
conn =
|
||||
post(conn, Routes.user_session_path(conn, :create), %{
|
||||
"user" => %{"email" => current_user.email, "password" => valid_user_password()}
|
||||
user: %{email: current_user.email, password: valid_user_password()}
|
||||
})
|
||||
|
||||
assert get_session(conn, :user_token)
|
||||
@ -39,16 +38,16 @@ defmodule MemexWeb.UserSessionControllerTest do
|
||||
conn = get(conn, "/")
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ current_user.email
|
||||
assert response =~ dgettext("prompts", "are you sure you want to log out?")
|
||||
assert response =~ "are you sure you want to log out?"
|
||||
end
|
||||
|
||||
test "logs the user in with remember me", %{conn: conn, current_user: current_user} do
|
||||
conn =
|
||||
post(conn, Routes.user_session_path(conn, :create), %{
|
||||
"user" => %{
|
||||
"email" => current_user.email,
|
||||
"password" => valid_user_password(),
|
||||
"remember_me" => "true"
|
||||
user: %{
|
||||
email: current_user.email,
|
||||
password: valid_user_password(),
|
||||
remember_me: "true"
|
||||
}
|
||||
})
|
||||
|
||||
@ -61,9 +60,9 @@ defmodule MemexWeb.UserSessionControllerTest do
|
||||
conn
|
||||
|> init_test_session(user_return_to: "/foo/bar")
|
||||
|> post(Routes.user_session_path(conn, :create), %{
|
||||
"user" => %{
|
||||
"email" => current_user.email,
|
||||
"password" => valid_user_password()
|
||||
user: %{
|
||||
email: current_user.email,
|
||||
password: valid_user_password()
|
||||
}
|
||||
})
|
||||
|
||||
@ -74,12 +73,12 @@ defmodule MemexWeb.UserSessionControllerTest do
|
||||
%{conn: conn, current_user: current_user} do
|
||||
conn =
|
||||
post(conn, Routes.user_session_path(conn, :create), %{
|
||||
"user" => %{"email" => current_user.email, "password" => "bad"}
|
||||
user: %{email: current_user.email, password: "bad"}
|
||||
})
|
||||
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ dgettext("actions", "log in")
|
||||
assert response =~ dgettext("errors", "Invalid email or password")
|
||||
assert response =~ "log in"
|
||||
assert response =~ "Invalid email or password"
|
||||
end
|
||||
end
|
||||
|
||||
@ -88,14 +87,14 @@ defmodule MemexWeb.UserSessionControllerTest do
|
||||
conn = conn |> log_in_user(current_user) |> delete(Routes.user_session_path(conn, :delete))
|
||||
assert redirected_to(conn) == "/"
|
||||
refute get_session(conn, :user_token)
|
||||
assert get_flash(conn, :info) =~ gettext("logged out successfully")
|
||||
assert get_flash(conn, :info) =~ "logged out successfully"
|
||||
end
|
||||
|
||||
test "succeeds even if the user is not logged in", %{conn: conn} do
|
||||
conn = delete(conn, Routes.user_session_path(conn, :delete))
|
||||
assert redirected_to(conn) == "/"
|
||||
refute get_session(conn, :user_token)
|
||||
assert get_flash(conn, :info) =~ gettext("logged out successfully")
|
||||
assert get_flash(conn, :info) =~ "logged out successfully"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -4,7 +4,6 @@ defmodule MemexWeb.UserSettingsControllerTest do
|
||||
"""
|
||||
|
||||
use MemexWeb.ConnCase, async: true
|
||||
import MemexWeb.Gettext
|
||||
alias Memex.Accounts
|
||||
|
||||
@moduletag :user_settings_controller_test
|
||||
@ -15,7 +14,7 @@ defmodule MemexWeb.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 =~ gettext("settings")
|
||||
assert response =~ "settings"
|
||||
end
|
||||
|
||||
test "redirects if user is not logged in" do
|
||||
@ -30,19 +29,17 @@ defmodule MemexWeb.UserSettingsControllerTest do
|
||||
%{conn: conn, current_user: current_user} do
|
||||
new_password_conn =
|
||||
put(conn, Routes.user_settings_path(conn, :update), %{
|
||||
"action" => "update_password",
|
||||
"current_password" => valid_user_password(),
|
||||
"user" => %{
|
||||
"password" => "new valid password",
|
||||
"password_confirmation" => "new valid password"
|
||||
action: "update_password",
|
||||
current_password: valid_user_password(),
|
||||
user: %{
|
||||
password: "new valid password",
|
||||
password_confirmation: "new valid password"
|
||||
}
|
||||
})
|
||||
|
||||
assert redirected_to(new_password_conn) == Routes.user_settings_path(conn, :edit)
|
||||
assert get_session(new_password_conn, :user_token) != get_session(conn, :user_token)
|
||||
|
||||
assert get_flash(new_password_conn, :info) =~
|
||||
dgettext("actions", "password updated successfully")
|
||||
assert get_flash(new_password_conn, :info) =~ "password updated successfully"
|
||||
|
||||
assert Accounts.get_user_by_email_and_password(current_user.email, "new valid password")
|
||||
end
|
||||
@ -50,19 +47,19 @@ defmodule MemexWeb.UserSettingsControllerTest do
|
||||
test "does not update password on invalid data", %{conn: conn} do
|
||||
old_password_conn =
|
||||
put(conn, Routes.user_settings_path(conn, :update), %{
|
||||
"action" => "update_password",
|
||||
"current_password" => "invalid",
|
||||
"user" => %{
|
||||
"password" => "too short",
|
||||
"password_confirmation" => "does not match"
|
||||
action: "update_password",
|
||||
current_password: "invalid",
|
||||
user: %{
|
||||
password: "too short",
|
||||
password_confirmation: "does not match"
|
||||
}
|
||||
})
|
||||
|
||||
response = html_response(old_password_conn, 200)
|
||||
assert response =~ gettext("settings")
|
||||
assert response =~ dgettext("errors", "should be at least 12 character(s)")
|
||||
assert response =~ dgettext("errors", "does not match password")
|
||||
assert response =~ dgettext("errors", "is not valid")
|
||||
assert response =~ "settings"
|
||||
assert response =~ "should be at least 12 character(s)"
|
||||
assert response =~ "does not match password"
|
||||
assert response =~ "is not valid"
|
||||
|
||||
assert get_session(old_password_conn, :user_token) == get_session(conn, :user_token)
|
||||
end
|
||||
@ -73,18 +70,15 @@ defmodule MemexWeb.UserSettingsControllerTest do
|
||||
test "updates the user email", %{conn: conn, current_user: current_user} do
|
||||
conn =
|
||||
put(conn, Routes.user_settings_path(conn, :update), %{
|
||||
"action" => "update_email",
|
||||
"current_password" => valid_user_password(),
|
||||
"user" => %{"email" => unique_user_email()}
|
||||
action: "update_email",
|
||||
current_password: valid_user_password(),
|
||||
user: %{"email" => unique_user_email()}
|
||||
})
|
||||
|
||||
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
|
||||
|
||||
assert get_flash(conn, :info) =~
|
||||
dgettext(
|
||||
"prompts",
|
||||
"a link to confirm your email change has been sent to the new address."
|
||||
)
|
||||
|
||||
assert Accounts.get_user_by_email(current_user.email)
|
||||
end
|
||||
@ -98,9 +92,9 @@ defmodule MemexWeb.UserSettingsControllerTest do
|
||||
})
|
||||
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ gettext("settings")
|
||||
assert response =~ dgettext("errors", "must have the @ sign and no spaces")
|
||||
assert response =~ dgettext("errors", "is not valid")
|
||||
assert response =~ "settings"
|
||||
assert response =~ "must have the @ sign and no spaces"
|
||||
assert response =~ "is not valid"
|
||||
end
|
||||
end
|
||||
|
||||
@ -124,24 +118,19 @@ defmodule MemexWeb.UserSettingsControllerTest do
|
||||
%{conn: conn, current_user: current_user, token: token, email: email} do
|
||||
conn = get(conn, Routes.user_settings_path(conn, :confirm_email, token))
|
||||
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
|
||||
assert get_flash(conn, :info) =~ dgettext("prompts", "email changed successfully")
|
||||
assert get_flash(conn, :info) =~ "email changed successfully"
|
||||
refute Accounts.get_user_by_email(current_user.email)
|
||||
assert Accounts.get_user_by_email(email)
|
||||
|
||||
conn = get(conn, Routes.user_settings_path(conn, :confirm_email, token))
|
||||
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
|
||||
|
||||
assert get_flash(conn, :error) =~
|
||||
dgettext("errors", "email change link is invalid or it has expired")
|
||||
assert get_flash(conn, :error) =~ "email change link is invalid or it has expired"
|
||||
end
|
||||
|
||||
test "does not update email with invalid token", %{conn: conn, current_user: current_user} do
|
||||
conn = get(conn, Routes.user_settings_path(conn, :confirm_email, "oops"))
|
||||
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
|
||||
|
||||
assert get_flash(conn, :error) =~
|
||||
dgettext("errors", "email change link is invalid or it has expired")
|
||||
|
||||
assert get_flash(conn, :error) =~ "email change link is invalid or it has expired"
|
||||
assert Accounts.get_user_by_email(current_user.email)
|
||||
end
|
||||
|
||||
|
@ -1,26 +1,26 @@
|
||||
defmodule MemexWeb.ContextLiveTest do
|
||||
use MemexWeb.ConnCase
|
||||
import Phoenix.LiveViewTest
|
||||
import Memex.{ContextsFixtures, NotesFixtures}
|
||||
import Memex.Fixtures
|
||||
alias MemexWeb.Endpoint
|
||||
|
||||
@create_attrs %{
|
||||
"content" => "some content",
|
||||
"tags_string" => "tag1",
|
||||
"slug" => "some-slug",
|
||||
"visibility" => :public
|
||||
content: "some content",
|
||||
tags_string: "tag1",
|
||||
slug: "some-slug",
|
||||
visibility: :public
|
||||
}
|
||||
@update_attrs %{
|
||||
"content" => "some updated content",
|
||||
"tags_string" => "tag1,tag2",
|
||||
"slug" => "some-updated-slug",
|
||||
"visibility" => :private
|
||||
content: "some updated content",
|
||||
tags_string: "tag1,tag2",
|
||||
slug: "some-updated-slug",
|
||||
visibility: :private
|
||||
}
|
||||
@invalid_attrs %{
|
||||
"content" => nil,
|
||||
"tags_string" => " ",
|
||||
"slug" => nil,
|
||||
"visibility" => nil
|
||||
content: nil,
|
||||
tags_string: " ",
|
||||
slug: nil,
|
||||
visibility: nil
|
||||
}
|
||||
|
||||
defp create_context(%{current_user: current_user}) do
|
||||
@ -37,34 +37,31 @@ defmodule MemexWeb.ContextLiveTest do
|
||||
assert html =~ context.slug
|
||||
end
|
||||
|
||||
test "searches by tag", %{conn: conn} do
|
||||
test "searches by tag", %{conn: conn, context: %{tags: [tag]}} do
|
||||
{:ok, index_live, html} = live(conn, Routes.context_index_path(conn, :index))
|
||||
|
||||
assert html =~ "example-tag"
|
||||
assert index_live |> element("a", "example-tag") |> render_click()
|
||||
assert_patch(index_live, Routes.context_index_path(conn, :search, "example-tag"))
|
||||
assert html =~ tag
|
||||
assert index_live |> element("a", tag) |> render_click()
|
||||
assert_patch(index_live, Routes.context_index_path(conn, :search, tag))
|
||||
end
|
||||
|
||||
test "saves new context", %{conn: conn} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.context_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("a", "new context") |> render_click() =~
|
||||
"new context"
|
||||
|
||||
assert index_live |> element("a", "new context") |> render_click() =~ "new context"
|
||||
assert_patch(index_live, Routes.context_index_path(conn, :new))
|
||||
|
||||
assert index_live
|
||||
|> form("#context-form", context: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|> form("#context-form")
|
||||
|> render_change(context: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _live, html} =
|
||||
index_live
|
||||
|> form("#context-form", context: @create_attrs)
|
||||
|> render_submit()
|
||||
|> form("#context-form")
|
||||
|> render_submit(context: @create_attrs)
|
||||
|> follow_redirect(conn, Routes.context_index_path(conn, :index))
|
||||
|
||||
assert html =~ "#{@create_attrs |> Map.get("slug")} created"
|
||||
assert html =~ "some-slug"
|
||||
assert html =~ "#{@create_attrs.slug} created"
|
||||
assert html =~ @create_attrs.slug
|
||||
end
|
||||
|
||||
test "updates context in listing", %{conn: conn, context: context} do
|
||||
@ -76,16 +73,16 @@ defmodule MemexWeb.ContextLiveTest do
|
||||
assert_patch(index_live, Routes.context_index_path(conn, :edit, context.slug))
|
||||
|
||||
assert index_live
|
||||
|> form("#context-form", context: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|> form("#context-form")
|
||||
|> render_change(context: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _live, html} =
|
||||
index_live
|
||||
|> form("#context-form", context: @update_attrs)
|
||||
|> render_submit()
|
||||
|> form("#context-form")
|
||||
|> render_submit(context: @update_attrs)
|
||||
|> follow_redirect(conn, Routes.context_index_path(conn, :index))
|
||||
|
||||
assert html =~ "#{@update_attrs |> Map.get("slug")} saved"
|
||||
assert html =~ "#{@update_attrs.slug} saved"
|
||||
assert html =~ "some-updated-slug"
|
||||
end
|
||||
|
||||
@ -109,23 +106,21 @@ defmodule MemexWeb.ContextLiveTest do
|
||||
|
||||
test "updates context within modal", %{conn: conn, context: context} do
|
||||
{:ok, show_live, _html} = live(conn, Routes.context_show_path(conn, :show, context.slug))
|
||||
|
||||
assert show_live |> element("a", "edit") |> render_click() =~ "edit"
|
||||
|
||||
assert_patch(show_live, Routes.context_show_path(conn, :edit, context.slug))
|
||||
|
||||
html =
|
||||
show_live
|
||||
|> form("#context-form", context: @invalid_attrs)
|
||||
|> render_change()
|
||||
|> form("#context-form")
|
||||
|> render_change(context: @invalid_attrs)
|
||||
|
||||
assert html =~ "can't be blank"
|
||||
assert html =~ "tags must be comma-delimited"
|
||||
|
||||
{:ok, _live, html} =
|
||||
show_live
|
||||
|> form("#context-form", context: Map.put(@update_attrs, "slug", context.slug))
|
||||
|> render_submit()
|
||||
|> form("#context-form")
|
||||
|> render_submit(context: Map.put(@update_attrs, "slug", context.slug))
|
||||
|> follow_redirect(conn, Routes.context_show_path(conn, :show, context.slug))
|
||||
|
||||
assert html =~ "#{context.slug} saved"
|
||||
@ -161,12 +156,12 @@ defmodule MemexWeb.ContextLiveTest do
|
||||
]
|
||||
end
|
||||
|
||||
test "searches by tag", %{conn: conn, context: context} do
|
||||
test "searches by tag", %{conn: conn, context: %{tags: [tag]} = context} do
|
||||
{:ok, show_live, html} = live(conn, Routes.context_show_path(conn, :show, context.slug))
|
||||
|
||||
assert html =~ "example-tag"
|
||||
assert show_live |> element("a", "example-tag") |> render_click()
|
||||
assert_redirect(show_live, Routes.context_index_path(conn, :search, "example-tag"))
|
||||
assert html =~ tag
|
||||
assert show_live |> element("a", tag) |> render_click()
|
||||
assert_redirect(show_live, Routes.context_index_path(conn, :search, tag))
|
||||
end
|
||||
|
||||
test "displays context", %{conn: conn, context: context, note: %{slug: note_slug}} do
|
||||
|
@ -5,12 +5,11 @@ defmodule MemexWeb.InviteLiveTest do
|
||||
|
||||
use MemexWeb.ConnCase
|
||||
import Phoenix.LiveViewTest
|
||||
import MemexWeb.Gettext
|
||||
alias Memex.Accounts.Invites
|
||||
|
||||
@moduletag :invite_live_test
|
||||
@create_attrs %{"name" => "some name"}
|
||||
@update_attrs %{"name" => "some updated name"}
|
||||
@create_attrs %{name: "some name"}
|
||||
@update_attrs %{name: "some updated name"}
|
||||
# @invalid_attrs %{"name" => nil}
|
||||
|
||||
describe "Index" do
|
||||
@ -24,32 +23,26 @@ defmodule MemexWeb.InviteLiveTest do
|
||||
test "lists all invites", %{conn: conn, invite: invite} do
|
||||
{:ok, _index_live, html} = live(conn, Routes.invite_index_path(conn, :index))
|
||||
|
||||
assert html =~ gettext("invites")
|
||||
assert html =~ "invites"
|
||||
assert html =~ invite.name
|
||||
end
|
||||
|
||||
test "saves new invite", %{conn: conn} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.invite_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("a", dgettext("actions", "create invite")) |> render_click() =~
|
||||
gettext("new invite")
|
||||
|
||||
assert index_live |> element("a", "create invite") |> render_click() =~ "new invite"
|
||||
assert_patch(index_live, Routes.invite_index_path(conn, :new))
|
||||
|
||||
# assert index_live
|
||||
# |> form("#invite-form", invite: @invalid_attrs)
|
||||
# |> render_change() =~ dgettext("errors", "can't be blank")
|
||||
# |> form("#invite-form")
|
||||
# |> render_change(invite: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _live, html} =
|
||||
index_live
|
||||
|> form("#invite-form", invite: @create_attrs)
|
||||
|> render_submit()
|
||||
|> form("#invite-form")
|
||||
|> render_submit(invite: @create_attrs)
|
||||
|> follow_redirect(conn, Routes.invite_index_path(conn, :index))
|
||||
|
||||
assert html =~
|
||||
dgettext("prompts", "%{invite_name} created successfully", invite_name: "some name")
|
||||
|
||||
assert html =~ "some name"
|
||||
assert html =~ "some name created successfully"
|
||||
end
|
||||
|
||||
test "updates invite in listing", %{conn: conn, invite: invite} do
|
||||
@ -57,27 +50,21 @@ defmodule MemexWeb.InviteLiveTest do
|
||||
|
||||
assert index_live
|
||||
|> element(~s/a[aria-label="edit invite for #{invite.name}"]/)
|
||||
|> render_click() =~
|
||||
gettext("edit invite")
|
||||
|> render_click() =~ "edit invite"
|
||||
|
||||
assert_patch(index_live, Routes.invite_index_path(conn, :edit, invite))
|
||||
|
||||
# assert index_live
|
||||
# |> form("#invite-form", invite: @invalid_attrs)
|
||||
# |> render_change() =~ dgettext("errors", "can't be blank")
|
||||
# |> form("#invite-form")
|
||||
# |> render_change(invite: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _live, html} =
|
||||
index_live
|
||||
|> form("#invite-form", invite: @update_attrs)
|
||||
|> render_submit()
|
||||
|> form("#invite-form")
|
||||
|> render_submit(invite: @update_attrs)
|
||||
|> follow_redirect(conn, Routes.invite_index_path(conn, :index))
|
||||
|
||||
assert html =~
|
||||
dgettext("prompts", "%{invite_name} updated successfully",
|
||||
invite_name: "some updated name"
|
||||
)
|
||||
|
||||
assert html =~ "some updated name"
|
||||
assert html =~ "some updated name updated successfully"
|
||||
end
|
||||
|
||||
test "deletes invite in listing", %{conn: conn, invite: invite} do
|
||||
|
@ -2,26 +2,26 @@ defmodule MemexWeb.NoteLiveTest do
|
||||
use MemexWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
import Memex.NotesFixtures
|
||||
import Memex.Fixtures
|
||||
alias MemexWeb.Endpoint
|
||||
|
||||
@create_attrs %{
|
||||
"content" => "some content",
|
||||
"tags_string" => "tag1",
|
||||
"slug" => "some-slug",
|
||||
"visibility" => :public
|
||||
content: "some content",
|
||||
tags_string: "tag1",
|
||||
slug: "some-slug",
|
||||
visibility: :public
|
||||
}
|
||||
@update_attrs %{
|
||||
"content" => "some updated content",
|
||||
"tags_string" => "tag1,tag2",
|
||||
"slug" => "some-updated-slug",
|
||||
"visibility" => :private
|
||||
content: "some updated content",
|
||||
tags_string: "tag1,tag2",
|
||||
slug: "some-updated-slug",
|
||||
visibility: :private
|
||||
}
|
||||
@invalid_attrs %{
|
||||
"content" => nil,
|
||||
"tags_string" => " ",
|
||||
"slug" => nil,
|
||||
"visibility" => nil
|
||||
content: nil,
|
||||
tags_string: " ",
|
||||
slug: nil,
|
||||
visibility: nil
|
||||
}
|
||||
|
||||
defp create_note(%{current_user: current_user}) do
|
||||
@ -38,38 +38,35 @@ defmodule MemexWeb.NoteLiveTest do
|
||||
assert html =~ note.slug
|
||||
end
|
||||
|
||||
test "searches by tag", %{conn: conn} do
|
||||
test "searches by tag", %{conn: conn, note: %{tags: [tag]}} do
|
||||
{:ok, index_live, html} = live(conn, Routes.note_index_path(conn, :index))
|
||||
|
||||
assert html =~ "example-tag"
|
||||
assert index_live |> element("a", "example-tag") |> render_click()
|
||||
assert_patch(index_live, Routes.note_index_path(conn, :search, "example-tag"))
|
||||
assert html =~ tag
|
||||
assert index_live |> element("a", tag) |> render_click()
|
||||
assert_patch(index_live, Routes.note_index_path(conn, :search, tag))
|
||||
end
|
||||
|
||||
test "saves new note", %{conn: conn} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.note_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("a", "new note") |> render_click() =~
|
||||
"new note"
|
||||
|
||||
assert index_live |> element("a", "new note") |> render_click() =~ "new note"
|
||||
assert_patch(index_live, Routes.note_index_path(conn, :new))
|
||||
|
||||
html =
|
||||
index_live
|
||||
|> form("#note-form", note: @invalid_attrs)
|
||||
|> render_change()
|
||||
|> form("#note-form")
|
||||
|> render_change(note: @invalid_attrs)
|
||||
|
||||
assert html =~ "can't be blank"
|
||||
assert html =~ "tags must be comma-delimited"
|
||||
|
||||
{:ok, _live, html} =
|
||||
index_live
|
||||
|> form("#note-form", note: @create_attrs)
|
||||
|> render_submit()
|
||||
|> form("#note-form")
|
||||
|> render_submit(note: @create_attrs)
|
||||
|> follow_redirect(conn, Routes.note_index_path(conn, :index))
|
||||
|
||||
assert html =~ "#{@create_attrs |> Map.get("slug")} created"
|
||||
assert html =~ "some-slug"
|
||||
assert html =~ "#{@create_attrs.slug} created"
|
||||
assert html =~ @create_attrs.slug
|
||||
end
|
||||
|
||||
test "updates note in listing", %{conn: conn, note: note} do
|
||||
@ -81,17 +78,17 @@ defmodule MemexWeb.NoteLiveTest do
|
||||
assert_patch(index_live, Routes.note_index_path(conn, :edit, note.slug))
|
||||
|
||||
assert index_live
|
||||
|> form("#note-form", note: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|> form("#note-form")
|
||||
|> render_change(note: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _live, html} =
|
||||
index_live
|
||||
|> form("#note-form", note: @update_attrs)
|
||||
|> render_submit()
|
||||
|> form("#note-form")
|
||||
|> render_submit(note: @update_attrs)
|
||||
|> follow_redirect(conn, Routes.note_index_path(conn, :index))
|
||||
|
||||
assert html =~ "#{@update_attrs |> Map.get("slug")} saved"
|
||||
assert html =~ "some-updated-slug"
|
||||
assert html =~ "#{@update_attrs.slug} saved"
|
||||
assert html =~ @update_attrs.slug
|
||||
end
|
||||
|
||||
test "deletes note in listing", %{conn: conn, note: note} do
|
||||
@ -114,23 +111,21 @@ defmodule MemexWeb.NoteLiveTest do
|
||||
|
||||
test "updates note within modal", %{conn: conn, note: note} do
|
||||
{:ok, show_live, _html} = live(conn, Routes.note_show_path(conn, :show, note.slug))
|
||||
|
||||
assert show_live |> element("a", "edit") |> render_click() =~ "edit"
|
||||
|
||||
assert_patch(show_live, Routes.note_show_path(conn, :edit, note.slug))
|
||||
|
||||
assert show_live
|
||||
|> form("#note-form", note: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|> form("#note-form")
|
||||
|> render_change(note: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _live, html} =
|
||||
show_live
|
||||
|> form("#note-form", note: Map.put(@update_attrs, "slug", note.slug))
|
||||
|> render_submit()
|
||||
|> form("#note-form")
|
||||
|> render_submit(note: @update_attrs |> Map.put(:slug, note.slug))
|
||||
|> follow_redirect(conn, Routes.note_show_path(conn, :show, note.slug))
|
||||
|
||||
assert html =~ "#{note.slug} saved"
|
||||
assert html =~ "tag2"
|
||||
assert html =~ note.slug
|
||||
end
|
||||
|
||||
test "deletes note", %{conn: conn, note: note} do
|
||||
@ -159,12 +154,12 @@ defmodule MemexWeb.NoteLiveTest do
|
||||
]
|
||||
end
|
||||
|
||||
test "searches by tag", %{conn: conn, note: note} do
|
||||
test "searches by tag", %{conn: conn, note: %{tags: [tag]} = note} do
|
||||
{:ok, show_live, html} = live(conn, Routes.note_show_path(conn, :show, note.slug))
|
||||
|
||||
assert html =~ "example-tag"
|
||||
assert show_live |> element("a", "example-tag") |> render_click()
|
||||
assert_redirect(show_live, Routes.note_index_path(conn, :search, "example-tag"))
|
||||
assert html =~ tag
|
||||
assert show_live |> element("a", tag) |> render_click()
|
||||
assert_redirect(show_live, Routes.note_index_path(conn, :search, tag))
|
||||
end
|
||||
|
||||
test "displays context", %{
|
||||
|
@ -1,37 +1,37 @@
|
||||
defmodule MemexWeb.PipelineLiveTest do
|
||||
use MemexWeb.ConnCase
|
||||
import Phoenix.LiveViewTest
|
||||
import Memex.{PipelinesFixtures, StepsFixtures}
|
||||
import Memex.Fixtures
|
||||
|
||||
@create_attrs %{
|
||||
"description" => "some description",
|
||||
"tags_string" => "tag1",
|
||||
"slug" => "some-slug",
|
||||
"visibility" => :public
|
||||
description: "some description",
|
||||
tags_string: "tag1",
|
||||
slug: "some-slug",
|
||||
visibility: :public
|
||||
}
|
||||
@update_attrs %{
|
||||
"description" => "some updated description",
|
||||
"tags_string" => "tag1,tag2",
|
||||
"slug" => "some-updated-slug",
|
||||
"visibility" => :private
|
||||
description: "some updated description",
|
||||
tags_string: "tag1,tag2",
|
||||
slug: "some-updated-slug",
|
||||
visibility: :private
|
||||
}
|
||||
@invalid_attrs %{
|
||||
"description" => nil,
|
||||
"tags_string" => " ",
|
||||
"slug" => nil,
|
||||
"visibility" => nil
|
||||
description: nil,
|
||||
tags_string: " ",
|
||||
slug: nil,
|
||||
visibility: nil
|
||||
}
|
||||
@step_create_attrs %{
|
||||
"content" => "some content",
|
||||
"title" => "some title"
|
||||
content: "some content",
|
||||
title: "some title"
|
||||
}
|
||||
@step_update_attrs %{
|
||||
"content" => "some updated content",
|
||||
"title" => "some updated title"
|
||||
content: "some updated content",
|
||||
title: "some updated title"
|
||||
}
|
||||
@step_invalid_attrs %{
|
||||
"content" => nil,
|
||||
"title" => nil
|
||||
content: nil,
|
||||
title: nil
|
||||
}
|
||||
|
||||
defp create_pipeline(%{current_user: current_user}) do
|
||||
@ -48,34 +48,32 @@ defmodule MemexWeb.PipelineLiveTest do
|
||||
assert html =~ pipeline.description
|
||||
end
|
||||
|
||||
test "searches by tag", %{conn: conn} do
|
||||
test "searches by tag", %{conn: conn, pipeline: %{tags: [tag]}} do
|
||||
{:ok, index_live, html} = live(conn, Routes.pipeline_index_path(conn, :index))
|
||||
|
||||
assert html =~ "example-tag"
|
||||
assert index_live |> element("a", "example-tag") |> render_click()
|
||||
assert_patch(index_live, Routes.pipeline_index_path(conn, :search, "example-tag"))
|
||||
assert html =~ tag
|
||||
assert index_live |> element("a", tag) |> render_click()
|
||||
assert_patch(index_live, Routes.pipeline_index_path(conn, :search, tag))
|
||||
end
|
||||
|
||||
test "saves new pipeline", %{conn: conn} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.pipeline_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("a", "new pipeline") |> render_click() =~
|
||||
"new pipeline"
|
||||
|
||||
assert index_live |> element("a", "new pipeline") |> render_click() =~ "new pipeline"
|
||||
assert_patch(index_live, Routes.pipeline_index_path(conn, :new))
|
||||
|
||||
assert index_live
|
||||
|> form("#pipeline-form", pipeline: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|> form("#pipeline-form")
|
||||
|> render_change(pipeline: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _live, html} =
|
||||
index_live
|
||||
|> form("#pipeline-form", pipeline: @create_attrs)
|
||||
|> render_submit()
|
||||
|> form("#pipeline-form")
|
||||
|> render_submit(pipeline: @create_attrs)
|
||||
|> follow_redirect(conn, Routes.pipeline_index_path(conn, :index))
|
||||
|
||||
assert html =~ "#{@create_attrs |> Map.get("slug")} created"
|
||||
assert html =~ "some description"
|
||||
assert html =~ "#{@create_attrs.slug} created"
|
||||
assert html =~ @create_attrs.description
|
||||
end
|
||||
|
||||
test "updates pipeline in listing", %{conn: conn, pipeline: pipeline} do
|
||||
@ -87,17 +85,17 @@ defmodule MemexWeb.PipelineLiveTest do
|
||||
assert_patch(index_live, Routes.pipeline_index_path(conn, :edit, pipeline.slug))
|
||||
|
||||
assert index_live
|
||||
|> form("#pipeline-form", pipeline: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|> form("#pipeline-form")
|
||||
|> render_change(pipeline: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _live, html} =
|
||||
index_live
|
||||
|> form("#pipeline-form", pipeline: @update_attrs)
|
||||
|> render_submit()
|
||||
|> form("#pipeline-form")
|
||||
|> render_submit(pipeline: @update_attrs)
|
||||
|> follow_redirect(conn, Routes.pipeline_index_path(conn, :index))
|
||||
|
||||
assert html =~ "#{@update_attrs |> Map.get("slug")} saved"
|
||||
assert html =~ "some updated description"
|
||||
assert html =~ "#{@update_attrs.slug} saved"
|
||||
assert html =~ @update_attrs.description
|
||||
end
|
||||
|
||||
test "deletes pipeline in listing", %{conn: conn, pipeline: pipeline} do
|
||||
@ -123,27 +121,25 @@ defmodule MemexWeb.PipelineLiveTest do
|
||||
|
||||
test "updates pipeline within modal", %{conn: conn, pipeline: pipeline} do
|
||||
{:ok, show_live, _html} = live(conn, Routes.pipeline_show_path(conn, :show, pipeline.slug))
|
||||
|
||||
assert show_live |> element("a", "edit") |> render_click() =~ "edit"
|
||||
|
||||
assert_patch(show_live, Routes.pipeline_show_path(conn, :edit, pipeline.slug))
|
||||
|
||||
html =
|
||||
show_live
|
||||
|> form("#pipeline-form", pipeline: @invalid_attrs)
|
||||
|> render_change()
|
||||
|> form("#pipeline-form")
|
||||
|> render_change(pipeline: @invalid_attrs)
|
||||
|
||||
assert html =~ "can't be blank"
|
||||
assert html =~ "tags must be comma-delimited"
|
||||
|
||||
{:ok, _live, html} =
|
||||
show_live
|
||||
|> form("#pipeline-form", pipeline: Map.put(@update_attrs, "slug", pipeline.slug))
|
||||
|> render_submit()
|
||||
|> form("#pipeline-form")
|
||||
|> render_submit(pipeline: @update_attrs |> Map.put(:slug, pipeline.slug))
|
||||
|> follow_redirect(conn, Routes.pipeline_show_path(conn, :show, pipeline.slug))
|
||||
|
||||
assert html =~ "#{pipeline.slug} saved"
|
||||
assert html =~ "some updated description"
|
||||
assert html =~ @update_attrs.description
|
||||
end
|
||||
|
||||
test "deletes pipeline", %{conn: conn, pipeline: pipeline} do
|
||||
@ -160,19 +156,17 @@ defmodule MemexWeb.PipelineLiveTest do
|
||||
|
||||
test "creates a step", %{conn: conn, pipeline: pipeline} do
|
||||
{:ok, show_live, _html} = live(conn, Routes.pipeline_show_path(conn, :show, pipeline.slug))
|
||||
|
||||
show_live |> element("a", "add step") |> render_click()
|
||||
|
||||
assert_patch(show_live, Routes.pipeline_show_path(conn, :add_step, pipeline.slug))
|
||||
|
||||
{:ok, _show_live, html} =
|
||||
show_live
|
||||
|> form("#step-form", step: @step_create_attrs)
|
||||
|> render_submit()
|
||||
|> form("#step-form")
|
||||
|> render_submit(step: @step_create_attrs)
|
||||
|> follow_redirect(conn, Routes.pipeline_show_path(conn, :show, pipeline.slug))
|
||||
|
||||
assert html =~ "some title created"
|
||||
assert html =~ "some description"
|
||||
assert html =~ @step_create_attrs.title
|
||||
assert html =~ @step_create_attrs.content
|
||||
end
|
||||
end
|
||||
|
||||
@ -185,12 +179,12 @@ defmodule MemexWeb.PipelineLiveTest do
|
||||
]
|
||||
end
|
||||
|
||||
test "searches by tag", %{conn: conn, pipeline: pipeline} do
|
||||
test "searches by tag", %{conn: conn, pipeline: %{tags: [tag]} = pipeline} do
|
||||
{:ok, show_live, html} = live(conn, Routes.pipeline_show_path(conn, :show, pipeline.slug))
|
||||
|
||||
assert html =~ "example-tag"
|
||||
assert show_live |> element("a", "example-tag") |> render_click()
|
||||
assert_redirect(show_live, Routes.pipeline_index_path(conn, :search, "example-tag"))
|
||||
assert html =~ tag
|
||||
assert show_live |> element("a", tag) |> render_click()
|
||||
assert_redirect(show_live, Routes.pipeline_index_path(conn, :search, tag))
|
||||
end
|
||||
|
||||
test "updates a step", %{conn: conn, pipeline: pipeline, step: step} do
|
||||
@ -203,17 +197,17 @@ defmodule MemexWeb.PipelineLiveTest do
|
||||
assert_patch(show_live, Routes.pipeline_show_path(conn, :edit_step, pipeline.slug, step.id))
|
||||
|
||||
assert show_live
|
||||
|> form("#step-form", step: @step_invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|> form("#step-form")
|
||||
|> render_change(step: @step_invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _show_live, html} =
|
||||
show_live
|
||||
|> form("#step-form", step: @step_update_attrs)
|
||||
|> render_submit()
|
||||
|> form("#step-form")
|
||||
|> render_submit(step: @step_update_attrs)
|
||||
|> follow_redirect(conn, Routes.pipeline_show_path(conn, :show, pipeline.slug))
|
||||
|
||||
assert html =~ "some updated title saved"
|
||||
assert html =~ "some updated content"
|
||||
assert html =~ @step_update_attrs.title
|
||||
assert html =~ @step_update_attrs.content
|
||||
end
|
||||
|
||||
test "deletes a step", %{conn: conn, pipeline: pipeline, step: step} do
|
||||
@ -226,8 +220,8 @@ defmodule MemexWeb.PipelineLiveTest do
|
||||
|
||||
assert_patch(show_live, Routes.pipeline_show_path(conn, :show, pipeline.slug))
|
||||
|
||||
assert html =~ "some title deleted"
|
||||
refute html =~ "some updated content"
|
||||
assert html =~ "#{step.title} deleted"
|
||||
refute html =~ step.content
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -4,19 +4,16 @@ defmodule MemexWeb.ErrorViewTest do
|
||||
"""
|
||||
|
||||
use MemexWeb.ConnCase, async: true
|
||||
import MemexWeb.Gettext
|
||||
# Bring render/3 and render_to_string/3 for testing custom views
|
||||
import Phoenix.View
|
||||
|
||||
@moduletag :error_view_test
|
||||
|
||||
test "renders 404.html" do
|
||||
assert render_to_string(MemexWeb.ErrorView, "404.html", []) =~
|
||||
dgettext("errors", "not found")
|
||||
assert render_to_string(MemexWeb.ErrorView, "404.html", []) =~ "not found"
|
||||
end
|
||||
|
||||
test "renders 500.html" do
|
||||
assert render_to_string(MemexWeb.ErrorView, "500.html", []) =~
|
||||
dgettext("errors", "internal server error")
|
||||
assert render_to_string(MemexWeb.ErrorView, "500.html", []) =~ "internal server error"
|
||||
end
|
||||
end
|
||||
|
@ -23,7 +23,7 @@ defmodule MemexWeb.ConnCase do
|
||||
using do
|
||||
quote do
|
||||
# credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse
|
||||
import Memex.Fixtures
|
||||
import Memex.{DataCase, Fixtures}
|
||||
import MemexWeb.ConnCase
|
||||
# Import conveniences for testing with connections
|
||||
import Plug.Conn
|
||||
|
@ -48,4 +48,24 @@ defmodule Memex.DataCase do
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Generates a random string of any length, default of 12
|
||||
"""
|
||||
@spec random_string(length :: non_neg_integer()) :: String.t()
|
||||
def random_string(length \\ 12) do
|
||||
:crypto.strong_rand_bytes(length) |> Base.url_encode64() |> binary_part(0, length)
|
||||
end
|
||||
|
||||
def unique_user_email, do: "user#{System.unique_integer()}@example.com"
|
||||
def valid_user_password, do: "hello world!"
|
||||
|
||||
def random_slug(length \\ 20) do
|
||||
symbols = '0123456789abcdef-'
|
||||
symbol_count = Enum.count(symbols)
|
||||
|
||||
for _ <- Range.new(1, length),
|
||||
into: "",
|
||||
do: <<Enum.at(symbols, :rand.uniform(symbol_count - 1))>>
|
||||
end
|
||||
end
|
||||
|
@ -3,18 +3,19 @@ defmodule Memex.Fixtures do
|
||||
This module defines test helpers for creating entities
|
||||
"""
|
||||
|
||||
import Memex.DataCase
|
||||
alias Memex.{Accounts, Accounts.User, Email, Repo}
|
||||
|
||||
def unique_user_email, do: "user#{System.unique_integer()}@example.com"
|
||||
def valid_user_password, do: "hello world!"
|
||||
alias Memex.{Contexts, Contexts.Context}
|
||||
alias Memex.{Notes, Notes.Note}
|
||||
alias Memex.{Pipelines, Pipelines.Pipeline, Pipelines.Steps}
|
||||
|
||||
@spec user_fixture() :: User.t()
|
||||
@spec user_fixture(attrs :: map()) :: User.t()
|
||||
def user_fixture(attrs \\ %{}) do
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
"email" => unique_user_email(),
|
||||
"password" => valid_user_password()
|
||||
email: unique_user_email(),
|
||||
password: valid_user_password()
|
||||
})
|
||||
|> Accounts.register_user()
|
||||
|> unwrap_ok_tuple()
|
||||
@ -25,8 +26,8 @@ defmodule Memex.Fixtures do
|
||||
def admin_fixture(attrs \\ %{}) do
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
"email" => unique_user_email(),
|
||||
"password" => valid_user_password()
|
||||
email: unique_user_email(),
|
||||
password: valid_user_password()
|
||||
})
|
||||
|> Accounts.register_user()
|
||||
|> unwrap_ok_tuple()
|
||||
@ -57,13 +58,76 @@ defmodule Memex.Fixtures do
|
||||
})
|
||||
end
|
||||
|
||||
def random_slug(length \\ 20) do
|
||||
symbols = '0123456789abcdef-'
|
||||
symbol_count = Enum.count(symbols)
|
||||
@doc """
|
||||
Generate a step.
|
||||
"""
|
||||
def step_fixture(attrs \\ %{}, position, pipeline, user) do
|
||||
{:ok, step} =
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
content: random_string(),
|
||||
title: random_string()
|
||||
})
|
||||
|> Steps.create_step(position, pipeline, user)
|
||||
|
||||
for _ <- Range.new(1, length),
|
||||
into: "",
|
||||
do: <<Enum.at(symbols, :rand.uniform(symbol_count - 1))>>
|
||||
step
|
||||
end
|
||||
|
||||
@doc """
|
||||
Generate a pipeline.
|
||||
"""
|
||||
@spec pipeline_fixture(User.t()) :: Pipeline.t()
|
||||
@spec pipeline_fixture(attrs :: map(), User.t()) :: Pipeline.t()
|
||||
def pipeline_fixture(attrs \\ %{}, user) do
|
||||
{:ok, pipeline} =
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
description: random_string(),
|
||||
tags: [random_slug()],
|
||||
slug: random_slug(),
|
||||
visibility: :private
|
||||
})
|
||||
|> Pipelines.create_pipeline(user)
|
||||
|
||||
%{pipeline | tags_string: nil}
|
||||
end
|
||||
|
||||
@doc """
|
||||
Generate a note.
|
||||
"""
|
||||
@spec note_fixture(User.t()) :: Note.t()
|
||||
@spec note_fixture(attrs :: map(), User.t()) :: Note.t()
|
||||
def note_fixture(attrs \\ %{}, user) do
|
||||
{:ok, note} =
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
content: random_string(),
|
||||
tags: [random_slug()],
|
||||
slug: random_slug(),
|
||||
visibility: :private
|
||||
})
|
||||
|> Notes.create_note(user)
|
||||
|
||||
%{note | tags_string: nil}
|
||||
end
|
||||
|
||||
@doc """
|
||||
Generate a context.
|
||||
"""
|
||||
@spec context_fixture(User.t()) :: Context.t()
|
||||
@spec context_fixture(attrs :: map(), User.t()) :: Context.t()
|
||||
def context_fixture(attrs \\ %{}, user) do
|
||||
{:ok, context} =
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
content: random_string(),
|
||||
tags: [random_slug()],
|
||||
slug: random_slug(),
|
||||
visibility: :private
|
||||
})
|
||||
|> Contexts.create_context(user)
|
||||
|
||||
%{context | tags_string: nil}
|
||||
end
|
||||
|
||||
defp unwrap_ok_tuple({:ok, value}), do: value
|
||||
|
@ -1,27 +0,0 @@
|
||||
defmodule Memex.ContextsFixtures do
|
||||
@moduledoc """
|
||||
This module defines test helpers for creating
|
||||
entities via the `Memex.Contexts` context.
|
||||
"""
|
||||
import Memex.Fixtures
|
||||
alias Memex.{Accounts.User, Contexts, Contexts.Context}
|
||||
|
||||
@doc """
|
||||
Generate a context.
|
||||
"""
|
||||
@spec context_fixture(User.t()) :: Context.t()
|
||||
@spec context_fixture(attrs :: map(), User.t()) :: Context.t()
|
||||
def context_fixture(attrs \\ %{}, user) do
|
||||
{:ok, context} =
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
content: "some content",
|
||||
tags: ["example-tag"],
|
||||
slug: random_slug(),
|
||||
visibility: :private
|
||||
})
|
||||
|> Contexts.create_context(user)
|
||||
|
||||
%{context | tags_string: nil}
|
||||
end
|
||||
end
|
@ -1,27 +0,0 @@
|
||||
defmodule Memex.NotesFixtures do
|
||||
@moduledoc """
|
||||
This module defines test helpers for creating
|
||||
entities via the `Memex.Notes` context.
|
||||
"""
|
||||
import Memex.Fixtures
|
||||
alias Memex.{Accounts.User, Notes, Notes.Note}
|
||||
|
||||
@doc """
|
||||
Generate a note.
|
||||
"""
|
||||
@spec note_fixture(User.t()) :: Note.t()
|
||||
@spec note_fixture(attrs :: map(), User.t()) :: Note.t()
|
||||
def note_fixture(attrs \\ %{}, user) do
|
||||
{:ok, note} =
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
content: "some content",
|
||||
tags: ["example-tag"],
|
||||
slug: random_slug(),
|
||||
visibility: :private
|
||||
})
|
||||
|> Notes.create_note(user)
|
||||
|
||||
%{note | tags_string: nil}
|
||||
end
|
||||
end
|
@ -1,27 +0,0 @@
|
||||
defmodule Memex.PipelinesFixtures do
|
||||
@moduledoc """
|
||||
This module defines test helpers for creating
|
||||
entities via the `Memex.Pipelines` context.
|
||||
"""
|
||||
import Memex.Fixtures
|
||||
alias Memex.{Accounts.User, Pipelines, Pipelines.Pipeline}
|
||||
|
||||
@doc """
|
||||
Generate a pipeline.
|
||||
"""
|
||||
@spec pipeline_fixture(User.t()) :: Pipeline.t()
|
||||
@spec pipeline_fixture(attrs :: map(), User.t()) :: Pipeline.t()
|
||||
def pipeline_fixture(attrs \\ %{}, user) do
|
||||
{:ok, pipeline} =
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
description: "some description",
|
||||
tags: ["example-tag"],
|
||||
slug: random_slug(),
|
||||
visibility: :private
|
||||
})
|
||||
|> Pipelines.create_pipeline(user)
|
||||
|
||||
%{pipeline | tags_string: nil}
|
||||
end
|
||||
end
|
@ -1,22 +0,0 @@
|
||||
defmodule Memex.StepsFixtures do
|
||||
@moduledoc """
|
||||
This module defines test helpers for creating
|
||||
entities via the `Memex.Steps` context.
|
||||
"""
|
||||
alias Memex.Pipelines.Steps
|
||||
|
||||
@doc """
|
||||
Generate a step.
|
||||
"""
|
||||
def step_fixture(attrs \\ %{}, position, pipeline, user) do
|
||||
{:ok, step} =
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
content: "some content",
|
||||
title: "some title"
|
||||
})
|
||||
|> Steps.create_step(position, pipeline, user)
|
||||
|
||||
step
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user