From 7cc00c5f9a24d09ea5e1ecd59161526b510488e3 Mon Sep 17 00:00:00 2001 From: Jason Morgan Date: Thu, 31 Jan 2013 15:41:28 -0500 Subject: [PATCH] Implemented test for all methods using URLs as an argument. --- index.js | 4 +- test/index.js | 215 +++++++------------------------------------------- 2 files changed, 31 insertions(+), 188 deletions(-) diff --git a/index.js b/index.js index 7952e16..b6d6539 100644 --- a/index.js +++ b/index.js @@ -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 @@ -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); diff --git a/test/index.js b/test/index.js index a73d45c..f4ff8db 100644 --- a/test/index.js +++ b/test/index.js @@ -1,15 +1,13 @@ 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 = 'Alchemy Test HTML

Alchemy Test HTML

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

GEO: 37.386013, -122.082932
'; -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); @@ -17,8 +15,7 @@ module.exports = { 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); @@ -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(); - }); - } - */ + } }; \ No newline at end of file