Stub artist show test
This commit is contained in:
@@ -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
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user