Permalink
Browse files

added some search tests, minor fixes

  • Loading branch information...
1 parent c6820f7 commit 3ebf4a9bf3f93d64387c0123f0fc1509f6374421 @roncioso committed Jan 12, 2011
Showing with 36 additions and 18 deletions.
  1. +3 −3 lib/main.js
  2. +1 −1 package.json
  3. +32 −14 test/test.js
View
@@ -101,7 +101,7 @@ SpotifyMeta.prototype._singleSearch = function(q, type, cb){
uri: "http://ws.spotify.com/search/1/"+type+".json?q="+type+":"+q
}, function(e,r,b){
b = JSON.parse(b);
- cb(b[type+"s"]);
+ cb(e, b[type+"s"]);
});
}
@@ -119,11 +119,11 @@ SpotifyMeta.prototype.search = function(q, cb){
for(var i=0;i<fields.length;i++){
(function(f){
- self._singleSearch(q, f, function(result){
+ self._singleSearch(q, f, function(error, result){
results[f] = result;
count = ++count;
if(count==(fields.length)){
- cb(null, results);
+ cb(error, results);
}
});
View
@@ -1,7 +1,7 @@
{
"name": "spotify-metadata",
"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"],
"author": {
"name": "Luca Manno",
View
@@ -127,24 +127,42 @@ vows.describe('Spotify Metadata').addBatch({
},
'Search': {
- 'try search': {
+ 'global search for Nirvana': {
'topic': function(){
spotify.search("Nirvana", this.callback);
},
'is returned something': function(error, results){
- //assert.equal(results.length, 3);
- for(var i=0;i<results.track.length;i++){
- console.log(results.track[i])
- }
- /*
- assert.equal(results.artist, 100);
- assert.equal(results.album, 100);
- assert.equal(results.track, 100);*/
+ assert.equal(results.artist.length>0, true);
+ assert.equal(results.album.length>0, true);
+ assert.equal(results.track.length>0, true);
+ }
+ },
+ 'search album': {
+ 'topic': function(){
+ 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();
-/*
-spotify.searchAlbum("Nevermind", function(){console.log(arguments)});
-spotify.searchArtist("Nirvana", function(){console.log(arguments)});
-spotify.searchTrack("About a Girl", function(){console.log(arguments)});*/
+}).run();

0 comments on commit 3ebf4a9

Please sign in to comment.