Share recent tracks fixture between Last.fm tests
This commit is contained in:
@@ -1,21 +1,15 @@
|
||||
defmodule LastFm.ImportTest do
|
||||
use MusicLibrary.DataCase
|
||||
|
||||
alias LastFm.Fixtures.RecentTracks
|
||||
alias MusicLibrary.ListeningStats
|
||||
|
||||
@recent_tracks_fixture Path.expand(
|
||||
"../support/fixtures/last_fm/user.getrecenttracks.json",
|
||||
__DIR__
|
||||
)
|
||||
|
||||
describe "batch/1" do
|
||||
test "fetches recent tracks and persists them via ListeningStats" do
|
||||
response = @recent_tracks_fixture |> File.read!() |> JSON.decode!()
|
||||
|
||||
Req.Test.stub(LastFm.API, fn conn ->
|
||||
assert URI.decode_query(conn.query_string)["method"] == "user.getrecenttracks"
|
||||
|
||||
Req.Test.json(conn, response)
|
||||
Req.Test.json(conn, RecentTracks.get())
|
||||
end)
|
||||
|
||||
assert {:ok, count} = LastFm.Import.batch([])
|
||||
@@ -24,14 +18,12 @@ defmodule LastFm.ImportTest do
|
||||
end
|
||||
|
||||
test "forwards limit and to_uts options to the Last.fm API" do
|
||||
response = @recent_tracks_fixture |> File.read!() |> JSON.decode!()
|
||||
|
||||
Req.Test.stub(LastFm.API, fn conn ->
|
||||
params = URI.decode_query(conn.query_string)
|
||||
assert params["limit"] == "50"
|
||||
assert params["to"] == "1730600000"
|
||||
|
||||
Req.Test.json(conn, response)
|
||||
Req.Test.json(conn, RecentTracks.get())
|
||||
end)
|
||||
|
||||
assert {:ok, _count} = LastFm.Import.batch(limit: 50, to_uts: 1_730_600_000)
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
defmodule LastFm.TrackTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
@api_response_path Path.expand("../support/fixtures/last_fm/user.getrecenttracks.json", __DIR__)
|
||||
alias LastFm.Fixtures.RecentTracks
|
||||
|
||||
describe "from_api_response/1" do
|
||||
test "returns correct data" do
|
||||
api_response =
|
||||
@api_response_path
|
||||
|> File.read!()
|
||||
|> JSON.decode!()
|
||||
|> get_in(["recenttracks", "track"])
|
||||
api_response = get_in(RecentTracks.get(), ["recenttracks", "track"])
|
||||
|
||||
assert [
|
||||
%LastFm.Track{
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
defmodule LastFm.Fixtures.RecentTracks do
|
||||
@fixtures_folder Path.join([File.cwd!(), "test/support/fixtures/last_fm"])
|
||||
|
||||
@external_resource Path.join([@fixtures_folder, "user.getrecenttracks.json"])
|
||||
@get Path.join([@fixtures_folder, "user.getrecenttracks.json"])
|
||||
|> File.read!()
|
||||
|> JSON.decode!()
|
||||
|
||||
def get, do: @get
|
||||
end
|
||||
Reference in New Issue
Block a user