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:
@@ -83,8 +83,10 @@ if config_env() == :prod do
|
||||
username: System.get_env("SMTP_USERNAME"),
|
||||
password: System.get_env("SMTP_PASSWORD"),
|
||||
ssl: System.get_env("SMTP_SSL", "true") == "true",
|
||||
tls: String.to_atom(System.get_env("SMTP_TLS", "always")), # always, never, if_available
|
||||
auth: String.to_atom(System.get_env("SMTP_AUTH", "always")), # always, never, if_available
|
||||
# always, never, if_available
|
||||
tls: String.to_atom(System.get_env("SMTP_TLS", "always")),
|
||||
# always, never, if_available
|
||||
auth: String.to_atom(System.get_env("SMTP_AUTH", "always")),
|
||||
port: String.to_integer(System.get_env("SMTP_PORT", "25"))
|
||||
end
|
||||
|
||||
|
||||
@@ -410,9 +410,11 @@ defmodule Claper.Accounts do
|
||||
Ecto.Multi.new()
|
||||
|> Ecto.Multi.run(:run, fn repo, _changes ->
|
||||
user = repo.get_by(User, email: token.sent_to)
|
||||
if (is_nil(user)) do
|
||||
|
||||
if is_nil(user) do
|
||||
UserNotifier.deliver_welcome(token.sent_to)
|
||||
end
|
||||
|
||||
{:ok, user || %User{email: token.sent_to}}
|
||||
end)
|
||||
|> Ecto.Multi.insert_or_update(:user, fn %{run: user} -> User.confirm_changeset(user) end)
|
||||
|
||||
@@ -111,5 +111,4 @@ defmodule Claper.Accounts.User do
|
||||
add_error(changeset, :current_password, "is not valid")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -19,6 +19,7 @@ defmodule Claper.Accounts.UserNotifier do
|
||||
|
||||
def deliver_magic_link(email, url) do
|
||||
email = ClaperWeb.Notifiers.UserNotifier.magic(email, url)
|
||||
|
||||
with {:ok, _metadata} <- Mailer.deliver(email) do
|
||||
{:ok, email}
|
||||
end
|
||||
@@ -26,6 +27,7 @@ defmodule Claper.Accounts.UserNotifier do
|
||||
|
||||
def deliver_welcome(email) do
|
||||
email = ClaperWeb.Notifiers.UserNotifier.welcome(email)
|
||||
|
||||
with {:ok, _metadata} <- Mailer.deliver(email) do
|
||||
{:ok, email}
|
||||
end
|
||||
@@ -76,6 +78,7 @@ defmodule Claper.Accounts.UserNotifier do
|
||||
"""
|
||||
def deliver_update_email_instructions(user, url) do
|
||||
email = ClaperWeb.Notifiers.UserNotifier.update_email(user, url)
|
||||
|
||||
with {:ok, _metadata} <- Mailer.deliver(email) do
|
||||
{:ok, email}
|
||||
end
|
||||
|
||||
@@ -95,7 +95,10 @@ defmodule Claper.Events do
|
||||
"""
|
||||
def get_managed_event!(current_user, id, preload \\ []) do
|
||||
event = Repo.get_by!(Event, uuid: id)
|
||||
is_leader = Claper.Events.is_leaded_by(current_user.email, event) || event.user_id == current_user.id
|
||||
|
||||
is_leader =
|
||||
Claper.Events.is_leaded_by(current_user.email, event) || event.user_id == current_user.id
|
||||
|
||||
if is_leader do
|
||||
event |> Repo.preload(preload)
|
||||
else
|
||||
|
||||
@@ -167,7 +167,6 @@ defmodule Claper.Polls do
|
||||
{:error, changeset} ->
|
||||
{:error, %{changeset | action: :update}}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@doc """
|
||||
@@ -306,7 +305,6 @@ defmodule Claper.Polls do
|
||||
{:ok, poll}
|
||||
end
|
||||
|
||||
|
||||
@doc """
|
||||
Gets a single poll_vote.
|
||||
|
||||
|
||||
@@ -176,6 +176,7 @@ defmodule Claper.Posts do
|
||||
|
||||
"""
|
||||
def create_reaction(%{post: nil} = attrs), do: create_reaction(%{attrs | post: %Post{}})
|
||||
|
||||
def create_reaction(%{post: post} = attrs) do
|
||||
case %Reaction{}
|
||||
|> Map.put(:post_id, post.id)
|
||||
|
||||
@@ -22,9 +22,16 @@ defmodule Claper.Posts.Post do
|
||||
@doc false
|
||||
def changeset(post, attrs) do
|
||||
post
|
||||
|> cast(attrs, [:body, :attendee_identifier, :user_id, :like_count, :love_count, :lol_count, :position])
|
||||
|> cast(attrs, [
|
||||
:body,
|
||||
:attendee_identifier,
|
||||
:user_id,
|
||||
:like_count,
|
||||
:love_count,
|
||||
:lol_count,
|
||||
:position
|
||||
])
|
||||
|> validate_required([:body, :position])
|
||||
|> validate_length(:body, min: 2, max: 250)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -17,7 +17,14 @@ defmodule Claper.Presentations.PresentationState do
|
||||
@doc false
|
||||
def changeset(presentation_state, attrs) do
|
||||
presentation_state
|
||||
|> cast(attrs, [:position, :chat_visible, :poll_visible, :join_screen_visible, :banned, :presentation_file_id])
|
||||
|> cast(attrs, [
|
||||
:position,
|
||||
:chat_visible,
|
||||
:poll_visible,
|
||||
:join_screen_visible,
|
||||
:banned,
|
||||
:presentation_file_id
|
||||
])
|
||||
|> validate_required([])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -47,13 +47,14 @@ defmodule Claper.Tasks.Converter do
|
||||
IO.puts("Clearing #{hash}...")
|
||||
|
||||
if System.get_env("PRESENTATION_STORAGE", "local") == "local" do
|
||||
File.rm_rf(Path.join([
|
||||
File.rm_rf(
|
||||
Path.join([
|
||||
:code.priv_dir(:claper),
|
||||
"static",
|
||||
"uploads",
|
||||
"#{hash}"
|
||||
]))
|
||||
|
||||
])
|
||||
)
|
||||
else
|
||||
stream =
|
||||
ExAws.S3.list_objects(System.get_env("AWS_PRES_BUCKET"), prefix: "presentations/#{hash}")
|
||||
@@ -115,28 +116,27 @@ defmodule Claper.Tasks.Converter do
|
||||
end
|
||||
|
||||
defp jpg_upload(%Result{status: 0}, hash, path, presentation, user_id) do
|
||||
|
||||
files = Path.wildcard("#{path}/*.jpg")
|
||||
|
||||
# assign new hash to avoid cache issues
|
||||
new_hash = :erlang.phash2("#{hash}-#{System.system_time(:second)}")
|
||||
|
||||
if System.get_env("PRESENTATION_STORAGE", "local") == "local" do
|
||||
|
||||
File.rename(Path.join([
|
||||
File.rename(
|
||||
Path.join([
|
||||
:code.priv_dir(:claper),
|
||||
"static",
|
||||
"uploads",
|
||||
"#{hash}"
|
||||
]), Path.join([
|
||||
]),
|
||||
Path.join([
|
||||
:code.priv_dir(:claper),
|
||||
"static",
|
||||
"uploads",
|
||||
"#{new_hash}"
|
||||
]))
|
||||
|
||||
])
|
||||
)
|
||||
else
|
||||
|
||||
for f <- files do
|
||||
IO.puts("Uploads #{f} to presentations/#{new_hash}/#{Path.basename(f)}")
|
||||
|
||||
@@ -149,7 +149,6 @@ defmodule Claper.Tasks.Converter do
|
||||
)
|
||||
|> ExAws.request()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if !is_nil(presentation.hash) do
|
||||
|
||||
@@ -5,6 +5,7 @@ defmodule ClaperWeb.Presence do
|
||||
See the [`Phoenix.Presence`](http://hexdocs.pm/phoenix/Phoenix.Presence.html)
|
||||
docs for more details.
|
||||
"""
|
||||
use Phoenix.Presence, otp_app: :claper,
|
||||
use Phoenix.Presence,
|
||||
otp_app: :claper,
|
||||
pubsub_server: Claper.PubSub
|
||||
end
|
||||
|
||||
@@ -8,22 +8,24 @@ defmodule ClaperWeb.PostController do
|
||||
render(conn, "index.json", posts: posts)
|
||||
end
|
||||
rescue
|
||||
Ecto.NoResultsError -> conn
|
||||
Ecto.NoResultsError ->
|
||||
conn
|
||||
|> put_status(:not_found)
|
||||
|> put_view(ClaperWeb.ErrorView)
|
||||
|> render(:"404")
|
||||
end
|
||||
end
|
||||
|
||||
def create(conn, %{"event_id" => event_id, "body" => body}) do
|
||||
try do
|
||||
with event <- Claper.Events.get_event!(event_id) do
|
||||
case Claper.Posts.create_post(event, %{body: body}) do
|
||||
{:ok, post} -> render(conn, "post.json", post: post)
|
||||
end
|
||||
|
||||
end
|
||||
rescue
|
||||
Ecto.NoResultsError -> conn
|
||||
Ecto.NoResultsError ->
|
||||
conn
|
||||
|> put_status(:not_found)
|
||||
|> put_view(ClaperWeb.ErrorView)
|
||||
|> render(:"404")
|
||||
|
||||
@@ -153,7 +153,6 @@ defmodule ClaperWeb.EventLive.FormComponent do
|
||||
end
|
||||
|
||||
defp create_event(socket, event_params, hash, ext) do
|
||||
|
||||
case Events.create_event(
|
||||
event_params
|
||||
|> Map.put("user_id", socket.assigns.current_user.id)
|
||||
|
||||
@@ -90,5 +90,4 @@ defmodule ClaperWeb.EventLive.Index do
|
||||
defp list_managed_events(socket) do
|
||||
Events.list_managed_events_by(socket.assigns.current_user.email, [:presentation_file])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -88,7 +88,6 @@ defmodule ClaperWeb.EventLive.Show do
|
||||
|
||||
{:ok, socket |> assign(:empty_room, Enum.count(socket.assigns.posts) == 0),
|
||||
temporary_assigns: [posts: []]}
|
||||
|
||||
end
|
||||
|
||||
defp leader_list(socket, event) do
|
||||
|
||||
@@ -20,5 +20,4 @@ defmodule ClaperWeb.LiveHelpers do
|
||||
modal_opts = [id: :modal, return_to: path, component: component, opts: opts]
|
||||
live_component(ClaperWeb.ModalComponent, modal_opts)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -31,7 +31,10 @@ defmodule ClaperWeb.StatLive.Index do
|
||||
grouped_total_votes
|
||||
)
|
||||
|> assign(:average_voters, average_voters(grouped_total_votes))
|
||||
|> assign(:engagement_rate, calculate_engagement_rate(grouped_total_votes, distinct_poster_count, event))
|
||||
|> assign(
|
||||
:engagement_rate,
|
||||
calculate_engagement_rate(grouped_total_votes, distinct_poster_count, event)
|
||||
)
|
||||
|> assign(:posts, list_posts(socket, event.uuid))}
|
||||
end
|
||||
|
||||
@@ -49,9 +52,16 @@ defmodule ClaperWeb.StatLive.Index do
|
||||
total_polls = Enum.count(grouped_total_votes)
|
||||
|
||||
if total_polls == 0 do
|
||||
(distinct_poster_count/event.audience_peak) * 100 |> Float.round |> :erlang.float_to_binary(decimals: 0) |> :erlang.binary_to_integer
|
||||
(distinct_poster_count / event.audience_peak * 100)
|
||||
|> Float.round()
|
||||
|> :erlang.float_to_binary(decimals: 0)
|
||||
|> :erlang.binary_to_integer()
|
||||
else
|
||||
(((distinct_poster_count/event.audience_peak) + (average_voters(grouped_total_votes))/event.audience_peak) / 2) * 100 |> Float.round |> :erlang.float_to_binary(decimals: 0) |> :erlang.binary_to_integer
|
||||
((distinct_poster_count / event.audience_peak +
|
||||
average_voters(grouped_total_votes) / event.audience_peak) / 2 * 100)
|
||||
|> Float.round()
|
||||
|> :erlang.float_to_binary(decimals: 0)
|
||||
|> :erlang.binary_to_integer()
|
||||
end
|
||||
end
|
||||
|
||||
@@ -61,9 +71,11 @@ defmodule ClaperWeb.StatLive.Index do
|
||||
if total_polls == 0 do
|
||||
0
|
||||
else
|
||||
(Enum.sum(grouped_total_votes)/total_polls) |> Float.round |> :erlang.float_to_binary(decimals: 0) |> :erlang.binary_to_integer
|
||||
(Enum.sum(grouped_total_votes) / total_polls)
|
||||
|> Float.round()
|
||||
|> :erlang.float_to_binary(decimals: 0)
|
||||
|> :erlang.binary_to_integer()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
defp list_posts(_socket, event_id) do
|
||||
|
||||
@@ -5,7 +5,10 @@ defmodule ClaperWeb.Notifiers.UserNotifier do
|
||||
def magic(email, url) do
|
||||
new()
|
||||
|> to(email)
|
||||
|> from({System.get_env("MAIL_FROM_NAME", "Claper"), System.get_env("MAIL_FROM", "noreply@claper.co")})
|
||||
|> from(
|
||||
{System.get_env("MAIL_FROM_NAME", "Claper"),
|
||||
System.get_env("MAIL_FROM", "noreply@claper.co")}
|
||||
)
|
||||
|> subject(gettext("Connect to Claper"))
|
||||
|> render_body("magic.html", %{url: url})
|
||||
end
|
||||
@@ -13,7 +16,10 @@ defmodule ClaperWeb.Notifiers.UserNotifier do
|
||||
def welcome(email) do
|
||||
new()
|
||||
|> to(email)
|
||||
|> from({System.get_env("MAIL_FROM_NAME", "Claper"), System.get_env("MAIL_FROM", "noreply@claper.co")})
|
||||
|> from(
|
||||
{System.get_env("MAIL_FROM_NAME", "Claper"),
|
||||
System.get_env("MAIL_FROM", "noreply@claper.co")}
|
||||
)
|
||||
|> subject(gettext("Next steps to boost your presentations"))
|
||||
|> render_body("welcome.html", %{email: email})
|
||||
end
|
||||
@@ -21,7 +27,10 @@ defmodule ClaperWeb.Notifiers.UserNotifier do
|
||||
def update_email(user, url) do
|
||||
new()
|
||||
|> to(user.email)
|
||||
|> from({System.get_env("MAIL_FROM_NAME", "Claper"), System.get_env("MAIL_FROM", "noreply@claper.co")})
|
||||
|> from(
|
||||
{System.get_env("MAIL_FROM_NAME", "Claper"),
|
||||
System.get_env("MAIL_FROM", "noreply@claper.co")}
|
||||
)
|
||||
|> subject(gettext("Update email instructions"))
|
||||
|> render_body("change.html", %{user: user, url: url})
|
||||
end
|
||||
|
||||
@@ -4,9 +4,11 @@ defmodule ClaperWeb.Plugs.Locale do
|
||||
def init(_opts), do: nil
|
||||
|
||||
def call(conn, _opts) do
|
||||
|
||||
known_locales = Gettext.known_locales(ClaperWeb.Gettext)
|
||||
accepted_languages = extract_accept_language(conn) |> Enum.reject(&String.length(&1) > 2 && not Enum.member?(known_locales, &1))
|
||||
|
||||
accepted_languages =
|
||||
extract_accept_language(conn)
|
||||
|> Enum.reject(&(String.length(&1) > 2 && not Enum.member?(known_locales, &1)))
|
||||
|
||||
case accepted_languages do
|
||||
[locale | _] ->
|
||||
|
||||
@@ -88,8 +88,8 @@ defmodule ClaperWeb.Router do
|
||||
# node running the Phoenix server.
|
||||
if Mix.env() == :dev || System.get_env("ENABLE_MAILBOX_ROUTE", "false") == "true" do
|
||||
scope "/dev" do
|
||||
|
||||
if System.get_env("MAILBOX_USER") && System.get_env("MAILBOX_PASSWORD") && System.get_env("ENABLE_MAILBOX_ROUTE", "false") == "true" do
|
||||
if System.get_env("MAILBOX_USER") && System.get_env("MAILBOX_PASSWORD") &&
|
||||
System.get_env("ENABLE_MAILBOX_ROUTE", "false") == "true" do
|
||||
pipe_through [:browser, :protect_with_basic_auth]
|
||||
else
|
||||
pipe_through [:browser]
|
||||
@@ -142,5 +142,4 @@ defmodule ClaperWeb.Router do
|
||||
password = System.fetch_env!("MAILBOX_PASSWORD")
|
||||
Plug.BasicAuth.basic_auth(conn, username: username, password: password)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -5,6 +5,7 @@ defmodule ClaperWeb.Component.Alert do
|
||||
assigns =
|
||||
assigns
|
||||
|> assign_new(:stick, fn -> false end)
|
||||
|
||||
~H"""
|
||||
<div class="bg-supporting-green-50 border-t-4 rounded-b-md shadow-md border-supporting-green-400 p-4 mb-3" x-data="{ open: true }" x-show={if @stick, do: "true", else: "open"} x-init="setTimeout(() => {open = false}, 4000)" x-transition>
|
||||
<div class="flex">
|
||||
@@ -27,6 +28,7 @@ defmodule ClaperWeb.Component.Alert do
|
||||
assigns =
|
||||
assigns
|
||||
|> assign_new(:stick, fn -> false end)
|
||||
|
||||
~H"""
|
||||
<div class="bg-supporting-red-50 border-t-4 rounded-b-md shadow-md border-supporting-red-400 p-4 mb-3" x-data="{ open: true }" x-show={if @stick, do: "true", else: "open"} x-init="setTimeout(() => {open = false}, 4000)" x-transition>
|
||||
<div class="flex">
|
||||
@@ -45,5 +47,4 @@ defmodule ClaperWeb.Component.Alert do
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -7,6 +7,7 @@ defmodule ClaperWeb.LayoutView do
|
||||
|
||||
def active_class(conn, path) do
|
||||
current_path = Path.join(["/" | conn.path_info])
|
||||
|
||||
if path == current_path do
|
||||
"bg-gray-900 text-white"
|
||||
else
|
||||
@@ -23,21 +24,28 @@ defmodule ClaperWeb.LayoutView do
|
||||
end
|
||||
|
||||
def active_link(%Plug.Conn{} = conn, text, opts) do
|
||||
class = [opts[:class], active_class(conn, opts[:to])]
|
||||
class =
|
||||
[opts[:class], active_class(conn, opts[:to])]
|
||||
|> Enum.filter(& &1)
|
||||
|> Enum.join(" ")
|
||||
opts = opts
|
||||
|
||||
opts =
|
||||
opts
|
||||
|> Keyword.put(:class, class)
|
||||
|
||||
link(text, opts)
|
||||
end
|
||||
|
||||
def active_link(%Phoenix.LiveView.Socket{} = conn, text, opts) do
|
||||
class = [opts[:class], active_live_class(conn, opts[:to])]
|
||||
class =
|
||||
[opts[:class], active_live_class(conn, opts[:to])]
|
||||
|> Enum.filter(& &1)
|
||||
|> Enum.join(" ")
|
||||
opts = opts
|
||||
|
||||
opts =
|
||||
opts
|
||||
|> Keyword.put(:class, class)
|
||||
|
||||
live_patch(text, opts)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
defmodule ClaperWeb.UserView do
|
||||
use ClaperWeb, :view
|
||||
|
||||
|
||||
def render("user.json", %{user: user}) do
|
||||
%{
|
||||
uuid: user.uuid,
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
defmodule Utils.FileUpload do
|
||||
|
||||
import Mogrify
|
||||
|
||||
def upload(type, path, old_path) when is_atom(type) do
|
||||
remove_old_file(old_path)
|
||||
dest = Path.join([:code.priv_dir(:claper), "static", "uploads", Atom.to_string(type), Path.basename(path)])
|
||||
|
||||
dest =
|
||||
Path.join([
|
||||
:code.priv_dir(:claper),
|
||||
"static",
|
||||
"uploads",
|
||||
Atom.to_string(type),
|
||||
Path.basename(path)
|
||||
])
|
||||
|
||||
open(path) |> resize_to_fill("100x100") |> save(in_place: true)
|
||||
File.cp!(path, dest)
|
||||
"/uploads/#{Atom.to_string(type)}/#{Path.basename(dest)}"
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
|
||||
15
mix.exs
15
mix.exs
@@ -28,7 +28,6 @@ defmodule Claper.MixProject do
|
||||
"guides/introduction/configuration.md",
|
||||
"guides/introduction/installation.md",
|
||||
"guides/introduction/storage.md",
|
||||
|
||||
"guides/usage/features.md",
|
||||
"guides/usage/howto.md"
|
||||
],
|
||||
@@ -48,19 +47,19 @@ defmodule Claper.MixProject do
|
||||
~r/ClaperWeb\.UserReset\.?/,
|
||||
~r/ClaperWeb\.Attendee\.?/,
|
||||
~r/ClaperWeb\.UserAuth\.?/,
|
||||
~r/ClaperWeb\.UserView\.?/,
|
||||
~r/ClaperWeb\.UserView\.?/
|
||||
],
|
||||
"Events": [
|
||||
Events: [
|
||||
~r/Claper\.Event\.?/,
|
||||
~r/ClaperWeb\.Event\.?/,
|
||||
~r/ClaperWeb\.Event\.?/
|
||||
],
|
||||
"Polls": [
|
||||
Polls: [
|
||||
~r/Claper\.Polls\.?/,
|
||||
~r/ClaperWeb\.Poll\.?/,
|
||||
~r/ClaperWeb\.Poll\.?/
|
||||
],
|
||||
"Posts": [
|
||||
Posts: [
|
||||
~r/Claper\.Posts\.?/,
|
||||
~r/ClaperWeb\.Post\.?/,
|
||||
~r/ClaperWeb\.Post\.?/
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -5,7 +5,6 @@ defmodule Claper.EventsTest do
|
||||
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"
|
||||
|
||||
@@ -26,17 +26,26 @@ defmodule Claper.PollsTest do
|
||||
|
||||
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: [
|
||||
|
||||
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},
|
||||
]}
|
||||
%{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,7 +92,6 @@ defmodule Claper.PollsTest do
|
||||
end
|
||||
|
||||
describe "poll_opts" do
|
||||
|
||||
import Claper.{PollsFixtures, PresentationsFixtures}
|
||||
|
||||
test "add_poll_opt/1 returns poll changeset plus the added poll_opt" do
|
||||
@@ -86,7 +99,8 @@ 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.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,12 +108,15 @@ 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}
|
||||
|
||||
test "get_poll_vote/2 returns the poll_vote with given id and user id" do
|
||||
@@ -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()
|
||||
{: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
|
||||
|
||||
@@ -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)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -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, %{})
|
||||
|
||||
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
|
||||
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)
|
||||
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(%{
|
||||
@@ -31,6 +32,7 @@ defmodule Claper.PresentationsFixtures do
|
||||
"""
|
||||
def presentation_state_fixture(attrs \\ %{}, preload \\ []) do
|
||||
assoc = %{presentation_file: attrs[:presentation_file] || presentation_file_fixture()}
|
||||
|
||||
{:ok, presentation_state} =
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
|
||||
@@ -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