Skip to content

Commit

Permalink
Implemented test for all methods using URLs as an argument.
Browse files Browse the repository at this point in the history
  • Loading branch information
framingeinstein committed Jan 31, 2013
1 parent 96d22d1 commit 7cc00c5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 188 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ AlchemyAPI.prototype._doRequest = function(request_query, cb) {
//console.log(request_query.nice);

//var server = http.createClient(80, this.config.api_url);
//console.log(JSON.stringify(request_query.nice));
//console.log(request_query.nice.path);
var req = http.request(request_query.nice, function(res) {
var data = [];
res
Expand Down Expand Up @@ -316,7 +316,7 @@ AlchemyAPI.prototype.text = function(data, options, cb) {
*/
AlchemyAPI.prototype.scrape = function(data, options, cb) {
if (!this._urlCheck(data) && !this._htmlCheck(data)) {
cb(new Error('The scrape method can only be used a URL or HTML encoded text. Plain text is not supported.'), null);
cb(new Error('The scrape method can only use a URL or HTML encoded text. Plain text is not supported.'), null);
return;
}
this._doRequest(this._getQuery(data, options, "GetConstraintQuery"), cb);
Expand Down
215 changes: 29 additions & 186 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
var Alchemy = require('../');

var testURL = "http://www.nytimes.com/";
var testURL = "https://github.com/framingeinstein/node-alchemy";
var testRSSURL = "http://www.cnn.com/services/rss/";

var testHTML = '<html><head><title>Alchemy Test HTML</title><meta name="author" content="Jason Morgan" /></head><body><h1>Alchemy Test HTML</h1><p>This is something I am writing about. I have to write this as I do not feel like getting it from the web. So here it is. A bunch of text to test the API with</p><div class="geo">GEO: <span class="latitude">37.386013</span>, <span class="longitude">-122.082932</span></div></body></html>';

var testText ="This is something I am writing about. I have to write this as I do not feel like getting it from the web. So here it is. A bunch of text to test the API with";
//fcb11f5cebca4850ae9771ed0678ae4222d5733e
var apikey = "fcb11f5cebca4850ae9771ed0678ae4222d5733e";

module.exports = {

'check html match': function(test) {
var alchemy = new Alchemy(apikey);
var result = alchemy._htmlCheck(testHTML);
test.deepEqual(result, true);
test.done();

},

'get sentiment from URL': function(test) {
'get sentiment': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.sentiment(testURL, {}, function(error, result) {
test.ifError(error);
Expand All @@ -27,251 +24,97 @@ module.exports = {
test.done();
});
},

'get relations from URL': function(test) {
'get relations': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.relations(testURL, {sentiment: 1}, function(error, result) {
console.log(result);
//console.log(result);
test.ifError(error);
//test.deepEqual(result.status, "OK");
test.done();
});
}/*,
'get concepts from URL': function(test) {
},
'get concepts': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.concepts(testURL, {}, function(error, result) {

test.ifError(error);
//test.deepEqual(result.status, "OK");
test.done();
});
},
'get entities from URL': function(test) {
'get entities': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.entities(testURL, {}, function(error, result) {

test.ifError(error);
//test.deepEqual(result.status, "OK");
test.done();
});
},
'get keywords from URL': function(test) {
},
'get keywords': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.keywords(testURL, {}, function(error, result) {

test.ifError(error);
//test.deepEqual(result.status, "OK");
test.done();
});
},
'get category from URL': function(test) {
'get category': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.category(testURL, {}, function(error, result) {
//console.log(result);
test.ifError(error);
//test.deepEqual(result.status, "OK");
test.done();
});
},
'get language from URL': function(test) {
'get language': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.language(testURL, {}, function(error, result) {
// console.log(result);
test.ifError(error);
//test.deepEqual(result.status, "OK");
test.done();
});
},
'get author from URL': function(test) {
'get author': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.author(testURL, {}, function(error, result) {
//console.log(result);
test.ifError(error);
test.deepEqual(result.status, "OK");
//test.deepEqual(result.status, "OK");
test.done();
});
},
'scrape text from URL': function(test) {
'scrape text': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.scrape(testURL, {}, function(error, result) {
alchemy.scrape(testURL, {cquery:"all readme"}, function(error, result) {
//console.log(result);
test.ifError(error);
//test.deepEqual(result.status, "OK");
test.deepEqual(result.status, "OK");
test.done();
});
},
//Tests for HTML content post to Alchemy
'get sentiment from HTML': function(test) {
'get microformats': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.sentiment(testHTML, {}, function(error, result) {
test.ifError(error);
alchemy.microformats(testURL, {}, function(error, result) {
//console.log(result);
//test.deepEqual(result.status, "OK");
test.done();
});
},
'get relations from HTML': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.relations(testHTML, {}, function(error, result) {
test.ifError(error);
//test.deepEqual(result.status, "OK");
test.done();
});
},
'get concepts from HTML': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.concepts(testHTML, {}, function(error, result) {
test.ifError(error);
//test.deepEqual(result.status, "OK");
test.done();
});
},
'get entities from HTML': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.entities(testHTML, {}, function(error, result) {
test.ifError(error);
//test.deepEqual(result.status, "OK");
test.done();
});
},
'get keywords from HTML': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.keywords(testHTML, {}, function(error, result) {
test.ifError(error);
test.deepEqual(result.status, "OK");
//test.deepEqual(result.status, "OK");
test.done();
});
},
'get category from HTML': function(test) {
'get feeds': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.category(testHTML, {}, function(error, result) {
test.ifError(error);
//test.deepEqual(result.status, "OK");
test.done();
});
},
'get language from HTML': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.language(testHTML, {}, function(error, result) {
test.ifError(error);
//test.deepEqual(result.status, "OK");
test.done();
});
},
'get author from HTML': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.author(testHTML, {}, function(error, result) {
//console.log(result);
test.ifError(error);
//test.deepEqual(result.status, "OK");
test.done();
});
},
'scrape text from HTML': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.scrape(testHTML, {}, function(error, result) {
alchemy.feeds(testRSSURL, {}, function(error, result) {
//console.log(result);
test.ifError(error);
test.deepEqual(result.status, "OK");
//test.deepEqual(result.status, "OK");
test.done();
});
},
//Tests for HTML content post to Alchemy
'get sentiment from Text': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.sentiment(testText, {}, function(error, result) {
test.ifError(error);
//console.log(result);
//test.deepEqual(result.status, "OK");
test.done();
});
},
'get relations from Text': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.relations(testText, {}, function(error, result) {
test.ifError(error);
//test.deepEqual(result.status, "OK");
test.done();
});
},
'get concepts from Text': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.concepts(testText, {}, function(error, result) {
test.ifError(error);
//test.deepEqual(result.status, "OK");
test.done();
});
},
'get entities from Text': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.entities(testText, {}, function(error, result) {
test.ifError(error);
//test.deepEqual(result.status, "OK");
test.done();
});
},
'get keywords from Text': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.keywords(testText, {}, function(error, result) {
test.ifError(error);
//test.deepEqual(result.status, "OK");
test.done();
});
},
'get category from Text': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.category(testText, {}, function(error, result) {
test.ifError(error);
//test.deepEqual(result.status, "OK");
test.done();
});
},
'get language from Text': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.language(testText, {}, function(error, result) {
test.ifError(error);
//test.deepEqual(result.status, "OK");
test.done();
});
},
'get author from Text': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.author(testText, {}, function(error, result) {
//console.log(error);
test.ok(error != null);
//test.deepEqual(result.status, "OK");
test.done();
});
},
'scrape text from Text': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.scrape(testText, {}, function(error, result) {
//console.log(error);
test.ok(error != null);
//test.deepEqual(result.status, "OK");
test.done();
});
},
'get microformats from HTML': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.microformats(testHTML, {}, function(error, result) {
//console.log(result);
test.ifError(error);
//test.deepEqual(result.status, "OK");
test.done();
});
},
'get microformats from URL': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.microformats("http://microformats.org/wiki/geo", {}, function(error, result) {
//console.log(result);
test.ifError(error);
//test.deepEqual(result.status, "OK");
test.done();
});
}
*/
}
};

0 comments on commit 7cc00c5

Please sign in to comment.