Skip to content

Commit

Permalink
Sept 11 Playlist API Updates - Fixes JMPerez#103 (JMPerez#105)
Browse files Browse the repository at this point in the history
Sept 11 Playlist API Updates
  • Loading branch information
jmfortunatojr authored and JMPerez committed Aug 22, 2018
1 parent 54efc17 commit df02c5c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 92 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ spotifyApi.getUserPlaylists('jmperezperez')
console.error(err);
});

spotifyApi.getPlaylist('jmperezperez', '4vHIKV7j4QcZwgzGQcZg1x')
spotifyApi.getPlaylist('4vHIKV7j4QcZwgzGQcZg1x')
.then(function(data) {
console.log('User playlist', data);
}, function(err) {
Expand Down
63 changes: 27 additions & 36 deletions __test__/spotify-web-api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,25 +442,25 @@ describe('Basic tests', function() {
var callback = sinon.spy();
var api = new SpotifyWebApi();
api.setAccessToken('<example_access_token>');
api.getPlaylist('jmperezperez', '7Kud0O2IdWLbEGgvBkW9di', callback);
api.getPlaylist('7Kud0O2IdWLbEGgvBkW9di', callback);
that.requests[0].respond(200, { 'Content-Type': 'application/json' }, JSON.stringify(fixtures.playlist));
expect(callback.calledWith(null, fixtures.playlist)).toBeTruthy();
expect(that.requests.length).toBe(1);
expect(that.requests[0].url).toBe(
'https://api.spotify.com/v1/users/jmperezperez/playlists/7Kud0O2IdWLbEGgvBkW9di'
'https://api.spotify.com/v1/playlists/7Kud0O2IdWLbEGgvBkW9di'
);
});

it('should get the tracks of a playlist', function() {
var callback = sinon.spy();
var api = new SpotifyWebApi();
api.setAccessToken('<example_access_token>');
api.getPlaylistTracks('wizzler', '0EIVqzEcrY2a8vO0AUJar2', callback);
api.getPlaylistTracks('0EIVqzEcrY2a8vO0AUJar2', callback);
that.requests[0].respond(200, { 'Content-Type': 'application/json' }, JSON.stringify(fixtures.playlist_tracks));
expect(callback.calledWith(null, fixtures.playlist_tracks)).toBeTruthy();
expect(that.requests.length).toBe(1);
expect(that.requests[0].url).toBe(
'https://api.spotify.com/v1/users/wizzler/playlists/0EIVqzEcrY2a8vO0AUJar2/tracks'
'https://api.spotify.com/v1/playlists/0EIVqzEcrY2a8vO0AUJar2/tracks'
);
});

Expand All @@ -480,7 +480,6 @@ describe('Basic tests', function() {
var api = new SpotifyWebApi();
api.setAccessToken('<example_access_token>');
api.changePlaylistDetails(
'jmperezperez',
'7Kud0O2IdWLbEGgvBkW9di',
{
name: 'A NEW name for the playlist',
Expand All @@ -492,7 +491,7 @@ describe('Basic tests', function() {
expect(callback.calledWith(null, '')).toBeTruthy();
expect(that.requests.length).toBe(1);
expect(that.requests[0].url).toBe(
'https://api.spotify.com/v1/users/jmperezperez/playlists/7Kud0O2IdWLbEGgvBkW9di'
'https://api.spotify.com/v1/playlists/7Kud0O2IdWLbEGgvBkW9di'
);
});

Expand All @@ -501,7 +500,6 @@ describe('Basic tests', function() {
var api = new SpotifyWebApi();
api.setAccessToken('<example_access_token>');
api.addTracksToPlaylist(
'jmperezperez',
'7Kud0O2IdWLbEGgvBkW9di',
['spotify:track:2Oehrcv4Kov0SuIgWyQY9e'],
callback
Expand All @@ -510,7 +508,7 @@ describe('Basic tests', function() {
expect(callback.calledWith(null, '')).toBeTruthy();
expect(that.requests.length).toBe(1);
expect(that.requests[0].url).toBe(
'https://api.spotify.com/v1/users/jmperezperez/playlists/7Kud0O2IdWLbEGgvBkW9di/tracks'
'https://api.spotify.com/v1/playlists/7Kud0O2IdWLbEGgvBkW9di/tracks'
);
expect(that.requests[0].requestBody).toBe(
JSON.stringify({
Expand All @@ -524,7 +522,6 @@ describe('Basic tests', function() {
var api = new SpotifyWebApi();
api.setAccessToken('<example_access_token>');
api.addTracksToPlaylist(
'jmperezperez',
'7Kud0O2IdWLbEGgvBkW9di',
['spotify:track:2Oehrcv4Kov0SuIgWyQY9e'],
{ position: 0 },
Expand All @@ -534,7 +531,7 @@ describe('Basic tests', function() {
expect(callback.calledWith(null, '')).toBeTruthy();
expect(that.requests.length).toBe(1);
expect(that.requests[0].url).toBe(
'https://api.spotify.com/v1/users/jmperezperez/playlists/7Kud0O2IdWLbEGgvBkW9di/tracks?position=0'
'https://api.spotify.com/v1/playlists/7Kud0O2IdWLbEGgvBkW9di/tracks?position=0'
);
expect(that.requests[0].requestBody).toBe(
JSON.stringify({
Expand All @@ -548,7 +545,6 @@ describe('Basic tests', function() {
var api = new SpotifyWebApi();
api.setAccessToken('<example_access_token>');
api.removeTracksFromPlaylist(
'jmperezperez',
'7Kud0O2IdWLbEGgvBkW9di',
['spotify:track:2Oehrcv4Kov0SuIgWyQY9e'],
callback
Expand All @@ -557,7 +553,7 @@ describe('Basic tests', function() {
expect(callback.calledWith(null, '')).toBeTruthy();
expect(that.requests.length).toBe(1);
expect(that.requests[0].url).toBe(
'https://api.spotify.com/v1/users/jmperezperez/playlists/7Kud0O2IdWLbEGgvBkW9di/tracks'
'https://api.spotify.com/v1/playlists/7Kud0O2IdWLbEGgvBkW9di/tracks'
);
expect(that.requests[0].method).toBe('DELETE');
expect(that.requests[0].status).toBe(200);
Expand All @@ -573,7 +569,6 @@ describe('Basic tests', function() {
var api = new SpotifyWebApi();
api.setAccessToken('<example_access_token>');
api.removeTracksFromPlaylist(
'jmperezperez',
'7Kud0O2IdWLbEGgvBkW9di',
[{ uri: 'spotify:track:2Oehrcv4Kov0SuIgWyQY9e', positions: [6] }],
callback
Expand All @@ -582,7 +577,7 @@ describe('Basic tests', function() {
expect(callback.calledWith(null, '')).toBeTruthy();
expect(that.requests.length).toBe(1);
expect(that.requests[0].url).toBe(
'https://api.spotify.com/v1/users/jmperezperez/playlists/7Kud0O2IdWLbEGgvBkW9di/tracks'
'https://api.spotify.com/v1/playlists/7Kud0O2IdWLbEGgvBkW9di/tracks'
);
expect(that.requests[0].method).toBe('DELETE');
expect(that.requests[0].status).toBe(200);
Expand All @@ -603,7 +598,6 @@ describe('Basic tests', function() {
var api = new SpotifyWebApi();
api.setAccessToken('<example_access_token>');
api.removeTracksFromPlaylistWithSnapshotId(
'jmperezperez',
'7Kud0O2IdWLbEGgvBkW9di',
['spotify:track:2Oehrcv4Kov0SuIgWyQY9e'],
'AsNaPsHoTiD',
Expand All @@ -613,7 +607,7 @@ describe('Basic tests', function() {
expect(callback.calledWith(null, '')).toBeTruthy();
expect(that.requests.length).toBe(1);
expect(that.requests[0].url).toBe(
'https://api.spotify.com/v1/users/jmperezperez/playlists/7Kud0O2IdWLbEGgvBkW9di/tracks'
'https://api.spotify.com/v1/playlists/7Kud0O2IdWLbEGgvBkW9di/tracks'
);
expect(that.requests[0].method).toBe('DELETE');
expect(that.requests[0].status).toBe(200);
Expand All @@ -630,7 +624,6 @@ describe('Basic tests', function() {
var api = new SpotifyWebApi();
api.setAccessToken('<example_access_token>');
api.removeTracksFromPlaylistWithSnapshotId(
'jmperezperez',
'7Kud0O2IdWLbEGgvBkW9di',
[{ uri: 'spotify:track:2Oehrcv4Kov0SuIgWyQY9e', positions: [6] }],
'AsNaPsHoTiD',
Expand All @@ -640,7 +633,7 @@ describe('Basic tests', function() {
expect(callback.calledWith(null, '')).toBeTruthy();
expect(that.requests.length).toBe(1);
expect(that.requests[0].url).toBe(
'https://api.spotify.com/v1/users/jmperezperez/playlists/7Kud0O2IdWLbEGgvBkW9di/tracks'
'https://api.spotify.com/v1/playlists/7Kud0O2IdWLbEGgvBkW9di/tracks'
);
expect(that.requests[0].method).toBe('DELETE');
expect(that.requests[0].status).toBe(200);
Expand All @@ -662,7 +655,6 @@ describe('Basic tests', function() {
var api = new SpotifyWebApi();
api.setAccessToken('<example_access_token>');
api.removeTracksFromPlaylistInPositions(
'jmperezperez',
'7Kud0O2IdWLbEGgvBkW9di',
[0, 1, 3, 9],
'AsNaPsHoTiD',
Expand All @@ -672,7 +664,7 @@ describe('Basic tests', function() {
expect(callback.calledWith(null, '')).toBeTruthy();
expect(that.requests.length).toBe(1);
expect(that.requests[0].url).toBe(
'https://api.spotify.com/v1/users/jmperezperez/playlists/7Kud0O2IdWLbEGgvBkW9di/tracks'
'https://api.spotify.com/v1/playlists/7Kud0O2IdWLbEGgvBkW9di/tracks'
);
expect(that.requests[0].method).toBe('DELETE');
expect(that.requests[0].status).toBe(200);
Expand All @@ -689,7 +681,6 @@ describe('Basic tests', function() {
var api = new SpotifyWebApi();
api.setAccessToken('<example_access_token>');
api.replaceTracksInPlaylist(
'jmperezperez',
'7Kud0O2IdWLbEGgvBkW9di',
['spotify:track:2Oehrcv4Kov0SuIgWyQY9e'],
callback
Expand All @@ -698,7 +689,7 @@ describe('Basic tests', function() {
expect(callback.calledWith(null, '')).toBeTruthy();
expect(that.requests.length).toBe(1);
expect(that.requests[0].url).toBe(
'https://api.spotify.com/v1/users/jmperezperez/playlists/7Kud0O2IdWLbEGgvBkW9di/tracks'
'https://api.spotify.com/v1/playlists/7Kud0O2IdWLbEGgvBkW9di/tracks'
);
expect(that.requests[0].method).toBe('PUT');
expect(that.requests[0].status).toBe(200);
Expand All @@ -713,7 +704,7 @@ describe('Basic tests', function() {
var callback = sinon.spy();
var api = new SpotifyWebApi();
api.setAccessToken('<example_access_token>');
api.reorderTracksInPlaylist('jmperezperez', '7Kud0O2IdWLbEGgvBkW9di', 1, 3, callback);
api.reorderTracksInPlaylist('7Kud0O2IdWLbEGgvBkW9di', 1, 3, callback);
that.requests[0].respond(
200,
{ 'Content-Type': 'application/json' },
Expand All @@ -722,7 +713,7 @@ describe('Basic tests', function() {
expect(callback.calledWith(null, { snapshot_id: 'AsNaPsHoTiD' })).toBeTruthy();
expect(that.requests.length).toBe(1);
expect(that.requests[0].url).toBe(
'https://api.spotify.com/v1/users/jmperezperez/playlists/7Kud0O2IdWLbEGgvBkW9di/tracks'
'https://api.spotify.com/v1/playlists/7Kud0O2IdWLbEGgvBkW9di/tracks'
);
expect(that.requests[0].method).toBe('PUT');
expect(that.requests[0].status).toBe(200);
Expand All @@ -738,7 +729,7 @@ describe('Basic tests', function() {
var callback = sinon.spy();
var api = new SpotifyWebApi();
api.setAccessToken('<example_access_token>');
api.reorderTracksInPlaylist('jmperezperez', '7Kud0O2IdWLbEGgvBkW9di', 1, 3, { range_length: 2 }, callback);
api.reorderTracksInPlaylist('7Kud0O2IdWLbEGgvBkW9di', 1, 3, { range_length: 2 }, callback);
that.requests[0].respond(
200,
{ 'Content-Type': 'application/json' },
Expand All @@ -747,7 +738,7 @@ describe('Basic tests', function() {
expect(callback.calledWith(null, { snapshot_id: 'AsNaPsHoTiD' })).toBeTruthy();
expect(that.requests.length).toBe(1);
expect(that.requests[0].url).toBe(
'https://api.spotify.com/v1/users/jmperezperez/playlists/7Kud0O2IdWLbEGgvBkW9di/tracks'
'https://api.spotify.com/v1/playlists/7Kud0O2IdWLbEGgvBkW9di/tracks'
);
expect(that.requests[0].method).toBe('PUT');
expect(that.requests[0].status).toBe(200);
Expand All @@ -766,11 +757,11 @@ describe('Basic tests', function() {
var imageDataWithEncoding = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2';
var imageDataWithoutEncoding = '/9j/4AAQSkZJRgABAQAAAQABAAD/2';
api.setAccessToken('<example_access_token>');
api.uploadCustomPlaylistCoverImage('jmperezperez', '7Kud0O2IdWLbEGgvBkW9di', imageDataWithEncoding, callback);
api.uploadCustomPlaylistCoverImage('7Kud0O2IdWLbEGgvBkW9di', imageDataWithEncoding, callback);
that.requests[0].respond(202);
expect(that.requests.length).toBe(1);
expect(that.requests[0].url).toBe(
'https://api.spotify.com/v1/users/jmperezperez/playlists/7Kud0O2IdWLbEGgvBkW9di/images'
'https://api.spotify.com/v1/playlists/7Kud0O2IdWLbEGgvBkW9di/images'
);
expect(that.requests[0].method).toBe('PUT');
expect(that.requests[0].status).toBe(202);
Expand Down Expand Up @@ -945,33 +936,33 @@ describe('Basic tests', function() {
it('should follow a playlist publicly', function() {
var callback = sinon.spy();
var api = new SpotifyWebApi();
api.followPlaylist('spotify', '2ujjMpFriZ2nayLmrD1Jgl', callback);
api.followPlaylist('2ujjMpFriZ2nayLmrD1Jgl', callback);
that.requests[0].respond(200);
expect(that.requests[0].method).toBe('PUT');
expect(callback.calledWith(null, '')).toBeTruthy();
expect(that.requests.length).toBe(1);
expect(that.requests[0].url).toBe(
'https://api.spotify.com/v1/users/spotify/playlists/2ujjMpFriZ2nayLmrD1Jgl/followers'
'https://api.spotify.com/v1/playlists/2ujjMpFriZ2nayLmrD1Jgl/followers'
);
});

it('should follow a playlist privately', function() {
var callback = sinon.spy();
var api = new SpotifyWebApi();
api.followPlaylist('spotify', '2ujjMpFriZ2nayLmrD1Jgl', { public: false }, callback);
api.followPlaylist('2ujjMpFriZ2nayLmrD1Jgl', { public: false }, callback);
that.requests[0].respond(200);
expect(that.requests[0].method).toBe('PUT');
expect(callback.calledWith(null, '')).toBeTruthy();
expect(that.requests.length).toBe(1);
expect(that.requests[0].url).toBe(
'https://api.spotify.com/v1/users/spotify/playlists/2ujjMpFriZ2nayLmrD1Jgl/followers'
'https://api.spotify.com/v1/playlists/2ujjMpFriZ2nayLmrD1Jgl/followers'
);
});

it('should check whether users are following a playlist', function() {
var callback = sinon.spy();
var api = new SpotifyWebApi();
api.areFollowingPlaylist('spotify', '2ujjMpFriZ2nayLmrD1Jgl', ['userid01', 'userid02'], callback);
api.areFollowingPlaylist('2ujjMpFriZ2nayLmrD1Jgl', ['userid01', 'userid02'], callback);
that.requests[0].respond(
200,
{ 'Content-Type': 'application/json' },
Expand All @@ -981,20 +972,20 @@ describe('Basic tests', function() {
expect(callback.calledWith(null, fixtures.follow_are_following_playlist)).toBeTruthy();
expect(that.requests.length).toBe(1);
expect(that.requests[0].url).toBe(
'https://api.spotify.com/v1/users/spotify/playlists/2ujjMpFriZ2nayLmrD1Jgl/followers/contains?ids=userid01%2Cuserid02'
'https://api.spotify.com/v1/playlists/2ujjMpFriZ2nayLmrD1Jgl/followers/contains?ids=userid01%2Cuserid02'
);
});

it('should unfollow a playlist', function() {
var callback = sinon.spy();
var api = new SpotifyWebApi();
api.unfollowPlaylist('spotify', '2ujjMpFriZ2nayLmrD1Jgl', callback);
api.unfollowPlaylist('2ujjMpFriZ2nayLmrD1Jgl', callback);
that.requests[0].respond(200);
expect(that.requests[0].method).toBe('DELETE');
expect(callback.calledWith(null, '')).toBeTruthy();
expect(that.requests.length).toBe(1);
expect(that.requests[0].url).toBe(
'https://api.spotify.com/v1/users/spotify/playlists/2ujjMpFriZ2nayLmrD1Jgl/followers'
'https://api.spotify.com/v1/playlists/2ujjMpFriZ2nayLmrD1Jgl/followers'
);
});

Expand Down
Loading

0 comments on commit df02c5c

Please sign in to comment.