Rename APIBehaviourMock -> APIMock
This commit is contained in:
@@ -4,7 +4,7 @@ defmodule LastFm.ConfigTest do
|
|||||||
describe "resolve/1" do
|
describe "resolve/1" do
|
||||||
test "reads data from application configuration" do
|
test "reads data from application configuration" do
|
||||||
assert %LastFm.Config{
|
assert %LastFm.Config{
|
||||||
api: LastFm.APIBehaviourMock,
|
api: LastFm.APIMock,
|
||||||
api_key: api_key,
|
api_key: api_key,
|
||||||
user: user,
|
user: user,
|
||||||
auto_refresh: false,
|
auto_refresh: false,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
defmodule MusicBrainzTest do
|
defmodule MusicBrainzTest do
|
||||||
use ExUnit.Case, async: true
|
use ExUnit.Case, async: true
|
||||||
|
|
||||||
alias MusicBrainz.APIBehaviourMock
|
alias MusicBrainz.APIMock
|
||||||
import MusicLibrary.Fixtures.ReleaseGroup
|
import MusicLibrary.Fixtures.ReleaseGroup
|
||||||
import Mox
|
import Mox
|
||||||
|
|
||||||
@@ -11,9 +11,7 @@ defmodule MusicBrainzTest do
|
|||||||
test "it returns results with correct limit and offset" do
|
test "it returns results with correct limit and offset" do
|
||||||
mock_results = release_group_search_results()
|
mock_results = release_group_search_results()
|
||||||
|
|
||||||
expect(APIBehaviourMock, :search_release_group, fn "Marillion",
|
expect(APIMock, :search_release_group, fn "Marillion", [limit: 20, offset: 10], _config ->
|
||||||
[limit: 20, offset: 10],
|
|
||||||
_config ->
|
|
||||||
{:ok, mock_results}
|
{:ok, mock_results}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ defmodule MusicLibrary.ArtistsTest do
|
|||||||
use MusicLibrary.DataCase
|
use MusicLibrary.DataCase
|
||||||
|
|
||||||
alias MusicLibrary.Artists
|
alias MusicLibrary.Artists
|
||||||
alias LastFm.APIBehaviourMock
|
alias LastFm.APIMock
|
||||||
import MusicLibrary.Fixtures.Records
|
import MusicLibrary.Fixtures.Records
|
||||||
import LastFm.Fixtures.Artist
|
import LastFm.Fixtures.Artist
|
||||||
import Mox
|
import Mox
|
||||||
@@ -48,8 +48,7 @@ defmodule MusicLibrary.ArtistsTest do
|
|||||||
|
|
||||||
expected_info = get_info()
|
expected_info = get_info()
|
||||||
|
|
||||||
expect(APIBehaviourMock, :get_artist_info, fn {:musicbrainz_id, ^artist_musicbrainz_id},
|
expect(APIMock, :get_artist_info, fn {:musicbrainz_id, ^artist_musicbrainz_id}, _config ->
|
||||||
_config ->
|
|
||||||
{:ok, expected_info}
|
{:ok, expected_info}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ defmodule MusicLibrary.RecordsTest do
|
|||||||
|
|
||||||
alias MusicLibrary.Records
|
alias MusicLibrary.Records
|
||||||
alias MusicLibrary.Records.SearchIndex
|
alias MusicLibrary.Records.SearchIndex
|
||||||
alias MusicBrainz.APIBehaviourMock
|
alias MusicBrainz.APIMock
|
||||||
import MusicLibrary.Fixtures.Records
|
import MusicLibrary.Fixtures.Records
|
||||||
import MusicLibrary.Fixtures.ReleaseGroup
|
import MusicLibrary.Fixtures.ReleaseGroup
|
||||||
import MusicBrainz.Fixtures.Release
|
import MusicBrainz.Fixtures.Release
|
||||||
@@ -63,11 +63,11 @@ defmodule MusicLibrary.RecordsTest do
|
|||||||
assert record.release_ids == []
|
assert record.release_ids == []
|
||||||
assert record.included_release_group_ids == []
|
assert record.included_release_group_ids == []
|
||||||
|
|
||||||
expect(APIBehaviourMock, :get_release_group, fn ^release_group_id, _config ->
|
expect(APIMock, :get_release_group, fn ^release_group_id, _config ->
|
||||||
{:ok, release_group(:lockdown_trilogy)}
|
{:ok, release_group(:lockdown_trilogy)}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
expect(APIBehaviourMock, :get_releases, fn ^release_group_id, _opts, _config ->
|
expect(APIMock, :get_releases, fn ^release_group_id, _opts, _config ->
|
||||||
{:ok, %{"releases" => release_group(:lockdown_trilogy)["releases"]}}
|
{:ok, %{"releases" => release_group(:lockdown_trilogy)["releases"]}}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -189,17 +189,17 @@ defmodule MusicLibrary.RecordsTest do
|
|||||||
release_group = release_group(:marbles)
|
release_group = release_group(:marbles)
|
||||||
release_group_id = release_group_id(:marbles)
|
release_group_id = release_group_id(:marbles)
|
||||||
|
|
||||||
expect(APIBehaviourMock, :get_release_group, fn ^release_group_id, _config ->
|
expect(APIMock, :get_release_group, fn ^release_group_id, _config ->
|
||||||
{:ok, release_group}
|
{:ok, release_group}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
expect(APIBehaviourMock, :get_releases, fn ^release_group_id, _opts, _config ->
|
expect(APIMock, :get_releases, fn ^release_group_id, _opts, _config ->
|
||||||
{:ok, %{"releases" => release_group["releases"]}}
|
{:ok, %{"releases" => release_group["releases"]}}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
cover_data = File.read!(marbles_cover_fixture())
|
cover_data = File.read!(marbles_cover_fixture())
|
||||||
|
|
||||||
expect(APIBehaviourMock, :get_cover_art, fn {:musicbrainz_id, ^release_group_id}, _config ->
|
expect(APIMock, :get_cover_art, fn {:musicbrainz_id, ^release_group_id}, _config ->
|
||||||
{:ok, cover_data}
|
{:ok, cover_data}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -243,21 +243,21 @@ defmodule MusicLibrary.RecordsTest do
|
|||||||
release_group = release_group(:marbles)
|
release_group = release_group(:marbles)
|
||||||
release_group_id = release_group_id(:marbles)
|
release_group_id = release_group_id(:marbles)
|
||||||
|
|
||||||
expect(APIBehaviourMock, :get_release, fn ^release_id, _config ->
|
expect(APIMock, :get_release, fn ^release_id, _config ->
|
||||||
{:ok, release}
|
{:ok, release}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
expect(APIBehaviourMock, :get_release_group, fn ^release_group_id, _config ->
|
expect(APIMock, :get_release_group, fn ^release_group_id, _config ->
|
||||||
{:ok, release_group}
|
{:ok, release_group}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
expect(APIBehaviourMock, :get_releases, fn ^release_group_id, _opts, _config ->
|
expect(APIMock, :get_releases, fn ^release_group_id, _opts, _config ->
|
||||||
{:ok, %{"releases" => release_group["releases"]}}
|
{:ok, %{"releases" => release_group["releases"]}}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
cover_data = File.read!(marbles_cover_fixture())
|
cover_data = File.read!(marbles_cover_fixture())
|
||||||
|
|
||||||
expect(APIBehaviourMock, :get_cover_art, fn {:musicbrainz_id, ^release_group_id}, _config ->
|
expect(APIMock, :get_cover_art, fn {:musicbrainz_id, ^release_group_id}, _config ->
|
||||||
{:ok, cover_data}
|
{:ok, cover_data}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -299,7 +299,7 @@ defmodule MusicLibrary.RecordsTest do
|
|||||||
|
|
||||||
cover_url = record.cover_url
|
cover_url = record.cover_url
|
||||||
|
|
||||||
expect(APIBehaviourMock, :get_cover_art, fn {:url, ^cover_url}, _config ->
|
expect(APIMock, :get_cover_art, fn {:url, ^cover_url}, _config ->
|
||||||
{:ok, raven_cover_data}
|
{:ok, raven_cover_data}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -317,7 +317,7 @@ defmodule MusicLibrary.RecordsTest do
|
|||||||
barcode = "5052205070023"
|
barcode = "5052205070023"
|
||||||
releases = releases(:queen_greatest_hits)
|
releases = releases(:queen_greatest_hits)
|
||||||
|
|
||||||
expect(APIBehaviourMock, :search_release_by_barcode, fn ^barcode, _config ->
|
expect(APIMock, :search_release_by_barcode, fn ^barcode, _config ->
|
||||||
{:ok, releases}
|
{:ok, releases}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
|
|||||||
import LastFm.Fixtures.Artist
|
import LastFm.Fixtures.Artist
|
||||||
import Mox
|
import Mox
|
||||||
|
|
||||||
alias LastFm.APIBehaviourMock
|
alias LastFm.APIMock
|
||||||
|
|
||||||
setup :verify_on_exit!
|
setup :verify_on_exit!
|
||||||
|
|
||||||
@@ -28,8 +28,7 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
|
|||||||
conn: conn,
|
conn: conn,
|
||||||
artist_musicbrainz_id: artist_musicbrainz_id
|
artist_musicbrainz_id: artist_musicbrainz_id
|
||||||
} do
|
} do
|
||||||
expect(APIBehaviourMock, :get_artist_info, fn {:musicbrainz_id, ^artist_musicbrainz_id},
|
expect(APIMock, :get_artist_info, fn {:musicbrainz_id, ^artist_musicbrainz_id}, _config ->
|
||||||
_config ->
|
|
||||||
{:ok, get_info()}
|
{:ok, get_info()}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -45,8 +44,7 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
|
|||||||
conn: conn,
|
conn: conn,
|
||||||
artist_musicbrainz_id: artist_musicbrainz_id
|
artist_musicbrainz_id: artist_musicbrainz_id
|
||||||
} do
|
} do
|
||||||
expect(APIBehaviourMock, :get_artist_info, fn {:musicbrainz_id, ^artist_musicbrainz_id},
|
expect(APIMock, :get_artist_info, fn {:musicbrainz_id, ^artist_musicbrainz_id}, _config ->
|
||||||
_config ->
|
|
||||||
{:error, :timeout}
|
{:error, :timeout}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -74,8 +72,7 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
|
|||||||
record_with_artist("Porcupine Tree", %{purchased_at: DateTime.utc_now()})
|
record_with_artist("Porcupine Tree", %{purchased_at: DateTime.utc_now()})
|
||||||
|
|
||||||
# for this test, we don't care about the artist info, but we mock it to avoid false test failures
|
# for this test, we don't care about the artist info, but we mock it to avoid false test failures
|
||||||
expect(APIBehaviourMock, :get_artist_info, fn {:musicbrainz_id, ^artist_musicbrainz_id},
|
expect(APIMock, :get_artist_info, fn {:musicbrainz_id, ^artist_musicbrainz_id}, _config ->
|
||||||
_config ->
|
|
||||||
{:error, :timeout}
|
{:error, :timeout}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
|
|||||||
import MusicLibraryWeb.RecordComponents, only: [format_label: 1, type_label: 1]
|
import MusicLibraryWeb.RecordComponents, only: [format_label: 1, type_label: 1]
|
||||||
import Mox
|
import Mox
|
||||||
alias MusicLibrary.Records.{Cover, Record}
|
alias MusicLibrary.Records.{Cover, Record}
|
||||||
alias MusicBrainz.APIBehaviourMock
|
alias MusicBrainz.APIMock
|
||||||
|
|
||||||
setup :verify_on_exit!
|
setup :verify_on_exit!
|
||||||
|
|
||||||
@@ -244,9 +244,9 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
|
|||||||
test "it imports a record when selected", %{conn: conn} do
|
test "it imports a record when selected", %{conn: conn} do
|
||||||
mock_results = release_group_search_results()
|
mock_results = release_group_search_results()
|
||||||
|
|
||||||
expect(APIBehaviourMock, :search_release_group, fn "Marillion Marbles",
|
expect(APIMock, :search_release_group, fn "Marillion Marbles",
|
||||||
[limit: 10, offset: 0],
|
[limit: 10, offset: 0],
|
||||||
_config ->
|
_config ->
|
||||||
{:ok, mock_results}
|
{:ok, mock_results}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -267,17 +267,17 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
|
|||||||
|
|
||||||
release_group = release_group(:marbles)
|
release_group = release_group(:marbles)
|
||||||
|
|
||||||
expect(APIBehaviourMock, :get_release_group, fn ^first_result_id, _config ->
|
expect(APIMock, :get_release_group, fn ^first_result_id, _config ->
|
||||||
{:ok, release_group}
|
{:ok, release_group}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
expect(APIBehaviourMock, :get_releases, fn ^first_result_id, _opts, _config ->
|
expect(APIMock, :get_releases, fn ^first_result_id, _opts, _config ->
|
||||||
{:ok, %{"releases" => release_group["releases"]}}
|
{:ok, %{"releases" => release_group["releases"]}}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
cover_data = File.read!(marbles_cover_fixture())
|
cover_data = File.read!(marbles_cover_fixture())
|
||||||
|
|
||||||
expect(APIBehaviourMock, :get_cover_art, fn {:musicbrainz_id, ^first_result_id}, _config ->
|
expect(APIMock, :get_cover_art, fn {:musicbrainz_id, ^first_result_id}, _config ->
|
||||||
{:ok, cover_data}
|
{:ok, cover_data}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do
|
|||||||
use MusicLibraryWeb.ConnCase
|
use MusicLibraryWeb.ConnCase
|
||||||
|
|
||||||
alias MusicLibrary.{Records, Repo, Wishlist}
|
alias MusicLibrary.{Records, Repo, Wishlist}
|
||||||
alias MusicBrainz.APIBehaviourMock
|
alias MusicBrainz.APIMock
|
||||||
import MusicLibraryWeb.RecordComponents, only: [format_label: 1, type_label: 1]
|
import MusicLibraryWeb.RecordComponents, only: [format_label: 1, type_label: 1]
|
||||||
import MusicLibrary.Fixtures.Records
|
import MusicLibrary.Fixtures.Records
|
||||||
import MusicLibrary.Fixtures.ReleaseGroup
|
import MusicLibrary.Fixtures.ReleaseGroup
|
||||||
@@ -186,22 +186,22 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do
|
|||||||
release_group = release_group(:mystery_of_time)
|
release_group = release_group(:mystery_of_time)
|
||||||
release_group_id = release_group_id(:mystery_of_time)
|
release_group_id = release_group_id(:mystery_of_time)
|
||||||
|
|
||||||
expect(APIBehaviourMock, :get_release, fn ^release_id, _config ->
|
expect(APIMock, :get_release, fn ^release_id, _config ->
|
||||||
{:ok, release}
|
{:ok, release}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
expect(APIBehaviourMock, :get_release_group, fn ^release_group_id, _config ->
|
expect(APIMock, :get_release_group, fn ^release_group_id, _config ->
|
||||||
{:ok, release_group}
|
{:ok, release_group}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
expect(APIBehaviourMock, :get_releases, fn ^release_group_id, _opts, _config ->
|
expect(APIMock, :get_releases, fn ^release_group_id, _opts, _config ->
|
||||||
{:ok, %{"releases" => release_group["releases"]}}
|
{:ok, %{"releases" => release_group["releases"]}}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
# Doesn't matter if we use a different cover
|
# Doesn't matter if we use a different cover
|
||||||
cover_data = File.read!(marbles_cover_fixture())
|
cover_data = File.read!(marbles_cover_fixture())
|
||||||
|
|
||||||
expect(APIBehaviourMock, :get_cover_art, fn {:musicbrainz_id, ^release_group_id}, _config ->
|
expect(APIMock, :get_cover_art, fn {:musicbrainz_id, ^release_group_id}, _config ->
|
||||||
{:ok, cover_data}
|
{:ok, cover_data}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
Mox.defmock(MusicBrainz.APIBehaviourMock, for: MusicBrainz.APIBehaviour)
|
Mox.defmock(MusicBrainz.APIMock, for: MusicBrainz.APIBehaviour)
|
||||||
|
|
||||||
music_brainz_config =
|
music_brainz_config =
|
||||||
Application.get_env(:music_library, MusicBrainz)
|
Application.get_env(:music_library, MusicBrainz)
|
||||||
|> Keyword.put(:api, MusicBrainz.APIBehaviourMock)
|
|> Keyword.put(:api, MusicBrainz.APIMock)
|
||||||
|
|
||||||
Application.put_env(:music_library, MusicBrainz, music_brainz_config)
|
Application.put_env(:music_library, MusicBrainz, music_brainz_config)
|
||||||
|
|
||||||
Mox.defmock(LastFm.APIBehaviourMock, for: LastFm.APIBehaviour)
|
Mox.defmock(LastFm.APIMock, for: LastFm.APIBehaviour)
|
||||||
|
|
||||||
last_fm_config =
|
last_fm_config =
|
||||||
Application.get_env(:music_library, LastFm)
|
Application.get_env(:music_library, LastFm)
|
||||||
|> Keyword.put(:api, LastFm.APIBehaviourMock)
|
|> Keyword.put(:api, LastFm.APIMock)
|
||||||
|
|
||||||
Application.put_env(:music_library, LastFm, last_fm_config)
|
Application.put_env(:music_library, LastFm, last_fm_config)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user