Skip to content

Commit

Permalink
added some search tests, minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
roncioso committed Jan 12, 2011
1 parent c6820f7 commit 3ebf4a9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
6 changes: 3 additions & 3 deletions lib/main.js
Expand Up @@ -101,7 +101,7 @@ SpotifyMeta.prototype._singleSearch = function(q, type, cb){
uri: "http://ws.spotify.com/search/1/"+type+".json?q="+type+":"+q uri: "http://ws.spotify.com/search/1/"+type+".json?q="+type+":"+q
}, function(e,r,b){ }, function(e,r,b){
b = JSON.parse(b); b = JSON.parse(b);
cb(b[type+"s"]); cb(e, b[type+"s"]);
}); });
} }


Expand All @@ -119,11 +119,11 @@ SpotifyMeta.prototype.search = function(q, cb){


for(var i=0;i<fields.length;i++){ for(var i=0;i<fields.length;i++){
(function(f){ (function(f){
self._singleSearch(q, f, function(result){ self._singleSearch(q, f, function(error, result){
results[f] = result; results[f] = result;
count = ++count; count = ++count;
if(count==(fields.length)){ if(count==(fields.length)){
cb(null, results); cb(error, results);
} }
}); });


Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{ {
"name": "spotify-metadata", "name": "spotify-metadata",
"version": "0.0.1", "version": "0.0.1",
"description": "Spotify metadata lookup and search. Works with Spotify and http uris", "description": "Spotify api wrapper. Metadata lookup and search. Works with Spotify and http uris",
"keywords": ["spotify", "spotify metadata", "lookup", "search"], "keywords": ["spotify", "spotify metadata", "lookup", "search"],
"author": { "author": {
"name": "Luca Manno", "name": "Luca Manno",
Expand Down
46 changes: 32 additions & 14 deletions test/test.js
Expand Up @@ -127,24 +127,42 @@ vows.describe('Spotify Metadata').addBatch({
}, },


'Search': { 'Search': {
'try search': { 'global search for Nirvana': {
'topic': function(){ 'topic': function(){
spotify.search("Nirvana", this.callback); spotify.search("Nirvana", this.callback);
}, },
'is returned something': function(error, results){ 'is returned something': function(error, results){
//assert.equal(results.length, 3); assert.equal(results.artist.length>0, true);
for(var i=0;i<results.track.length;i++){ assert.equal(results.album.length>0, true);
console.log(results.track[i]) assert.equal(results.track.length>0, true);
} }
/* },
assert.equal(results.artist, 100); 'search album': {
assert.equal(results.album, 100); 'topic': function(){
assert.equal(results.track, 100);*/ spotify.searchAlbum("Nevermind", this.callback);
},
'check artist': function(e, res){
assert.equal(res[0].artists[0].name, "Nirvana");
}
},
'search track': {
'topic': function(){
spotify.searchTrack("About a Girl", this.callback);
},
'check artist': function(e, res){
assert.equal(res[0].artists[0].name, "Nirvana");
},
'check album': function(e, res){
assert.equal(typeof res[0].album.name, typeof "Nirvana");
}
},
'search artist': {
'topic': function(){
spotify.searchArtist("Nirvana", this.callback);
},
'check name': function(e, res){
assert.equal(res[0].name, "Nirvana");
} }
} }
} }
}).run(); }).run();
/*
spotify.searchAlbum("Nevermind", function(){console.log(arguments)});
spotify.searchArtist("Nirvana", function(){console.log(arguments)});
spotify.searchTrack("About a Girl", function(){console.log(arguments)});*/

0 comments on commit 3ebf4a9

Please sign in to comment.