mirror of
https://github.com/ClaperCo/Claper.git
synced 2025-12-16 11:57:58 +01:00
run mix format
This commit is contained in:
@@ -107,8 +107,7 @@ defmodule Claper.AccountsTest do
|
||||
end
|
||||
|
||||
test "validates email", %{user: user} do
|
||||
{:error, changeset} =
|
||||
Accounts.apply_user_email(user, %{email: "not valid"})
|
||||
{:error, changeset} = Accounts.apply_user_email(user, %{email: "not valid"})
|
||||
|
||||
assert %{email: ["must have the @ sign and no spaces"]} = errors_on(changeset)
|
||||
end
|
||||
@@ -116,8 +115,7 @@ defmodule Claper.AccountsTest do
|
||||
test "validates maximum value for email for security", %{user: user} do
|
||||
too_long = String.duplicate("db", 100)
|
||||
|
||||
{:error, changeset} =
|
||||
Accounts.apply_user_email(user, %{email: too_long})
|
||||
{:error, changeset} = Accounts.apply_user_email(user, %{email: too_long})
|
||||
|
||||
assert "should be at most 160 character(s)" in errors_on(changeset).email
|
||||
end
|
||||
@@ -125,8 +123,7 @@ defmodule Claper.AccountsTest do
|
||||
test "validates email uniqueness", %{user: user} do
|
||||
%{email: email} = user_fixture()
|
||||
|
||||
{:error, changeset} =
|
||||
Accounts.apply_user_email(user, %{email: email})
|
||||
{:error, changeset} = Accounts.apply_user_email(user, %{email: email})
|
||||
|
||||
assert "has already been taken" in errors_on(changeset).email
|
||||
end
|
||||
@@ -305,5 +302,4 @@ defmodule Claper.AccountsTest do
|
||||
assert Repo.get_by(UserToken, user_id: user.id)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -2,10 +2,9 @@ defmodule Claper.EventsTest do
|
||||
use Claper.DataCase
|
||||
|
||||
alias Claper.Events
|
||||
import Claper.{EventsFixtures,AccountsFixtures}
|
||||
import Claper.{EventsFixtures, AccountsFixtures}
|
||||
|
||||
describe "events" do
|
||||
|
||||
alias Claper.Events.Event
|
||||
|
||||
@invalid_attrs %{name: nil, code: nil}
|
||||
@@ -32,12 +31,22 @@ defmodule Claper.EventsTest do
|
||||
test "get_user_event!/3 with invalid user raises exception" do
|
||||
event = event_fixture()
|
||||
event2 = event_fixture()
|
||||
assert_raise Ecto.NoResultsError, fn -> Events.get_user_event!(event.user_id, event2.uuid) == event end
|
||||
|
||||
assert_raise Ecto.NoResultsError, fn ->
|
||||
Events.get_user_event!(event.user_id, event2.uuid) == event
|
||||
end
|
||||
end
|
||||
|
||||
test "create_event/1 with valid data creates a event" do
|
||||
user = user_fixture()
|
||||
valid_attrs = %{name: "some name", code: "code", user_id: user.id, started_at: NaiveDateTime.utc_now, expired_at: NaiveDateTime.add(NaiveDateTime.utc_now, 7200, :second)}
|
||||
|
||||
valid_attrs = %{
|
||||
name: "some name",
|
||||
code: "code",
|
||||
user_id: user.id,
|
||||
started_at: NaiveDateTime.utc_now(),
|
||||
expired_at: NaiveDateTime.add(NaiveDateTime.utc_now(), 7200, :second)
|
||||
}
|
||||
|
||||
assert {:ok, %Event{} = event} = Events.create_event(valid_attrs)
|
||||
assert event.name == "some name"
|
||||
|
||||
@@ -6,37 +6,46 @@ defmodule Claper.PollsTest do
|
||||
describe "polls" do
|
||||
alias Claper.Polls.Poll
|
||||
|
||||
import Claper.{PollsFixtures,PresentationsFixtures}
|
||||
import Claper.{PollsFixtures, PresentationsFixtures}
|
||||
|
||||
@invalid_attrs %{title: nil}
|
||||
|
||||
test "list_polls/1 returns all polls from a presentation" do
|
||||
presentation_file = presentation_file_fixture()
|
||||
poll = poll_fixture(%{presentation_file_id: presentation_file.id })
|
||||
poll = poll_fixture(%{presentation_file_id: presentation_file.id})
|
||||
|
||||
assert Polls.list_polls(presentation_file.id) == [poll]
|
||||
end
|
||||
|
||||
test "list_polls_at_position/2 returns all polls from a presentation at a given position" do
|
||||
presentation_file = presentation_file_fixture()
|
||||
poll = poll_fixture(%{presentation_file_id: presentation_file.id, position: 5 })
|
||||
poll = poll_fixture(%{presentation_file_id: presentation_file.id, position: 5})
|
||||
|
||||
assert Polls.list_polls_at_position(presentation_file.id, 5) == [poll]
|
||||
end
|
||||
|
||||
test "get_poll!/1 returns the poll with given id" do
|
||||
presentation_file = presentation_file_fixture()
|
||||
poll = poll_fixture(%{presentation_file_id: presentation_file.id }) |> Claper.Polls.set_percentages()
|
||||
|
||||
poll =
|
||||
poll_fixture(%{presentation_file_id: presentation_file.id})
|
||||
|> Claper.Polls.set_percentages()
|
||||
|
||||
assert Polls.get_poll!(poll.id) == poll
|
||||
end
|
||||
|
||||
test "create_poll/1 with valid data creates a poll" do
|
||||
presentation_file = presentation_file_fixture()
|
||||
valid_attrs = %{title: "some title", presentation_file_id: presentation_file.id, position: 0, poll_opts: [
|
||||
%{content: "some option 1", vote_count: 0},
|
||||
%{content: "some option 2", vote_count: 0},
|
||||
]}
|
||||
|
||||
valid_attrs = %{
|
||||
title: "some title",
|
||||
presentation_file_id: presentation_file.id,
|
||||
position: 0,
|
||||
poll_opts: [
|
||||
%{content: "some option 1", vote_count: 0},
|
||||
%{content: "some option 2", vote_count: 0}
|
||||
]
|
||||
}
|
||||
|
||||
assert {:ok, %Poll{} = poll} = Polls.create_poll(valid_attrs)
|
||||
assert poll.title == "some title"
|
||||
@@ -51,14 +60,19 @@ defmodule Claper.PollsTest do
|
||||
poll = poll_fixture(%{presentation_file_id: presentation_file.id})
|
||||
update_attrs = %{title: "some updated title"}
|
||||
|
||||
assert {:ok, %Poll{} = poll} = Polls.update_poll(presentation_file.event_id, poll, update_attrs)
|
||||
assert {:ok, %Poll{} = poll} =
|
||||
Polls.update_poll(presentation_file.event_id, poll, update_attrs)
|
||||
|
||||
assert poll.title == "some updated title"
|
||||
end
|
||||
|
||||
test "update_poll/3 with invalid data returns error changeset" do
|
||||
presentation_file = presentation_file_fixture()
|
||||
poll = poll_fixture(%{presentation_file_id: presentation_file.id})
|
||||
assert {:error, %Ecto.Changeset{}} = Polls.update_poll(presentation_file.event_id, poll, @invalid_attrs)
|
||||
|
||||
assert {:error, %Ecto.Changeset{}} =
|
||||
Polls.update_poll(presentation_file.event_id, poll, @invalid_attrs)
|
||||
|
||||
assert poll |> Claper.Polls.set_percentages() == Polls.get_poll!(poll.id)
|
||||
end
|
||||
|
||||
@@ -78,15 +92,15 @@ defmodule Claper.PollsTest do
|
||||
end
|
||||
|
||||
describe "poll_opts" do
|
||||
|
||||
import Claper.{PollsFixtures,PresentationsFixtures}
|
||||
import Claper.{PollsFixtures, PresentationsFixtures}
|
||||
|
||||
test "add_poll_opt/1 returns poll changeset plus the added poll_opt" do
|
||||
presentation_file = presentation_file_fixture()
|
||||
poll = poll_fixture(%{presentation_file_id: presentation_file.id})
|
||||
poll_changeset = poll |> Polls.change_poll()
|
||||
|
||||
assert Ecto.Changeset.get_field(Polls.add_poll_opt(poll_changeset), :poll_opts) |> Enum.count == 3
|
||||
assert Ecto.Changeset.get_field(Polls.add_poll_opt(poll_changeset), :poll_opts)
|
||||
|> Enum.count() == 3
|
||||
end
|
||||
|
||||
test "remove_poll_opt/2 returns poll changeset minus the removed poll_opt" do
|
||||
@@ -94,13 +108,16 @@ defmodule Claper.PollsTest do
|
||||
poll = poll_fixture(%{presentation_file_id: presentation_file.id})
|
||||
poll_changeset = poll |> Polls.change_poll()
|
||||
|
||||
assert Ecto.Changeset.get_field(Polls.remove_poll_opt(poll_changeset, Enum.at(poll.poll_opts, 0)), :poll_opts) |> Enum.count == 1
|
||||
assert Ecto.Changeset.get_field(
|
||||
Polls.remove_poll_opt(poll_changeset, Enum.at(poll.poll_opts, 0)),
|
||||
:poll_opts
|
||||
)
|
||||
|> Enum.count() == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "poll_votes" do
|
||||
|
||||
import Claper.{PollsFixtures,PresentationsFixtures}
|
||||
import Claper.{PollsFixtures, PresentationsFixtures}
|
||||
|
||||
test "get_poll_vote/2 returns the poll_vote with given id and user id" do
|
||||
poll_vote = poll_vote_fixture()
|
||||
@@ -112,8 +129,13 @@ defmodule Claper.PollsTest do
|
||||
poll = poll_fixture(%{presentation_file_id: presentation_file.id})
|
||||
[poll_opt | _] = poll.poll_opts
|
||||
|
||||
|
||||
assert {:ok, %Polls.Poll{}} = Polls.vote(presentation_file.event.user_id, presentation_file.event_id, poll_opt, poll.id)
|
||||
assert {:ok, %Polls.Poll{}} =
|
||||
Polls.vote(
|
||||
presentation_file.event.user_id,
|
||||
presentation_file.event_id,
|
||||
poll_opt,
|
||||
poll.id
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -8,7 +8,6 @@ defmodule Claper.PostsTest do
|
||||
alias Claper.Posts.Post
|
||||
|
||||
describe "posts" do
|
||||
|
||||
@invalid_attrs %{body: "a"}
|
||||
|
||||
test "list_posts/0 returns all posts from an event" do
|
||||
@@ -55,7 +54,6 @@ defmodule Claper.PostsTest do
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe "reactions" do
|
||||
alias Claper.Posts.Reaction
|
||||
|
||||
@@ -86,7 +84,9 @@ defmodule Claper.PostsTest do
|
||||
post = post_fixture()
|
||||
reaction = reaction_fixture(%{post: post, user_id: post.user_id})
|
||||
|
||||
assert {:ok, %Post{}} = Posts.delete_reaction(%{user_id: post.user_id, post: post, icon: "some icon"})
|
||||
assert {:ok, %Post{}} =
|
||||
Posts.delete_reaction(%{user_id: post.user_id, post: post, icon: "some icon"})
|
||||
|
||||
assert_raise Ecto.NoResultsError, fn -> Posts.get_reaction!(reaction.id) end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,13 +15,17 @@ defmodule Claper.PresentationsTest do
|
||||
|
||||
test "get_presentation_file_by_hash!/2 returns the presentation_file with given hash" do
|
||||
presentation_file = presentation_file_fixture(%{}, [:event])
|
||||
assert Presentations.get_presentation_file_by_hash!(presentation_file.hash) == presentation_file
|
||||
|
||||
assert Presentations.get_presentation_file_by_hash!(presentation_file.hash) ==
|
||||
presentation_file
|
||||
end
|
||||
|
||||
test "create_presentation_file/1 with valid data creates a presentation_file" do
|
||||
valid_attrs = %{hash: "1234", length: 42}
|
||||
|
||||
assert {:ok, %PresentationFile{} = presentation_file} = Presentations.create_presentation_file(valid_attrs)
|
||||
assert {:ok, %PresentationFile{} = presentation_file} =
|
||||
Presentations.create_presentation_file(valid_attrs)
|
||||
|
||||
assert presentation_file.hash == "1234"
|
||||
assert presentation_file.length == 42
|
||||
end
|
||||
@@ -30,7 +34,9 @@ defmodule Claper.PresentationsTest do
|
||||
presentation_file = presentation_file_fixture()
|
||||
update_attrs = %{hash: "4567", length: 43}
|
||||
|
||||
assert {:ok, %PresentationFile{} = presentation_file} = Presentations.update_presentation_file(presentation_file, update_attrs)
|
||||
assert {:ok, %PresentationFile{} = presentation_file} =
|
||||
Presentations.update_presentation_file(presentation_file, update_attrs)
|
||||
|
||||
assert presentation_file.hash == "4567"
|
||||
assert presentation_file.length == 43
|
||||
end
|
||||
@@ -51,7 +57,8 @@ defmodule Claper.PresentationsTest do
|
||||
presentation_state = presentation_state_fixture()
|
||||
update_attrs = %{}
|
||||
|
||||
assert {:ok, %PresentationState{}} = Presentations.update_presentation_state(presentation_state, update_attrs)
|
||||
assert {:ok, %PresentationState{}} =
|
||||
Presentations.update_presentation_state(presentation_state, update_attrs)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,7 +25,9 @@ defmodule ClaperWeb.EventLiveTest do
|
||||
test "updates event in listing", %{conn: conn, presentation_file: presentation_file} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.event_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("#event-#{presentation_file.event.uuid} a", "Edit") |> render_click() =~
|
||||
assert index_live
|
||||
|> element("#event-#{presentation_file.event.uuid} a", "Edit")
|
||||
|> render_click() =~
|
||||
"Edit"
|
||||
|
||||
assert_patch(index_live, Routes.event_index_path(conn, :edit, presentation_file.event.uuid))
|
||||
@@ -43,15 +45,19 @@ defmodule ClaperWeb.EventLiveTest do
|
||||
test "deletes event in listing", %{conn: conn, presentation_file: presentation_file} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.event_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("#event-#{presentation_file.event.uuid} a", "Edit") |> render_click() =~
|
||||
assert index_live
|
||||
|> element("#event-#{presentation_file.event.uuid} a", "Edit")
|
||||
|> render_click() =~
|
||||
"Edit"
|
||||
|
||||
{:ok, conn} = index_live |> element(~s{a[phx-value-id=#{presentation_file.event.uuid}]}) |> render_click()
|
||||
|> follow_redirect(conn, Routes.event_index_path(conn, :index))
|
||||
{:ok, conn} =
|
||||
index_live
|
||||
|> element(~s{a[phx-value-id=#{presentation_file.event.uuid}]})
|
||||
|> render_click()
|
||||
|> follow_redirect(conn, Routes.event_index_path(conn, :index))
|
||||
|
||||
{:ok, index_live, _html} = live(conn, Routes.event_index_path(conn, :index))
|
||||
|
||||
|
||||
refute has_element?(index_live, "#event-#{presentation_file.event.uuid}")
|
||||
end
|
||||
end
|
||||
@@ -60,12 +66,11 @@ defmodule ClaperWeb.EventLiveTest do
|
||||
setup [:register_and_log_in_user, :create_event]
|
||||
|
||||
test "displays event", %{conn: conn, presentation_file: presentation_file} do
|
||||
|
||||
{:ok, _show_live, html} = live(conn, Routes.event_show_path(conn, :show, presentation_file.event.code))
|
||||
{:ok, _show_live, html} =
|
||||
live(conn, Routes.event_show_path(conn, :show, presentation_file.event.code))
|
||||
|
||||
assert html =~ "Be the first to react"
|
||||
assert html =~ presentation_file.event.name
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,7 +2,7 @@ defmodule ClaperWeb.PostLiveTest do
|
||||
use ClaperWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
import Claper.{PresentationsFixtures,PostsFixtures}
|
||||
import Claper.{PresentationsFixtures, PostsFixtures}
|
||||
|
||||
defp create_event(params) do
|
||||
presentation_file = presentation_file_fixture(%{user: params.user}, [:event])
|
||||
@@ -15,10 +15,10 @@ defmodule ClaperWeb.PostLiveTest do
|
||||
setup [:register_and_log_in_user, :create_event]
|
||||
|
||||
test "list posts", %{conn: conn, presentation_file: presentation_file} do
|
||||
{:ok, _index_live, html} = live(conn, Routes.event_show_path(conn, :show, presentation_file.event.code))
|
||||
{:ok, _index_live, html} =
|
||||
live(conn, Routes.event_show_path(conn, :show, presentation_file.event.code))
|
||||
|
||||
assert html =~ "some body"
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -62,6 +62,5 @@ defmodule ClaperWeb.ConnCase do
|
||||
|> Phoenix.ConnTest.init_test_session(%{})
|
||||
|> Plug.Conn.put_session(:current_user, user)
|
||||
|> Plug.Conn.put_session(:user_token, token)
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,7 +11,7 @@ defmodule Claper.AccountsFixtures do
|
||||
Enum.into(attrs, %{
|
||||
email: unique_user_email(),
|
||||
password: valid_user_password(),
|
||||
confirmed_at: NaiveDateTime.utc_now(),
|
||||
confirmed_at: NaiveDateTime.utc_now()
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ defmodule Claper.EventsFixtures do
|
||||
"""
|
||||
def event_fixture(attrs \\ %{}, preload \\ []) do
|
||||
assoc = %{user: attrs[:user] || user_fixture()}
|
||||
|
||||
{:ok, event} =
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
@@ -20,12 +21,12 @@ defmodule Claper.EventsFixtures do
|
||||
code: "#{Enum.random(1000..2000)}",
|
||||
uuid: Ecto.UUID.generate(),
|
||||
user_id: assoc.user.id,
|
||||
started_at: NaiveDateTime.utc_now,
|
||||
expired_at: NaiveDateTime.add(NaiveDateTime.utc_now, 7200, :second) # add 2 hours
|
||||
started_at: NaiveDateTime.utc_now(),
|
||||
# add 2 hours
|
||||
expired_at: NaiveDateTime.add(NaiveDateTime.utc_now(), 7200, :second)
|
||||
})
|
||||
|> Claper.Events.create_event()
|
||||
|
||||
Claper.UtilFixture.merge_preload(event, preload, assoc)
|
||||
Claper.UtilFixture.merge_preload(event, preload, assoc)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -4,7 +4,7 @@ defmodule Claper.PollsFixtures do
|
||||
entities via the `Claper.Polls` context.
|
||||
"""
|
||||
|
||||
import Claper.{AccountsFixtures,PresentationsFixtures}
|
||||
import Claper.{AccountsFixtures, PresentationsFixtures}
|
||||
|
||||
require Claper.UtilFixture
|
||||
|
||||
@@ -20,13 +20,12 @@ defmodule Claper.PollsFixtures do
|
||||
enabled: true,
|
||||
poll_opts: [
|
||||
%{content: "some option 1", vote_count: 0},
|
||||
%{content: "some option 2", vote_count: 0},
|
||||
%{content: "some option 2", vote_count: 0}
|
||||
]
|
||||
})
|
||||
|> Claper.Polls.create_poll()
|
||||
|
||||
Claper.UtilFixture.merge_preload(poll, preload, %{})
|
||||
|
||||
Claper.UtilFixture.merge_preload(poll, preload, %{})
|
||||
end
|
||||
|
||||
@doc """
|
||||
@@ -37,6 +36,7 @@ defmodule Claper.PollsFixtures do
|
||||
poll = poll_fixture(%{presentation_file_id: presentation_file.id})
|
||||
[poll_opt | _] = poll.poll_opts
|
||||
assoc = %{poll: poll}
|
||||
|
||||
{:ok, poll_vote} =
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
|
||||
@@ -15,20 +15,23 @@ defmodule Claper.PostsFixtures do
|
||||
user = attrs[:user] || user_fixture()
|
||||
event = attrs[:event] || event_fixture()
|
||||
assoc = %{user: user, event: event}
|
||||
|
||||
{:ok, post} =
|
||||
Claper.Posts.create_post(assoc.event, attrs
|
||||
|> Enum.into(%{
|
||||
body: "some body",
|
||||
like_count: 42,
|
||||
position: 0,
|
||||
uuid: Ecto.UUID.generate(),
|
||||
user_id: assoc.user.id
|
||||
}))
|
||||
Claper.Posts.create_post(
|
||||
assoc.event,
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
body: "some body",
|
||||
like_count: 42,
|
||||
position: 0,
|
||||
uuid: Ecto.UUID.generate(),
|
||||
user_id: assoc.user.id
|
||||
})
|
||||
)
|
||||
|
||||
Claper.UtilFixture.merge_preload(post, preload, assoc)
|
||||
Claper.UtilFixture.merge_preload(post, preload, assoc)
|
||||
end
|
||||
|
||||
|
||||
@doc """
|
||||
Generate a reaction.
|
||||
"""
|
||||
|
||||
@@ -13,6 +13,7 @@ defmodule Claper.PresentationsFixtures do
|
||||
"""
|
||||
def presentation_file_fixture(attrs \\ %{}, preload \\ []) do
|
||||
assoc = %{event: attrs[:event] || event_fixture(attrs)}
|
||||
|
||||
{:ok, presentation_file} =
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
@@ -23,14 +24,15 @@ defmodule Claper.PresentationsFixtures do
|
||||
})
|
||||
|> Claper.Presentations.create_presentation_file()
|
||||
|
||||
Claper.UtilFixture.merge_preload(presentation_file, preload, assoc)
|
||||
Claper.UtilFixture.merge_preload(presentation_file, preload, assoc)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Generate a presentation_state.
|
||||
"""
|
||||
def presentation_state_fixture(attrs \\ %{}, preload \\ []) do
|
||||
def presentation_state_fixture(attrs \\ %{}, preload \\ []) do
|
||||
assoc = %{presentation_file: attrs[:presentation_file] || presentation_file_fixture()}
|
||||
|
||||
{:ok, presentation_state} =
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
@@ -43,6 +45,6 @@ defmodule Claper.PresentationsFixtures do
|
||||
})
|
||||
|> Claper.Presentations.create_presentation_state()
|
||||
|
||||
Claper.UtilFixture.merge_preload(presentation_state, preload, assoc)
|
||||
Claper.UtilFixture.merge_preload(presentation_state, preload, assoc)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
defmodule Claper.UtilFixture do
|
||||
defmacro merge_preload(origin, preload, assoc) do
|
||||
quote do
|
||||
unquote(origin) |>
|
||||
Map.merge(for p <- unquote(preload), unquote(assoc)[p], into: %{}, do: {p, unquote(assoc)[p]})
|
||||
unquote(origin)
|
||||
|> Map.merge(
|
||||
for p <- unquote(preload), unquote(assoc)[p], into: %{}, do: {p, unquote(assoc)[p]}
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user