-
Notifications
You must be signed in to change notification settings - Fork 19
/
catalog_artists_test.go
107 lines (96 loc) · 2.44 KB
/
catalog_artists_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package applemusic
import (
"context"
"net/http"
"reflect"
"testing"
)
func TestCatalogService_GetArtist(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v1/catalog/us/artists/178834", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
w.WriteHeader(http.StatusOK)
_, _ = w.Write(artistsJSON)
})
got, _, err := client.Catalog.GetArtist(context.Background(), "us", "178834", nil)
if err != nil {
t.Errorf("Catalog.GetArtist returned error: %v", err)
}
if want := artists; !reflect.DeepEqual(got, want) {
t.Errorf("Catalog.GetArtist = %+v, want %+v", got, want)
}
}
func TestCatalogService_GetArtistsByIds(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v1/catalog/us/artists", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{
"ids": "178834,462006",
})
w.WriteHeader(http.StatusOK)
})
_, _, err := client.Catalog.GetArtistsByIds(context.Background(), "us", []string{"178834", "462006"}, nil)
if err != nil {
t.Errorf("Catalog.GetArtistsByIds returned error: %v", err)
}
}
var artistsJSON = []byte(`{
"data": [
{
"id": "178834",
"type": "artists",
"href": "/v1/catalog/us/artists/178834",
"attributes": {
"url": "https://itunes.apple.com/us/artist/bruce-springsteen/id178834",
"name": "Bruce Springsteen",
"genreNames": [
"Rock"
]
},
"relationships": {
"albums": {
"data": [
{
"id": "1185902474",
"type": "albums",
"href": "/v1/catalog/us/albums/1185902474"
}
],
"href": "/v1/catalog/us/artists/178834/albums",
"next": "/v1/catalog/us/artists/178834/albums?offset=25"
}
}
}
]
}`)
var artists = &Artists{
Data: []Artist{
{
Id: "178834",
Type: "artists",
Href: "/v1/catalog/us/artists/178834",
Attributes: ArtistAttributes{
URL: "https://itunes.apple.com/us/artist/bruce-springsteen/id178834",
Name: "Bruce Springsteen",
GenreNames: []string{
"Rock",
},
},
Relationships: ArtistRelationships{
Albums: Albums{
Data: []Album{
{
Id: "1185902474",
Type: "albums",
Href: "/v1/catalog/us/albums/1185902474",
},
},
Href: "/v1/catalog/us/artists/178834/albums",
Next: "/v1/catalog/us/artists/178834/albums?offset=25",
},
},
},
},
}