Skip to content

Commit 0416faa

Browse files
committed
More tests and some minor changes to shows endpoints
1 parent cbdca14 commit 0416faa

File tree

2 files changed

+103
-23
lines changed

2 files changed

+103
-23
lines changed

__tests__/spotify-web-api.js

+97
Original file line numberDiff line numberDiff line change
@@ -4350,4 +4350,101 @@ describe('Spotify Web API', () => {
43504350
);
43514351
});
43524352

4353+
/* Search for an episode. */
4354+
test('should search for an episode', done => {
4355+
sinon.stub(HttpManager, '_makeRequest').callsFake(function(
4356+
method,
4357+
options,
4358+
uri,
4359+
callback
4360+
) {
4361+
expect(method).toBe(superagent.get);
4362+
expect(uri).toBe(
4363+
'https://api.spotify.com/v1/search/'
4364+
);
4365+
expect(options.query.q).toBe('hanif bali');
4366+
expect(options.query.type).toBe('episode');
4367+
expect(options.query.market).toBe('UK');
4368+
expect(options.query.limit).toBe(10);
4369+
expect(options.query.offset).toBe(11);
4370+
callback(null, {
4371+
body: {},
4372+
statusCode: 200
4373+
})
4374+
});
4375+
4376+
var api = new SpotifyWebApi();
4377+
4378+
api.searchEpisodes('hanif bali', { 'market' : 'UK', 'limit' : 10, 'offset': 11}).then(
4379+
function(data) {
4380+
done();
4381+
},
4382+
function(err) {
4383+
done(err);
4384+
}
4385+
);
4386+
});
4387+
4388+
/* Look up an episode. */
4389+
test('should look up an episode', done => {
4390+
sinon.stub(HttpManager, '_makeRequest').callsFake(function(
4391+
method,
4392+
options,
4393+
uri,
4394+
callback
4395+
) {
4396+
expect(method).toBe(superagent.get);
4397+
expect(uri).toBe(
4398+
'https://api.spotify.com/v1/episodes/3Qm86XLflmIXVm1wcwkgDK'
4399+
);
4400+
expect(options.query.market).toBe('NO');
4401+
callback(null, {
4402+
body: {},
4403+
statusCode: 200
4404+
})
4405+
});
4406+
4407+
var api = new SpotifyWebApi();
4408+
4409+
api.getEpisode('3Qm86XLflmIXVm1wcwkgDK', { 'market' : 'NO' }).then(
4410+
function(data) {
4411+
done();
4412+
},
4413+
function(err) {
4414+
done(err);
4415+
}
4416+
);
4417+
});
4418+
4419+
/* Look up several episodes */
4420+
test('should get several episodes', done => {
4421+
sinon.stub(HttpManager, '_makeRequest').callsFake(function(
4422+
method,
4423+
options,
4424+
uri,
4425+
callback
4426+
) {
4427+
expect(method).toBe(superagent.get);
4428+
expect(uri).toBe(
4429+
'https://api.spotify.com/v1/episodes'
4430+
);
4431+
expect(options.query.market).toBe('DK');
4432+
expect(options.query.ids).toBe('3Qm86XLflmIXVm1wcwkgDK,66m86XLflmIXVm1wcwkg66');
4433+
callback(null, {
4434+
statusCode: 200
4435+
})
4436+
});
4437+
4438+
var api = new SpotifyWebApi();
4439+
4440+
api.getEpisodes(['3Qm86XLflmIXVm1wcwkgDK', '66m86XLflmIXVm1wcwkg66'], { market: 'DK' }).then(
4441+
function(data) {
4442+
done();
4443+
},
4444+
function(err) {
4445+
done(err);
4446+
}
4447+
);
4448+
});
4449+
43534450
});

src/spotify-web-api.js

+6-23
Original file line numberDiff line numberDiff line change
@@ -1700,19 +1700,11 @@ SpotifyWebApi.prototype = {
17001700
* about the episode. Not returned if a callback is given.
17011701
*/
17021702
getEpisode: function(episodeId, options, callback) {
1703-
var actualCallback, actualOptions;
1704-
if (typeof options === 'function' && !callback) {
1705-
actualCallback = options;
1706-
actualOptions = {};
1707-
} else {
1708-
actualCallback = callback;
1709-
actualOptions = options;
1710-
}
17111703
return WebApiRequest.builder(this.getAccessToken())
1712-
.withPath('/v1/episodes/' + episodeId)
1713-
.withQueryParameters(actualOptions)
1714-
.build()
1715-
.execute(HttpManager.get, actualCallback);
1704+
.withPath('/v1/episodes/' + episodeId)
1705+
.withQueryParameters(options)
1706+
.build()
1707+
.execute(HttpManager.get, callback);
17161708
},
17171709

17181710
/**
@@ -1725,25 +1717,16 @@ SpotifyWebApi.prototype = {
17251717
* about the episodes. Not returned if a callback is given.
17261718
*/
17271719
getEpisodes: function(episodeIds, options, callback) {
1728-
// In case someone is using a version where options parameter did not exist.
1729-
var actualCallback, actualOptions;
1730-
if (typeof options === 'function' && !callback) {
1731-
actualCallback = options;
1732-
actualOptions = {};
1733-
} else {
1734-
actualCallback = callback;
1735-
actualOptions = options;
1736-
}
17371720
return WebApiRequest.builder(this.getAccessToken())
17381721
.withPath('/v1/episodes')
17391722
.withQueryParameters(
17401723
{
17411724
ids: episodeIds.join(',')
17421725
},
1743-
actualOptions
1726+
options
17441727
)
17451728
.build()
1746-
.execute(HttpManager.get, actualCallback);
1729+
.execute(HttpManager.get, callback);
17471730
},
17481731
};
17491732

0 commit comments

Comments
 (0)