@kkbox/kkbox-js-sdk
Version:
KKBOX Open API developer SDK for JavaScript. Use it to easily access KKBOX open API to get various metadata about KKBOX's tracks, albums, artists, playlists and stations.
506 lines (480 loc) • 23.4 kB
JavaScript
;
var _should = _interopRequireDefault(require("should"));
var _HttpClient = _interopRequireDefault(require("../api/HttpClient"));
var _SearchFetcher = _interopRequireDefault(require("../api/SearchFetcher"));
var _AlbumFetcher = _interopRequireDefault(require("../api/AlbumFetcher"));
var _ArtistFetcher = _interopRequireDefault(require("../api/ArtistFetcher"));
var _FeaturedPlaylistFetcher = _interopRequireDefault(require("../api/FeaturedPlaylistFetcher"));
var _FeaturedPlaylistCategoryFetcher = _interopRequireDefault(require("../api/FeaturedPlaylistCategoryFetcher"));
var _NewReleaseCategoryFetcher = _interopRequireDefault(require("../api/NewReleaseCategoryFetcher"));
var _NewHitsPlaylistFetcher = _interopRequireDefault(require("../api/NewHitsPlaylistFetcher"));
var _SharedPlaylistFetcher = _interopRequireDefault(require("../api/SharedPlaylistFetcher"));
var _MoodStationFetcher = _interopRequireDefault(require("../api/MoodStationFetcher"));
var _GenreStationFetcher = _interopRequireDefault(require("../api/GenreStationFetcher"));
var _ChartFetcher = _interopRequireDefault(require("../api/ChartFetcher"));
var _TrackFetcher = _interopRequireDefault(require("../api/TrackFetcher"));
var _TokenFetcher = _interopRequireDefault(require("../auth/TokenFetcher"));
var _ClientCredentialsFlow = _interopRequireDefault(require("../auth/ClientCredentialsFlow"));
var _client_secrets = require("../../client_secrets.json");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
var CLIENT_ID = _client_secrets.kkbox_sdk.client_id;
var CLIENT_SECRET = _client_secrets.kkbox_sdk.client_secret;
describe('Api Begin to Test', function () {
describe('ClientCredentials', function () {
describe('#fetch the access token()', function () {
it('should fetch access token', function () {
var tokenFetcher = new _TokenFetcher["default"](CLIENT_ID, CLIENT_SECRET);
var clientCredentials = new _ClientCredentialsFlow["default"](tokenFetcher);
return clientCredentials.fetchAccessToken().then(function (response) {
var access_token = response.data.access_token;
access_token.should.be.ok;
var httpClient = new _HttpClient["default"](access_token);
describe('Search', function () {
var searchFetcher = new _SearchFetcher["default"](httpClient).setSearchCriteria('Linkin Park');
describe('#fetchSearchResult()', function () {
it('should response status 200', function () {
return searchFetcher.fetchSearchResult().then(function (response) {
response.status.should.be.exactly(200), function (reject) {
return _should["default"].not.exists(reject);
};
});
});
});
describe('#filter()', function () {
it('should get result', function () {
return searchFetcher.filter({
artist: 'Linkin Park',
album: 'One More Light',
available_territory: 'TW'
}).fetchSearchResult().then(function (response) {
response.data.tracks.data.length.should.be.greaterThan(0);
});
});
});
});
describe('Track', function () {
var track_id = 'KpnEGVHEsGgkoB0MBk';
var trackFetcher = new _TrackFetcher["default"](httpClient).setTrackID(track_id);
it('should response status 200', function () {
return trackFetcher.fetchMetadata().then(function (response) {
return response.status.should.be.exactly(200);
}, function (reject) {
return _should["default"].not.exists(reject);
});
});
describe('#getWidgetUri', function () {
it('should return right uri', function (doneCb) {
trackFetcher.getWidgetUri().should.be.exactly("https://widget.kkbox.com/v1/?id=".concat(track_id, "&type=song"));
doneCb();
});
});
});
describe('Album', function () {
var album_id = 'KmRKnW5qmUrTnGRuxF';
var albumFetcher = new _AlbumFetcher["default"](httpClient).setAlbumID(album_id);
describe('#fetchMetadata()', function () {
it('should response status 200', function () {
return albumFetcher.fetchMetadata().then(function (response) {
response.status.should.be.exactly(200);
}, function (reject) {
_should["default"].not.exist(reject);
});
});
});
describe('#fetchTracks()', function () {
var fulfillment = undefined;
it('should response status 200', function () {
return albumFetcher.fetchTracks().then(function (response) {
response.status.should.be.exactly(200);
fulfillment = response;
}, function (reject) {
_should["default"].not.exist(reject);
});
});
it('fetch next page should fail', function () {
return albumFetcher.fetchNextPage(fulfillment).then(function (response) {
throw new Error('Should not get response');
}, function (reject) {
_should["default"].exist(reject);
});
});
it('should not have next page', function (done) {
albumFetcher.hasNextPage(fulfillment).should.be["false"];
done();
});
});
describe('#getWidgetUri', function () {
it('should return right uri', function (done) {
albumFetcher.getWidgetUri().should.be.exactly("https://widget.kkbox.com/v1/?id=".concat(album_id, "&type=album"));
done();
});
});
});
describe('Album fetch next tracks', function () {
var album_id = 'Ks8MAYNedkIB_sGajW'; // Cosmic Explorer from Perfume
var albumFetcher = new _AlbumFetcher["default"](httpClient).setAlbumID(album_id);
describe('#fetchTracks(1)', function () {
it('should succeed and should fetch next page succeed', function (done) {
albumFetcher.fetchTracks(1).then(function (response) {
response.status.should.be.exactly(200);
albumFetcher.fetchNextPage(response).then(function (response) {
response.data.data.should.be.an.instanceOf(Array);
response.data.data.length.should.be.equal(1);
response.status.should.be.exactly(200);
done();
}, function (reject) {
done(reject);
});
}, function (reject) {
done(reject);
});
});
});
});
describe('Album fetch next page', function () {
var album_id = 'Ks8MAYNedkIB_sGajW'; // Cosmic Explorer from Perfume
var albumFetcher = new _AlbumFetcher["default"](httpClient).setAlbumID(album_id);
it('fetch next page should response status 200', function () {
return albumFetcher.fetchTracks(1).then(function (response) {
response.status.should.be.exactly(200);
albumFetcher.fetchNextPage(response).then(function (response) {
response.status.should.be.exactly(200);
}, function (reject) {
_should["default"].not.exists(reject);
});
}, function (reject) {
_should["default"].not.exists(reject);
});
});
});
describe('Shared Playlists', function () {
var playlist_id = '4nUZM-TY2aVxZ2xaA-';
var sharedPlaylistFetcher = new _SharedPlaylistFetcher["default"](httpClient).setPlaylistID(playlist_id);
describe('#find and get()', function () {
it('should response status 200', function (done) {
sharedPlaylistFetcher.fetchMetadata().then(function (response) {
response.status.should.be.exactly(200);
done();
})["catch"](function (error) {
_should["default"].not.exists(error);
done(error);
});
});
});
describe('#tracks()', function () {
it('should response status 200', function (done) {
sharedPlaylistFetcher.fetchTracks().then(function (response) {
response.status.should.be.exactly(200);
done();
}, function (reject) {
done(reject);
});
});
});
describe('#getWidgetUri', function () {
it('should return right uri', function (done) {
sharedPlaylistFetcher.getWidgetUri().should.be.exactly("https://widget.kkbox.com/v1/?id=".concat(playlist_id, "&type=playlist"));
done();
});
});
});
describe('Artist', function () {
var artistFetcher = new _ArtistFetcher["default"](httpClient).setArtistID('Cnv_K6i5Ft4y41SxLy');
describe('#fetchMetadata()', function () {
it('should response status 200', function () {
return artistFetcher.fetchMetadata().then(function (response) {
response.status.should.be.exactly(200);
return response;
})["catch"](function (error) {
return _should["default"].not.exists(error);
});
});
});
describe('#fetchAlbums()', function () {
it('should succeed and fetch next page should fail', function () {
return artistFetcher.fetchAlbums().then(function (response) {
response.status.should.be.exactly(200);
artistFetcher.fetchNextPage(response).then(function (response) {
response.status.should.not.be.exactly(200);
return response;
})["catch"](function (error) {
return _should["default"].exists(error);
});
return response;
})["catch"](function (error) {
return _should["default"].not.exists(error);
});
});
});
describe('#fetchTopTracks()', function () {
it('should response status 200', function (done) {
artistFetcher.fetchTopTracks().then(function (response) {
response.status.should.be.exactly(200);
done();
}, function (reject) {
_should["default"].not.exists(reject);
done();
});
});
});
describe('#fetchRelatedArtists()', function () {
it('should response status 200', function (done) {
artistFetcher.fetchRelatedArtists().then(function (response) {
response.status.should.be.exactly(200);
done();
}, function (reject) {
_should["default"].not.exists(reject);
done();
});
});
});
});
describe('Artist fetch album tests', function () {
var artistFetcher = new _ArtistFetcher["default"](httpClient).setArtistID('Cnv_K6i5Ft4y41SxLy');
describe('#fetchAlbums(1)', function () {
it('should succeed and fetch next page shuold succeed', function (done) {
artistFetcher.fetchAlbums(1).then(function (response) {
response.status.should.be.exactly(200);
artistFetcher.fetchNextPage(response).then(function (response) {
response.status.should.be.exactly(200);
done();
}, function (reject) {
done(reject);
});
});
});
});
describe('#fetchTopTracks(1)', function () {
it('should succeed and fetch next page shuold succeed', function (done) {
artistFetcher.fetchTopTracks(1).then(function (response) {
response.status.should.be.exactly(200);
artistFetcher.fetchNextPage(response).then(function (response) {
response.status.should.be.exactly(200);
done();
}, function (reject) {
done(reject);
});
});
});
});
});
describe('Featured Playlists', function () {
var featuredPlaylistFetcher = new _FeaturedPlaylistFetcher["default"](httpClient);
describe('#fetchAllFeaturedPlaylists()', function () {
it('should response status 200', function (done) {
featuredPlaylistFetcher.fetchAllFeaturedPlaylists(1).then(function (response) {
response.status.should.be.exactly(200);
featuredPlaylistFetcher.fetchNextPage(response).then(function (response) {
response.status.should.be.exactly(200);
done();
}, function (reject) {
done(reject);
});
});
});
});
});
describe('Featured Playlist Category', function () {
var featuredPlaylistCategoryFetcher = new _FeaturedPlaylistCategoryFetcher["default"](httpClient);
describe('#fetchAll()', function () {
it('should response status 200', function () {
return featuredPlaylistCategoryFetcher.fetchAllFeaturedPlaylistCategories().then(function (response) {
return response.status.should.be.exactly(200);
}, function (reject) {
return _should["default"].not.exists(reject);
});
});
});
var f = featuredPlaylistCategoryFetcher.setCategoryID('LXUR688EBKRRZydAWb');
describe('#fetchMetadata()', function () {
it('should response status 200', function () {
return f.fetchMetadata().then(function (response) {
return response.status.should.be.exactly(200);
}, function (reject) {
return _should["default"].not.exists(reject);
});
});
});
describe('#fetchPlaylists()', function () {
it('should response status 200 and fetch next page should succeed', function (done) {
f.fetchPlaylists().then(function (response) {
response.status.should.be.exactly(200);
f.fetchNextPage(response).then(function (response) {
response.status.should.be.exactly(200);
done();
}, function (reject) {
done(reject);
});
});
});
});
});
describe('Mood Station', function () {
var moodStationFetcher = new _MoodStationFetcher["default"](httpClient);
describe('#fetchAll()', function () {
it('should succeed', function () {
return moodStationFetcher.fetchAllMoodStations().then(function (response) {
return response.status.should.be.exactly(200);
}, function (reject) {
return _should["default"].not.exists(reject);
});
});
});
describe('#fetchMetadata()', function () {
it('should succeed', function () {
return moodStationFetcher.setMoodStationID('StGZp2ToWq92diPHS7').fetchMetadata().then(function (response) {
return response.status.should.be.exactly(200);
}, function (reject) {
return _should["default"].not.exists(reject);
});
});
});
});
describe('Genre Station', function () {
var genreStationFetcher = new _GenreStationFetcher["default"](httpClient);
describe('#fetchAllGenreStations()', function () {
it('should succeed and fetch next page should succeed', function (done) {
genreStationFetcher.fetchAllGenreStations(1).then(function (response) {
response.status.should.be.exactly(200);
genreStationFetcher.fetchNextPage(response).then(function (response) {
response.status.should.be.exactly(200);
done();
}, function (reject) {
done(reject);
});
});
});
});
describe('#fetchMetadata()', function () {
it('should succeed', function () {
return genreStationFetcher.setGenreStationID('TYq3EHFTl-1EOvJM5Y').fetchMetadata().then(function (response) {
return response.status.should.be.exactly(200);
}, function (reject) {
return _should["default"].not.exists(reject);
});
});
});
});
describe('Chart', function () {
var chartFetcher = new _ChartFetcher["default"](httpClient);
describe('#fetchCharts()', function () {
it('should succeed and fetch next page should fail', function (done) {
chartFetcher.fetchCharts().then(function (response) {
response.status.should.be.exactly(200);
chartFetcher.hasNextPage(response).should.be["false"]();
chartFetcher.fetchNextPage(response).then(function (response) {
response.should.not.exists();
done(response);
}, function (reject) {
done();
});
});
});
});
describe('#fetchMetadata()', function () {
it('should succeed', function (done) {
chartFetcher.setPlaylistID('4mJSYXvueA8t0odsny').fetchMetadata().then(function (response) {
response.status.should.be.exactly(200);
done();
}, function (reject) {
_should["default"].not.exists(reject);
done();
});
});
});
describe('#fetchTracks()', function () {
it('should succeed', function (done) {
chartFetcher.setPlaylistID('4mJSYXvueA8t0odsny').fetchTracks().then(function (response) {
response.status.should.be.exactly(200);
done();
}, function (reject) {
_should["default"].not.exists(reject);
done();
});
});
});
});
describe('New Release Category', function () {
var newReleaseCategoryFetcher = new _NewReleaseCategoryFetcher["default"](httpClient);
describe('#fetchAll()', function () {
it('should succeed and fetch next page should succeed', function (done) {
newReleaseCategoryFetcher.fetchAllNewReleaseCategories(1).then(function (response) {
response.status.should.be.exactly(200);
newReleaseCategoryFetcher.hasNextPage(response).should.be["true"]();
newReleaseCategoryFetcher.fetchNextPage(response).then(function (response) {
response.status.should.be.ok();
done();
}, function (reject) {
done(reject);
});
}, function (reject) {
return _should["default"].not.exists(reject);
});
});
});
var f = newReleaseCategoryFetcher.setCategoryID('Cng5IUIQhxb8w1cbsz');
describe('#fetchMetadata()', function () {
it('should response status 200', function () {
return f.fetchMetadata().then(function (response) {
return response.status.should.be.exactly(200);
}, function (reject) {
return _should["default"].not.exists(reject);
});
});
});
describe('#fetchAlbums()', function () {
it('should response status 200 and fetch next page should succeed', function (done) {
f.fetchAlbums().then(function (response) {
response.status.should.be.exactly(200);
f.fetchNextPage(response).then(function (response) {
response.status.should.be.exactly(200);
done();
}, function (reject) {
done(reject);
});
});
});
});
});
describe('New Hits Playlists', function () {
var newHitsPlaylistFetcher = new _NewHitsPlaylistFetcher["default"](httpClient);
describe('#fetchAll()', function () {
it('should succeed', function () {
newHitsPlaylistFetcher.fetchAllNewHitsPlaylists().then(function (response) {
response.status.should.be.exactly(200);
})["catch"](function (error) {
return _should["default"].not.exists(error);
});
});
});
var f = newHitsPlaylistFetcher.setPlaylistID('DZni8m29ciOFbRxTJq');
describe('#fetchMetadata()', function () {
it('should succeed', function () {
return f.fetchMetadata().then(function (response) {
return response.status.should.be.exactly(200);
}, function (reject) {
return _should["default"].not.exists(reject);
})["catch"](function (error) {
return _should["default"].not.exsits(error);
});
});
});
describe('#fetchTracks()', function () {
it('should succeed', function () {
return f.fetchTracks().then(function (response) {
return response.status.should.be.exactly(200);
}, function (reject) {
return _should["default"].not.exists(reject);
})["catch"](function (error) {
return _should["default"].not.exsits(error);
});
});
});
});
}, function (reject) {
return _should["default"].not.exists(reject);
});
});
});
});
});