Skip to content

Commit 13ff171

Browse files
committed
Fix #349: Transfer playback options parameter is optional
1 parent bfadbfa commit 13ff171

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

__tests__/spotify-web-api.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,6 +1846,42 @@ describe('Spotify Web API', () => {
18461846
);
18471847
});
18481848

1849+
test("should transfer the user's playback without using options", done => {
1850+
sinon.stub(HttpManager, '_makeRequest').callsFake(function(
1851+
method,
1852+
options,
1853+
uri,
1854+
callback
1855+
) {
1856+
expect(method).toBe(superagent.put);
1857+
expect(uri).toBe('https://api.spotify.com/v1/me/player');
1858+
expect(JSON.parse(options.data)).toEqual({
1859+
device_ids : ['my-device-id']
1860+
});
1861+
expect(options.query).toBeFalsy();
1862+
expect(options.headers['Content-Type']).toBe('application/json');
1863+
callback();
1864+
});
1865+
1866+
var accessToken = 'myAccessToken';
1867+
1868+
var api = new SpotifyWebApi({
1869+
accessToken: accessToken
1870+
});
1871+
1872+
api
1873+
.transferMyPlayback(['my-device-id'])
1874+
.then(
1875+
function(data) {
1876+
done();
1877+
},
1878+
function(err) {
1879+
console.log(err);
1880+
done(err);
1881+
}
1882+
);
1883+
});
1884+
18491885
test("should resume the user's playback", done => {
18501886
sinon.stub(HttpManager, '_makeRequest').callsFake(function(
18511887
method,

src/spotify-web-api.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,10 +1027,12 @@ SpotifyWebApi.prototype = {
10271027
return WebApiRequest.builder(this.getAccessToken())
10281028
.withPath('/v1/me/player')
10291029
.withHeaders({ 'Content-Type': 'application/json' })
1030-
.withBodyParameters({
1031-
device_ids: deviceIds,
1032-
play: !!options.play
1033-
})
1030+
.withBodyParameters(
1031+
{
1032+
device_ids: deviceIds,
1033+
},
1034+
options
1035+
)
10341036
.build()
10351037
.execute(HttpManager.put, callback);
10361038
},

0 commit comments

Comments
 (0)