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