From 570e86d02c698f54d8df0992c9a04cf5ed3b0c1c Mon Sep 17 00:00:00 2001 From: Chris McCord Date: Tue, 14 Dec 2021 15:29:07 -0500 Subject: [PATCH] Test song deletion --- lib/live_beats_web/live/profile_live.ex | 2 +- test/live_beats_web/live/profile_live_test.exs | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/live_beats_web/live/profile_live.ex b/lib/live_beats_web/live/profile_live.ex index 1eec09d..e707732 100644 --- a/lib/live_beats_web/live/profile_live.ex +++ b/lib/live_beats_web/live/profile_live.ex @@ -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} diff --git a/test/live_beats_web/live/profile_live_test.exs b/test/live_beats_web/live/profile_live_test.exs index 98720bf..7d706a2 100644 --- a/test/live_beats_web/live/profile_live_test.exs +++ b/test/live_beats_web/live/profile_live_test.exs @@ -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