Stub artist show test

This commit is contained in:
Claudio Ortolina
2024-12-03 20:15:07 +00:00
parent 9f2335cfa0
commit bef38967a1
3 changed files with 52 additions and 0 deletions
@@ -0,0 +1,38 @@
defmodule MusicLibraryWeb.ArtistLive.ShowTest do
use MusicLibraryWeb.ConnCase
import Phoenix.LiveViewTest
import MusicLibrary.RecordsFixtures
import LastFm.Fixtures
import Mox
alias LastFm.{Artist, APIBehaviourMock}
setup :verify_on_exit!
describe "Show artist" do
test "it shows records from the collection", %{conn: conn} do
current_time = DateTime.utc_now()
collection_record =
record_fixture_with_artist("Steven Wilson", %{purchased_at: current_time})
_wishlist_record = record_fixture_with_artist("Steven Wilson", %{purchased_at: nil})
_other_record = record_fixture_with_artist("Porcupine Tree", %{purchased_at: current_time})
[artist] = collection_record.artists
artist_musicbrainz_id = artist.musicbrainz_id
expect(APIBehaviourMock, :get_artist_info, fn ^artist_musicbrainz_id, _config ->
{:ok,
artist_get_info()
|> Map.get("artist")
|> Artist.from_api_response()}
end)
{:ok, show_live, _html} = live(conn, ~p"/artists/#{artist_musicbrainz_id}")
assert render_async(show_live) =~ "Steven Wilson"
end
end
end
@@ -0,0 +1,9 @@
defmodule LastFm.Fixtures do
@fixtures_folder Path.join([File.cwd!(), "test/support/fixtures"])
def artist_get_info do
Path.join([@fixtures_folder, "artist.getinfo.json"])
|> File.read!()
|> Jason.decode!()
end
end
+5
View File
@@ -1,5 +1,10 @@
Mox.defmock(MusicBrainz.APIBehaviourMock, for: MusicBrainz.APIBehaviour)
Application.put_env(:music_library, :musicbrainz, MusicBrainz.APIBehaviourMock)
Mox.defmock(LastFm.APIBehaviourMock, for: LastFm.APIBehaviour)
last_fm_config = Application.get_env(:music_library, LastFm)
new_last_fm_config = Keyword.put(last_fm_config, :api, LastFm.APIBehaviourMock)
Application.put_env(:music_library, LastFm, new_last_fm_config)
ExUnit.start()
Ecto.Adapters.SQL.Sandbox.mode(MusicLibrary.Repo, :manual)