Skip to content

Commit cbdca14

Browse files
committed
Add more tests for shows endpoints
1 parent d9ef8cf commit cbdca14

File tree

2 files changed

+136
-29
lines changed

2 files changed

+136
-29
lines changed

__tests__/spotify-web-api.js

+132-16
Original file line numberDiff line numberDiff line change
@@ -4189,7 +4189,7 @@ describe('Spotify Web API', () => {
41894189
* Shows
41904190
*/
41914191

4192-
/* Get a Show */
4192+
/* Get a Show */
41934193
test('should get a show', done => {
41944194
sinon.stub(HttpManager, '_makeRequest').callsFake(function(
41954195
method,
@@ -4204,19 +4204,6 @@ describe('Spotify Web API', () => {
42044204
expect(options.query.market).toBe('SE');
42054205

42064206
callback(null, {
4207-
body: {
4208-
total_episodes : 3,
4209-
type : "show",
4210-
name : "The API show",
4211-
episodes : [{
4212-
items : [
4213-
{
4214-
"audio_preview_url" : "https://p.scdn.co/mp3-preview/7a785904a33e34b0b2bd382c82fca16be7060c36",
4215-
"duration_ms" : 2677448
4216-
}
4217-
]
4218-
}]
4219-
},
42204207
statusCode: 200
42214208
})
42224209
});
@@ -4225,13 +4212,142 @@ describe('Spotify Web API', () => {
42254212

42264213
api.getShow('123', { market: 'SE' }).then(
42274214
function(data) {
4228-
expect(data.body.total_episodes).toBe(3);
4229-
expect(data.body.episodes[0].items[0].duration_ms).toBe(2677448);
42304215
done();
42314216
},
42324217
function(err) {
42334218
done(err);
42344219
}
42354220
);
42364221
});
4222+
4223+
/* Look up several shows */
4224+
test('should get several shows', done => {
4225+
sinon.stub(HttpManager, '_makeRequest').callsFake(function(
4226+
method,
4227+
options,
4228+
uri,
4229+
callback
4230+
) {
4231+
expect(method).toBe(superagent.get);
4232+
expect(uri).toBe(
4233+
'https://api.spotify.com/v1/shows'
4234+
);
4235+
expect(options.query.market).toBe('SE');
4236+
expect(options.query.ids).toBe('1,2,3');
4237+
callback(null, {
4238+
statusCode: 200
4239+
})
4240+
});
4241+
4242+
var api = new SpotifyWebApi();
4243+
4244+
api.getShows(['1', '2', '3'], { market: 'SE' }).then(
4245+
function(data) {
4246+
done();
4247+
},
4248+
function(err) {
4249+
done(err);
4250+
}
4251+
);
4252+
});
4253+
4254+
/* Check if one or more shows is already saved in the current Spotify user’s “Your Music” library. */
4255+
test('should see that show is already saved by user', done => {
4256+
sinon.stub(HttpManager, '_makeRequest').callsFake(function(
4257+
method,
4258+
options,
4259+
uri,
4260+
callback
4261+
) {
4262+
expect(method).toBe(superagent.get);
4263+
expect(uri).toBe(
4264+
'https://api.spotify.com/v1/me/shows/contains'
4265+
);
4266+
expect(options.query.ids).toBe('1,2,3');
4267+
callback(null, {
4268+
body: [ true, false, false ],
4269+
statusCode: 200
4270+
})
4271+
});
4272+
4273+
var api = new SpotifyWebApi();
4274+
4275+
api.containsMySavedShows(['1', '2', '3']).then(
4276+
function(data) {
4277+
done();
4278+
},
4279+
function(err) {
4280+
done(err);
4281+
}
4282+
);
4283+
});
4284+
4285+
/* Get the episodes of an show. */
4286+
test('should retrieve the episodes of a show', done => {
4287+
sinon.stub(HttpManager, '_makeRequest').callsFake(function(
4288+
method,
4289+
options,
4290+
uri,
4291+
callback
4292+
) {
4293+
expect(method).toBe(superagent.get);
4294+
expect(uri).toBe(
4295+
'https://api.spotify.com/v1/shows/123/episodes'
4296+
);
4297+
expect(options.query.market).toBe('SE');
4298+
expect(options.query.limit).toBe(1);
4299+
expect(options.query.offset).toBe(2);
4300+
callback(null, {
4301+
body: {},
4302+
statusCode: 200
4303+
})
4304+
});
4305+
4306+
var api = new SpotifyWebApi();
4307+
4308+
api.getShowEpisodes('123', { 'market' : 'SE', 'limit' : 1, 'offset': 2}).then(
4309+
function(data) {
4310+
done();
4311+
},
4312+
function(err) {
4313+
done(err);
4314+
}
4315+
);
4316+
});
4317+
4318+
/* Search for a show. */
4319+
test('should search for a show', done => {
4320+
sinon.stub(HttpManager, '_makeRequest').callsFake(function(
4321+
method,
4322+
options,
4323+
uri,
4324+
callback
4325+
) {
4326+
expect(method).toBe(superagent.get);
4327+
expect(uri).toBe(
4328+
'https://api.spotify.com/v1/search/'
4329+
);
4330+
expect(options.query.q).toBe('kvartal');
4331+
expect(options.query.type).toBe('show');
4332+
expect(options.query.market).toBe('SE');
4333+
expect(options.query.limit).toBe(3);
4334+
expect(options.query.offset).toBe(1);
4335+
callback(null, {
4336+
body: {},
4337+
statusCode: 200
4338+
})
4339+
});
4340+
4341+
var api = new SpotifyWebApi();
4342+
4343+
api.searchShows('kvartal', { 'market' : 'SE', 'limit' : 3, 'offset': 1}).then(
4344+
function(data) {
4345+
done();
4346+
},
4347+
function(err) {
4348+
done(err);
4349+
}
4350+
);
4351+
});
4352+
42374353
});

src/spotify-web-api.js

+4-13
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ SpotifyWebApi.prototype = {
261261
* Search for music entities of certain types.
262262
* @param {string} query The search query.
263263
* @param {string[]} types An array of item types to search across.
264-
* Valid types are: 'album', 'artist', 'playlist', and 'track'.
264+
* Valid types are: 'album', 'artist', 'playlist', 'track', 'show', and 'episode'.
265265
* @param {Object} [options] The possible options, e.g. limit, offset.
266266
* @param {requestCallback} [callback] Optional callback method to be called instead of the promise.
267267
* @example search('Abba', ['track', 'playlist'], { limit : 5, offset : 1 }).then(...)
@@ -1567,25 +1567,16 @@ SpotifyWebApi.prototype = {
15671567
* about the shows. Not returned if a callback is given.
15681568
*/
15691569
getShows: function(showIds, options, callback) {
1570-
// In case someone is using a version where options parameter did not exist.
1571-
var actualCallback, actualOptions;
1572-
if (typeof options === 'function' && !callback) {
1573-
actualCallback = options;
1574-
actualOptions = {};
1575-
} else {
1576-
actualCallback = callback;
1577-
actualOptions = options;
1578-
}
15791570
return WebApiRequest.builder(this.getAccessToken())
15801571
.withPath('/v1/shows')
15811572
.withQueryParameters(
15821573
{
15831574
ids: showIds.join(',')
15841575
},
1585-
actualOptions
1576+
options
15861577
)
15871578
.build()
1588-
.execute(HttpManager.get, actualCallback);
1579+
.execute(HttpManager.get, callback);
15891580
},
15901581

15911582
/**
@@ -1656,7 +1647,7 @@ SpotifyWebApi.prototype = {
16561647
/**
16571648
* Get the episodes of an show.
16581649
* @param showId the show's ID.
1659-
* @options {Object} [options] The possible options, e.g. limit.
1650+
* @options {Object} [options] The possible options, being limit, offset, and market.
16601651
* @param {requestCallback} [callback] Optional callback method to be called instead of the promise.
16611652
* @example getShowEpisodes('41MnTivkwTO3UUJ8DrqEJJ', { limit : 5, offset : 1 }).then(...)
16621653
* @returns {Promise|undefined} A promise that if successful, returns an object containing the

0 commit comments

Comments
 (0)