-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathtest-066-link-from-objects.js
More file actions
61 lines (56 loc) · 2.59 KB
/
test-066-link-from-objects.js
File metadata and controls
61 lines (56 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var sp = require('../lib/libspotify');
var testutil = require('./util');
var session = null;
function testLink (Class, url) {
return function(test) {
var object = Class.getFromUrl(url);
object.whenReady(function() {
test.doesNotThrow(function() {
var link = object.getLink();
test.equal('string', typeof link, 'Link should be a string');
test.ok(object instanceof Class, "retrieved object should be an instance of the class");
test.equal(Class._object_type, sp.getLinkType(link), "Class and link should have the same type");
test.equal(link, url, "Retrieved link should be equal to the given url");
}, 'getting link from object should not throw');
test.done();
})
}
}
exports.links = {
setUp: function(cb) {
testutil.getDefaultTestSession(function(s) {
session = s;
cb();
});
},
"get link from track": testLink(sp.Track, 'spotify:track:4BdSLkzKO6iMVCgw7A7JBl'),
"get link from album": testLink(sp.Album, 'spotify:album:2UGJa9DjYhXpBDKsCTyhSh'),
"get link from artist": testLink(sp.Artist, 'spotify:artist:4ZCLbhEKI7019HKbk5RsUq'),
"get link from playlist": testLink(sp.Playlist, 'spotify:user:flobyiv:playlist:2t8yWR57SFWSKHtOlWr095'),
'get artist link from artist': function(test) {
var track = sp.Track.getFromUrl('spotify:track:2Uqs7Gi9F0BHg3H7yhbpWm');
track.on('ready', function() {
var artist = track.artist;
test.ok(artist instanceof sp.Artist, 'artist should be an instance of Artist');
test.equal('Guillemots', artist.name, 'this should be Guillemots');
test.equal(typeof artist.getUrl(), 'string', 'url should be a string');
test.done();
});
},
'get artist from link': function(test) {
var artist = sp.Artist.getFromUrl('spotify:artist:3zD5liDjbqljSRorrrcEjs');
test.ok(artist instanceof sp.Artist, 'the returned object should be an artist');
artist.on('ready', function() {
test.equal('Guillemots', artist.name, 'this should be the Guillemots artist');
test.done();
});
},
'get album from link': function(test) {
var album = sp.Album.getFromUrl('spotify:album:2UGJa9DjYhXpBDKsCTyhSh');
test.ok(album instanceof sp.Album, 'the returned object should be an album');
album.on('ready', function () {
test.equal('Exile (Deluxe)', album.name, 'this should be the Exile (Deluxe) album');
test.done();
});
}
};