yql-client
Version:
Nodejs client lib for the Yahoo YQL service.
114 lines (95 loc) • 4.48 kB
JavaScript
var assert = require('assert'), YQLClient = require('../yql'), YQL = YQLClient.YQL, YQLRequest = YQLClient.YQLRequest;
describe('YQL-client', function(){
var currentMock;
this.timeout(30 * 1000);
describe('YQL', function() {
it('should be a function', function(){
assert.ok((typeof YQL === 'function'), 'YQL should be a function');
assert.ok((typeof YQLRequest === 'function'), 'YQLRequest should be a function');
});
});
describe('Query', function() {
it('should return data with the correct format', function(done){
YQL('select * from weather.forecast where location=62896', function(r) {
assert.ok((typeof r === 'object'), 'Query Failure, response should be an Object');
assert.ok((typeof r.query === 'object'), 'Query object not present');
assert.equal(r.query.count, 1, 'Query Count not correct');
done(r.error);
});
});
});
describe('https Query', function() {
it('should return data with the correct format', function(done){
YQL('select * from weather.forecast where location=62896', function(r) {
assert.ok((typeof r === 'object'), 'Query Failure, response should be an Object');
assert.ok((typeof r.query === 'object'), 'Query object not present');
assert.equal(r.query.count, 1, 'Query Count not correct');
done(r.error);
}, {}, {proto:"https"});
});
});
describe('query failed', function() {
it('should fail', function(done){
YQL('select * from weatherFOO.forecast where location=62896', function(r) {
assert.ok((typeof r === 'object'), 'Query Failure r should be an object');
assert.ok(r.error, 'Query did not produce an error');
done();
});
});
});
describe('test unescaped input', function() {
it('should accept unescaped input', function(done){
YQL("select * from html where url = \"http://instantwatcher.com/genres/506\" and xpath='//div[@id=\"titles\"]/ul/li/a'", function(r) {
assert.ok((typeof r === 'object'), 'Query Failure, response should be an Object');
assert.ok((typeof r.query === 'object'), 'Query object not present');
done(r.error);
});
});
});
describe('test_requery', function() {
var counter = 0;
it('should send two queries', function(done){
var q = YQL('select * from weather.forecast where location=62896', function(r) {
counter++;
if (counter === 1) {
q.send();
} else {
assert.ok((counter === 2), 'Query did not send twice');
assert.ok((typeof r === 'object'), 'Query Failure, response should be an Object');
assert.ok((typeof r.query === 'object'), 'Query object not present');
done();
}
});
});
});
describe('context as option', function() {
var self = this;
self.isSelf = true;
it('should maintain the context passed as an option', function(done){
YQL('select * from weather.forecast where location=62896', function(r) {
var context = this;
assert.ok(context.isSelf, 'Context object not correct');
assert.ok((typeof r === 'object'), 'Query Failure, response should be an Object');
assert.ok((typeof r.query === 'object'), 'Query object not present');
done();
}, {}, {
context: self
});
});
});
describe('context as param', function() {
var self = this;
self.isSelf = true;
it('should maintain the context passed as an option', function(done){
YQL('select * from weather.forecast where location=62896', function(r) {
var context = this;
assert.ok(context.isSelf, 'Context object not correct');
assert.ok((typeof r === 'object'), 'Query Failure, response should be an Object');
assert.ok((typeof r.query === 'object'), 'Query object not present');
done();
}, {
context: self
});
});
});
});