-
Notifications
You must be signed in to change notification settings - Fork 19
/
catalog_search_test.go
236 lines (222 loc) · 8.62 KB
/
catalog_search_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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
package applemusic
import (
"context"
"net/http"
"reflect"
"testing"
)
func TestCatalogService_Search(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v1/catalog/us/search", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{
"term": "james+brown",
"limit": "1",
"types": "artists,albums",
})
w.WriteHeader(http.StatusOK)
_, _ = w.Write(searchJSON)
})
opt := &SearchOptions{
Term: "james+brown",
Limit: 1,
Types: "artists,albums",
}
got, _, err := client.Catalog.Search(context.Background(), "us", opt)
if err != nil {
t.Errorf("Catalog.Search returned error: %v", err)
}
if want := search; !reflect.DeepEqual(got, want) {
t.Errorf("Catalog.Search = %+v, want %+v", got, want)
}
}
func TestCatalogService_SearchHints(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v1/catalog/us/search/hints", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{
"term": "james+brown",
"limit": "1",
"types": "artists,albums",
})
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(`{
"results": {
"terms": [
"love kendrick lamar",
"love on the brain",
"love galore",
"love",
"love songs",
"love the way you lie",
"loverboy",
"lovely day",
"love me like you do",
"love me now"
]
}
}`))
})
opt := &SearchHintsOptions{
Term: "james+brown",
Limit: 1,
Types: "artists,albums",
}
searchHints := &SearchHints{
Results: SearchHintsResults{
Terms: []string{
"love kendrick lamar",
"love on the brain",
"love galore",
"love",
"love songs",
"love the way you lie",
"loverboy",
"lovely day",
"love me like you do",
"love me now",
},
},
}
got, _, err := client.Catalog.SearchHints(context.Background(), "us", opt)
if err != nil {
t.Errorf("Catalog.SearchHints returned error: %v", err)
}
if want := searchHints; !reflect.DeepEqual(got, want) {
t.Errorf("Catalog.SearchHints = %+v, want %+v", got, want)
}
}
var searchJSON = []byte(`{
"results": {
"albums": {
"href": "/v1/catalog/us/search?types=albums&term=james+brown&limit=1",
"next": "/v1/catalog/us/search?types=albums&term=james+brown&offset=1",
"data": [
{
"id": "900721190",
"type": "albums",
"href": "/v1/catalog/us/albums/900721190",
"attributes": {
"artwork": {
"width": 1400,
"height": 1400,
"url": "https://is1-ssl.mzstatic.com/image/thumb/Music4/v4/76/85/e5/7685e5c8-9346-88db-95ff-af87bf84151b/source/{w}x{h}bb.jpg",
"bgColor": "ffffff",
"textColor1": "0a0a09",
"textColor2": "2a240f",
"textColor3": "3b3b3a",
"textColor4": "544f3f"
},
"artistName": "James Brown",
"isSingle": false,
"url": "https://itunes.apple.com/us/album/20-all-time-greatest-hits/id900721190",
"isComplete": true,
"genreNames": [
"Soul",
"Music",
"R&B/Soul",
"Funk"
],
"trackCount": 20,
"releaseDate": "1991-01-01",
"name": "20 All-Time Greatest Hits!",
"copyright": "℗ 1991 Universal Records, a Division of UMG Recordings, Inc.",
"playParams": {
"id": "900721190",
"kind": "album"
}
}
}
]
},
"artists": {
"href": "/v1/catalog/us/search?types=artists&term=james+brown&limit=1",
"next": "/v1/catalog/us/search?types=artists&term=james+brown&offset=1",
"data": [
{
"id": "117118",
"type": "artists",
"href": "/v1/catalog/us/artists/117118",
"attributes": {
"url": "https://itunes.apple.com/us/artist/james-brown/id117118",
"name": "James Brown",
"genreNames": [
"R&B/Soul"
],
"editorialNotes": {
"standard": "The Godfather of Soul, The Hardest Working Man in Show Business, Soul Brother Number One . . . Mountain-of-a-man nicknames, no doubt, but not one of them ever did James Brown the justice he deserved. JB’s influence is so large it’s plain impossible to imagine what music today would sound like without him. James didn’t just master soul and funk; he invented them. From the on-bended-knee plea called “Try Me” straight to ground zero of the hip-hop revolution, where his screams, grunts, and funky drummer backboned every cut worth mentioning, Brown was soul power itself, an inspiration to an entire nation. Now that Mr. Dynamite has taken his last sweat-drenched shuffle offstage, we’re all left like an awe-struck Apollo audience — still screaming for just one more encore while trying to take in the force of nature we were blessed to witness. James Brown’s face should be on money. His likeness carved on a mountain. And, most importantly, his music played forever."
}
}
}
]
}
}
}`)
var search = &Search{
Results: SearchResults{
Albums: &Albums{
Href: "/v1/catalog/us/search?types=albums&term=james+brown&limit=1",
Next: "/v1/catalog/us/search?types=albums&term=james+brown&offset=1",
Data: []Album{
{
Id: "900721190",
Type: "albums",
Href: "/v1/catalog/us/albums/900721190",
Attributes: AlbumAttributes{
Artwork: Artwork{
Width: 1400,
Height: 1400,
URL: "https://is1-ssl.mzstatic.com/image/thumb/Music4/v4/76/85/e5/7685e5c8-9346-88db-95ff-af87bf84151b/source/{w}x{h}bb.jpg",
BgColor: "ffffff",
TextColor1: "0a0a09",
TextColor2: "2a240f",
TextColor3: "3b3b3a",
TextColor4: "544f3f",
},
ArtistName: "James Brown",
IsSingle: false,
URL: "https://itunes.apple.com/us/album/20-all-time-greatest-hits/id900721190",
IsComplete: true,
GenreNames: []string{
"Soul",
"Music",
"R&B/Soul",
"Funk",
},
TrackCount: 20,
ReleaseDate: "1991-01-01",
Name: "20 All-Time Greatest Hits!",
Copyright: "℗ 1991 Universal Records, a Division of UMG Recordings, Inc.",
PlayParams: &PlayParameters{
Id: "900721190",
Kind: "album",
},
},
},
},
},
Artists: &Artists{
Href: "/v1/catalog/us/search?types=artists&term=james+brown&limit=1",
Next: "/v1/catalog/us/search?types=artists&term=james+brown&offset=1",
Data: []Artist{
{
Id: "117118",
Type: "artists",
Href: "/v1/catalog/us/artists/117118",
Attributes: ArtistAttributes{
URL: "https://itunes.apple.com/us/artist/james-brown/id117118",
Name: "James Brown",
GenreNames: []string{
"R&B/Soul",
},
EditorialNotes: &EditorialNotes{
Standard: "The Godfather of Soul, The Hardest Working Man in Show Business, Soul Brother Number One . . . Mountain-of-a-man nicknames, no doubt, but not one of them ever did James Brown the justice he deserved. JB’s influence is so large it’s plain impossible to imagine what music today would sound like without him. James didn’t just master soul and funk; he invented them. From the on-bended-knee plea called “Try Me” straight to ground zero of the hip-hop revolution, where his screams, grunts, and funky drummer backboned every cut worth mentioning, Brown was soul power itself, an inspiration to an entire nation. Now that Mr. Dynamite has taken his last sweat-drenched shuffle offstage, we’re all left like an awe-struck Apollo audience — still screaming for just one more encore while trying to take in the force of nature we were blessed to witness. James Brown’s face should be on money. His likeness carved on a mountain. And, most importantly, his music played forever.",
},
},
},
},
},
},
}