Skip to content

Commit

Permalink
fix tests and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
JannikStreek committed Nov 18, 2024
1 parent d97b0d8 commit 0a5d97e
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/mindwendel/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ defmodule Mindwendel.Accounts do
end

def get_user(id) do
Repo.get(User, id) |> Repo.preload(:brainstormings)
Repo.get(User, id) |> Repo.preload([:brainstormings, :moderated_brainstormings])
rescue
Ecto.Query.CastError -> nil
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mindwendel_web/live/idea_live/card_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule MindwendelWeb.IdeaLive.CardComponent do

%{current_user: current_user, brainstorming: brainstorming} = socket.assigns

if current_user.id in [idea.user_id | brainstorming.moderating_users |> Enum.map(& &1.id)] do
if has_moderating_or_ownership_permission(brainstorming, idea, current_user) do
{:ok, _} = Ideas.delete_idea(idea)
end

Expand Down
3 changes: 1 addition & 2 deletions lib/mindwendel_web/live/label_live/captions_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ defmodule MindwendelWeb.LabelLive.CaptionsComponent do
alias Mindwendel.Brainstormings

def handle_event("set_filter_idea_label", %{"id" => idea_label_id}, socket) do
brainstorming = socket.assigns.brainstorming
current_user = socket.assigns.current_user
%{current_user: current_user, brainstorming: brainstorming} = socket.assigns

if has_moderating_permission(brainstorming, current_user) do
# If the filter is already present, remove it as its toggled. If not, add it.
Expand Down
2 changes: 1 addition & 1 deletion lib/mindwendel_web/live/live_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule MindwendelWeb.LiveHelpers do
end

def has_moderating_permission(brainstorming, current_user) do
Enum.member?(brainstorming.moderating_users |> Enum.map(& &1.id), current_user.id)
Enum.member?(current_user.moderated_brainstormings |> Enum.map(& &1.id), brainstorming.id)
end

def has_ownership(record, current_user) do
Expand Down
6 changes: 3 additions & 3 deletions priv/gettext/de/LC_MESSAGES/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ msgstr "Wie können wir ..."
msgid "Ready?"
msgstr "Fertig?"

#: lib/mindwendel_web/live/brainstorming_live/show.ex:168
#: lib/mindwendel_web/live/brainstorming_live/show.ex:174
#, elixir-autogen, elixir-format
msgid "%{name} - Edit"
msgstr "%{name} - Editieren"

#: lib/mindwendel_web/live/brainstorming_live/show.ex:145
#: lib/mindwendel_web/live/brainstorming_live/show.ex:151
#, elixir-autogen, elixir-format
msgid "%{name} - New Idea"
msgstr "%{name} - Neue Idee"
Expand Down Expand Up @@ -403,7 +403,7 @@ msgstr "Löschen"
msgid "Type the label name"
msgstr "Gebe dem Label einen Namen"

#: lib/mindwendel_web/live/brainstorming_live/show.ex:155
#: lib/mindwendel_web/live/brainstorming_live/show.ex:161
#, elixir-autogen, elixir-format, fuzzy
msgid "%{name} - New Lane"
msgstr "%{name} - Neue Idee"
Expand Down
6 changes: 3 additions & 3 deletions priv/gettext/default.pot
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ msgstr ""
msgid "Ready?"
msgstr ""

#: lib/mindwendel_web/live/brainstorming_live/show.ex:168
#: lib/mindwendel_web/live/brainstorming_live/show.ex:174
#, elixir-autogen, elixir-format
msgid "%{name} - Edit"
msgstr ""

#: lib/mindwendel_web/live/brainstorming_live/show.ex:145
#: lib/mindwendel_web/live/brainstorming_live/show.ex:151
#, elixir-autogen, elixir-format
msgid "%{name} - New Idea"
msgstr ""
Expand Down Expand Up @@ -402,7 +402,7 @@ msgstr ""
msgid "Type the label name"
msgstr ""

#: lib/mindwendel_web/live/brainstorming_live/show.ex:155
#: lib/mindwendel_web/live/brainstorming_live/show.ex:161
#, elixir-autogen, elixir-format
msgid "%{name} - New Lane"
msgstr ""
Expand Down
6 changes: 3 additions & 3 deletions priv/gettext/en/LC_MESSAGES/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ msgstr ""
msgid "Ready?"
msgstr ""

#: lib/mindwendel_web/live/brainstorming_live/show.ex:168
#: lib/mindwendel_web/live/brainstorming_live/show.ex:174
#, elixir-autogen, elixir-format
msgid "%{name} - Edit"
msgstr ""

#: lib/mindwendel_web/live/brainstorming_live/show.ex:145
#: lib/mindwendel_web/live/brainstorming_live/show.ex:151
#, elixir-autogen, elixir-format
msgid "%{name} - New Idea"
msgstr ""
Expand Down Expand Up @@ -403,7 +403,7 @@ msgstr ""
msgid "Type the label name"
msgstr ""

#: lib/mindwendel_web/live/brainstorming_live/show.ex:155
#: lib/mindwendel_web/live/brainstorming_live/show.ex:161
#, elixir-autogen, elixir-format, fuzzy
msgid "%{name} - New Lane"
msgstr ""
Expand Down
2 changes: 1 addition & 1 deletion test/mindwendel/accounts_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ defmodule Mindwendel.AccountsTest do

describe "get_user" do
test "returns user when it exists", %{user: existing_user} do
assert existing_user |> Repo.preload(:brainstormings) ==
assert existing_user |> Repo.preload([:brainstormings, :moderated_brainstormings]) ==
Accounts.get_user(existing_user.id)
end

Expand Down
12 changes: 7 additions & 5 deletions test/mindwendel_web/live/label_live/captions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule MindwendelWeb.LabelLive.CaptionsTest do

import Phoenix.LiveViewTest

alias Mindwendel.Accounts
alias Mindwendel.Brainstormings
alias Mindwendel.Factory

Expand All @@ -16,20 +17,21 @@ defmodule MindwendelWeb.LabelLive.CaptionsTest do
brainstorming: brainstorming,
user: user
} do
preloaded_braisntorming = Brainstormings.get_brainstorming!(brainstorming.id)
preloaded_brainstorming = Brainstormings.get_brainstorming!(brainstorming.id)
preloaded_user = Accounts.get_user(user.id)

captions_component =
render_component(CaptionsComponent,
id: "captions",
brainstorming: preloaded_braisntorming,
current_user: user
brainstorming: preloaded_brainstorming,
current_user: preloaded_user
)

# make sure that there is at least one label in the list:

assert length(preloaded_braisntorming.labels) > 0
assert length(preloaded_brainstorming.labels) > 0

Enum.each(brainstorming.labels, fn label ->
Enum.each(preloaded_brainstorming.labels, fn label ->
assert captions_component =~ label.name
end)
end
Expand Down

0 comments on commit 0a5d97e

Please sign in to comment.