Files
music_library/test/last_fm_test.exs
T
Claudio Ortolina 03e4c6195b Update dependencies
db_connection 2.7.0 => 2.8.0
ecto 3.13.1 => 3.13.2
ecto_sql 3.13.1 => 3.13.2
ecto_sqlite3 0.20.0 => 0.21.0 (minor)
phoenix_ecto 4.6.4 => 4.6.5
req 0.5.11 => 0.5.12

Restores old form of last_fm_test which had changed to accomodate a
change of default of Req.
2025-06-24 20:19:12 +03:00

65 lines
1.9 KiB
Elixir

defmodule LastFmTest do
use ExUnit.Case, async: true
alias LastFm.{Artist, Fixtures, Scrobble}
describe "get_artist_info/1" do
test "it returns the artist info" do
name = "Steven Wilson"
musicbrainz_id = Ecto.UUID.generate()
expected_info =
Fixtures.Artist.get_info()
|> Map.get("artist")
|> Artist.from_api_response()
Req.Test.stub(LastFm.API, fn conn ->
Req.Test.json(conn, Fixtures.Artist.get_info())
end)
assert {:ok, expected_info} == LastFm.get_artist_info(musicbrainz_id, name)
end
end
describe "scrobble/2" do
test "it returns the scrobbled track" do
scrobbles = [
%Scrobble{
track: "Wonderland",
artist: "IQ",
album: "Dominion",
timestamp: 1_746_561_301,
mbid: "aefaaf73-b52c-4b0d-91df-f8e4321db2bd"
}
]
session_key = "session_key"
response_body = %{
"scrobbles" => %{
"@attr" => %{"accepted" => 1, "ignored" => 0},
"scrobble" => %{
"album" => %{"#text" => "Dominion", "corrected" => "0"},
"albumArtist" => %{"#text" => "", "corrected" => "0"},
"artist" => %{"#text" => "IQ", "corrected" => "0"},
"ignoredMessage" => %{"#text" => "", "code" => "1"},
"timestamp" => "1746561301",
"track" => %{"#text" => "Wonderland", "corrected" => "0"}
}
}
}
Req.Test.stub(LastFm.API, fn conn ->
body = Req.Test.raw_body(conn)
assert body ==
"album%5B0%5D=Dominion&api_key=change+me&api_sig=f3c0644ba671654aafb2396806c4b96f&artist%5B0%5D=IQ&format=json&mbid%5B0%5D=aefaaf73-b52c-4b0d-91df-f8e4321db2bd&method=track.scrobble&sk=session_key&timestamp%5B0%5D=1746561301&track%5B0%5D=Wonderland"
Req.Test.json(conn, response_body)
end)
assert {:ok, response_body} == LastFm.scrobble(scrobbles, session_key)
end
end
end