From e178265b63ba9b389038a6ef85acc29271eb4512 Mon Sep 17 00:00:00 2001 From: Mark Dalgleish Date: Wed, 25 Jul 2012 17:07:00 +1000 Subject: [PATCH] Return an error if page format is invalid --- lib/lanyrd-scraper.js | 5 +++++ test/lanyrd-scraper_test.js | 7 +++++++ test/mock-pages/invalid-page.html | 5 +++++ 3 files changed, 17 insertions(+) create mode 100644 test/mock-pages/invalid-page.html diff --git a/lib/lanyrd-scraper.js b/lib/lanyrd-scraper.js index 2321c31..478196b 100644 --- a/lib/lanyrd-scraper.js +++ b/lib/lanyrd-scraper.js @@ -20,6 +20,11 @@ exports.scrape = function(url, callback) { return; } + if ($('h1.summary').length === 0) { + callback(new Error('Invalid page format'), null); + return; + } + helper.setContext($); var data = {}; diff --git a/test/lanyrd-scraper_test.js b/test/lanyrd-scraper_test.js index 8709d51..df2366a 100644 --- a/test/lanyrd-scraper_test.js +++ b/test/lanyrd-scraper_test.js @@ -46,6 +46,13 @@ exports['multi-day event'] = { done(); }); }, + 'returns an error if page content is invalid': function(test) { + test.expect(1); + lanyrd.scrape('http://localhost:' + PORT + '/invalid-page.html', function(err, res){ + test.equal(err.message, 'Invalid page format'); + test.done(); + }); + }, 'has title': function(test) { test.expect(1); test.equal(multiDayEventData.title, 'Web Directions Code'); diff --git a/test/mock-pages/invalid-page.html b/test/mock-pages/invalid-page.html new file mode 100644 index 0000000..5469aa6 --- /dev/null +++ b/test/mock-pages/invalid-page.html @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file