Skip to content

Commit 8b4aecb

Browse files
authored
Handle empty user in getUserPlaylists() (#244)
1 parent dba91a8 commit 8b4aecb

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

__tests__/spotify-web-api.js

+35
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,41 @@ describe('Spotify Web API', () => {
14471447
});
14481448
});
14491449

1450+
test('should get the current users playlists with options', done => {
1451+
sinon.stub(HttpManager, '_makeRequest', function(
1452+
method,
1453+
options,
1454+
uri,
1455+
callback
1456+
) {
1457+
expect(method).toBe(superagent.get);
1458+
expect(uri).toBe('https://api.spotify.com/v1/me/playlists');
1459+
expect(options.query).toEqual({ limit: 27, offset: 7 });
1460+
callback(null, {
1461+
body: {
1462+
items: [
1463+
{
1464+
uri: 'spotify:user:thelinmichael:playlist:5ieJqeLJjjI8iJWaxeBLuK'
1465+
},
1466+
{
1467+
uri: 'spotify:user:thelinmichael:playlist:3EsfV6XzCHU8SPNdbnFogK'
1468+
}
1469+
]
1470+
},
1471+
statusCode: 200
1472+
});
1473+
});
1474+
1475+
var api = new SpotifyWebApi();
1476+
api.setAccessToken('myVeryLongAccessToken');
1477+
1478+
api.getUserPlaylists({ limit: 27, offset: 7 }).then(function(data) {
1479+
expect(2).toBe(data.body.items.length);
1480+
expect(data.statusCode).toBe(200);
1481+
done();
1482+
});
1483+
});
1484+
14501485
test('should get a playlist', done => {
14511486
sinon.stub(HttpManager, '_makeRequest', function(
14521487
method,

src/spotify-web-api.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,11 @@ SpotifyWebApi.prototype = {
457457
var path;
458458
if (typeof userId === 'string') {
459459
path = '/v1/users/' + encodeURIComponent(userId) + '/playlists';
460-
} else {
460+
} else if (typeof userId === 'object') {
461+
callback = options;
462+
options = userId;
463+
path = '/v1/me/playlists';
464+
} /* undefined */ else {
461465
path = '/v1/me/playlists';
462466
}
463467

0 commit comments

Comments
 (0)