Test song deletion

This commit is contained in:
Chris McCord 2021-12-14 15:29:07 -05:00
parent dda0cdaa3f
commit 570e86d02c
2 changed files with 14 additions and 3 deletions

View file

@ -133,7 +133,7 @@ defmodule LiveBeatsWeb.ProfileLive do
song = MediaLibrary.get_song!(id)
if song.user_id == socket.assigns.current_user.id do
{:ok, _} = MediaLibrary.delete_song(song)
:ok = MediaLibrary.delete_song(song)
end
{:noreply, socket}

View file

@ -4,6 +4,7 @@ defmodule LiveBeatsWeb.ProfileLiveTest do
import Phoenix.LiveViewTest
import LiveBeats.AccountsFixtures
alias LiveBeats.MediaLibrary
alias LiveBeatsWeb.LiveHelpers
setup %{conn: conn} do
@ -13,11 +14,13 @@ defmodule LiveBeatsWeb.ProfileLiveTest do
{:ok, conn: conn, current_user: current_user, user2: user2}
end
test "profile page", %{conn: conn, current_user: current_user} do
test "profile page uploads", %{conn: conn, current_user: current_user} do
profile = MediaLibrary.get_profile!(current_user)
{:ok, lv, dead_html} = live(conn, LiveHelpers.profile_path(current_user))
assert dead_html =~ "chrismccord's beats"
# uploads
assert lv
|> element("#upload-btn")
|> render_click()
@ -47,12 +50,20 @@ defmodule LiveBeatsWeb.ProfileLiveTest do
}
}) =~ "can't be blank"
assert {:ok, _new_lv, html} =
assert {:ok, new_lv, html} =
lv |> form("#song-form") |> render_submit() |> follow_redirect(conn)
assert_redirected(lv, "/#{current_user.username}")
assert html =~ "1 song(s) uploaded"
assert html =~ "silence1s"
# deleting songs
song = MediaLibrary.get_first_song(profile)
assert new_lv |> element("#delete-modal-#{song.id}-confirm") |> render_click()
{:ok, refreshed_lv, _} = live(conn, LiveHelpers.profile_path(current_user))
refute render(refreshed_lv) =~ "silence1s"
end
end