2020-10-18 05:59:09 +02:00
|
|
|
package lastfm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2021-07-21 02:00:58 +02:00
|
|
|
"os"
|
2020-10-18 05:59:09 +02:00
|
|
|
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("LastFM responses", func() {
|
|
|
|
Describe("Artist", func() {
|
|
|
|
It("parses the response correctly", func() {
|
|
|
|
var resp Response
|
2021-07-21 02:00:58 +02:00
|
|
|
body, _ := os.ReadFile("tests/fixtures/lastfm.artist.getinfo.json")
|
2020-10-18 05:59:09 +02:00
|
|
|
err := json.Unmarshal(body, &resp)
|
|
|
|
Expect(err).To(BeNil())
|
|
|
|
|
|
|
|
Expect(resp.Artist.Name).To(Equal("U2"))
|
|
|
|
Expect(resp.Artist.MBID).To(Equal("a3cb23fc-acd3-4ce0-8f36-1e5aa6a18432"))
|
|
|
|
Expect(resp.Artist.URL).To(Equal("https://www.last.fm/music/U2"))
|
|
|
|
Expect(resp.Artist.Bio.Summary).To(ContainSubstring("U2 é uma das mais importantes bandas de rock de todos os tempos"))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-10-20 19:38:44 +02:00
|
|
|
Describe("SimilarArtists", func() {
|
|
|
|
It("parses the response correctly", func() {
|
|
|
|
var resp Response
|
2021-07-21 02:00:58 +02:00
|
|
|
body, _ := os.ReadFile("tests/fixtures/lastfm.artist.getsimilar.json")
|
2020-10-20 19:38:44 +02:00
|
|
|
err := json.Unmarshal(body, &resp)
|
|
|
|
Expect(err).To(BeNil())
|
|
|
|
|
|
|
|
Expect(resp.SimilarArtists.Artists).To(HaveLen(2))
|
|
|
|
Expect(resp.SimilarArtists.Artists[0].Name).To(Equal("Passengers"))
|
|
|
|
Expect(resp.SimilarArtists.Artists[1].Name).To(Equal("INXS"))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-10-21 04:53:52 +02:00
|
|
|
Describe("TopTracks", func() {
|
|
|
|
It("parses the response correctly", func() {
|
|
|
|
var resp Response
|
2021-07-21 02:00:58 +02:00
|
|
|
body, _ := os.ReadFile("tests/fixtures/lastfm.artist.gettoptracks.json")
|
2020-10-21 04:53:52 +02:00
|
|
|
err := json.Unmarshal(body, &resp)
|
|
|
|
Expect(err).To(BeNil())
|
|
|
|
|
|
|
|
Expect(resp.TopTracks.Track).To(HaveLen(2))
|
|
|
|
Expect(resp.TopTracks.Track[0].Name).To(Equal("Beautiful Day"))
|
|
|
|
Expect(resp.TopTracks.Track[0].MBID).To(Equal("f7f264d0-a89b-4682-9cd7-a4e7c37637af"))
|
|
|
|
Expect(resp.TopTracks.Track[1].Name).To(Equal("With or Without You"))
|
|
|
|
Expect(resp.TopTracks.Track[1].MBID).To(Equal("6b9a509f-6907-4a6e-9345-2f12da09ba4b"))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-10-18 05:59:09 +02:00
|
|
|
Describe("Error", func() {
|
|
|
|
It("parses the error response correctly", func() {
|
2021-05-28 02:53:24 +02:00
|
|
|
var error Response
|
2020-10-18 05:59:09 +02:00
|
|
|
body := []byte(`{"error":3,"message":"Invalid Method - No method with that name in this package"}`)
|
|
|
|
err := json.Unmarshal(body, &error)
|
|
|
|
Expect(err).To(BeNil())
|
|
|
|
|
2021-05-28 02:53:24 +02:00
|
|
|
Expect(error.Error).To(Equal(3))
|
2020-10-18 05:59:09 +02:00
|
|
|
Expect(error.Message).To(Equal("Invalid Method - No method with that name in this package"))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|