From 84dfc5de2c26916299eae481b2657061c4f85e9f Mon Sep 17 00:00:00 2001 From: Salvatore Iovene Date: Fri, 25 Jan 2013 10:56:39 +0200 Subject: [PATCH] (hoofbeats) Adds test for 'artist not found'. --- examples/hoofbeats/javascripts/musicbrainz.js | 21 +++++++++++++++------ examples/hoofbeats/tests/unit/musicbrainz.js | 11 +++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/examples/hoofbeats/javascripts/musicbrainz.js b/examples/hoofbeats/javascripts/musicbrainz.js index f0ae5cc..def9b07 100644 --- a/examples/hoofbeats/javascripts/musicbrainz.js +++ b/examples/hoofbeats/javascripts/musicbrainz.js @@ -6,15 +6,24 @@ $(function() { this.getArtist = function(q) { var self = this, - lookup_url = self.baseUrl + 'artist/?query=' + q + '&' + self.fmtArg; + lookup_url = self.baseUrl + 'artist/?query="' + q + '"&' + self.fmtArg; deferred = new $.Deferred(); - $.getJSON(lookup_url).done(function(data) { - artist_url = self.baseUrl + 'artist/' + data.artist[0].id + '?' + self.fmtArg; - $.getJSON(artist_url).done(function(data) { - deferred.resolve(data); + if (q !== undefined) { + $.getJSON(lookup_url).done(function(data) { + if (data.count > 0) { + artist_url = self.baseUrl + 'artist/' + data.artist[0].id + '?' + self.fmtArg; + $.getJSON(artist_url).done(function(data) { + deferred.resolve(data); + }); + } else { + deferred.reject(); + } }); - }); + } else { + deferred.reject(); + } + return deferred.promise(); }; } diff --git a/examples/hoofbeats/tests/unit/musicbrainz.js b/examples/hoofbeats/tests/unit/musicbrainz.js index ddc8322..b7853e6 100644 --- a/examples/hoofbeats/tests/unit/musicbrainz.js +++ b/examples/hoofbeats/tests/unit/musicbrainz.js @@ -17,4 +17,15 @@ $(function() { start(); }); }); + + test("get artist data, artist not found", + function() { + var name = "This artist does not exist"; + var promise = MusicBrainz.getArtist(name); + stop(); + promise.fail(function() { + equals(1, 1, "the method failed"); + start(); + }); + }); }); -- 2.7.4