Permalink
Browse files

Added some tests

  • Loading branch information...
1 parent 7cc9981 commit c262176636f641c9193b31e2c9aa9fc3ccff2c2b @smilledge committed Feb 13, 2013
Showing with 65 additions and 0 deletions.
  1. +3 −0 .npmignore
  2. +3 −0 Makefile
  3. +7 −0 package.json
  4. +52 −0 test/search-test.js
View
@@ -0,0 +1,3 @@
+.git*
+test/
+.DS_Store
View
@@ -0,0 +1,3 @@
+test:
+ @./node_modules/.bin/mocha --timeout 10000 --reporter spec
+.PHONY: test
View
@@ -7,6 +7,13 @@
"extend":"",
"querystring":""
},
+ "devDependencies": {
+ "mocha": "1.x.x",
+ "should": "0.6.x"
+ },
+ "scripts": {
+ "test": "make test"
+ },
"repository": {
"type": "git",
"url": "https://github.com/smilledge/node-google-books-search"
View
@@ -0,0 +1,52 @@
+var mocha = require('mocha');
+var should = require('should');
+var books = require('../lib/google-books-search.js');
+
+describe('Searching', function() {
+
+ it('should return a JSON object of books', function(done) {
+ books.search('Guinness World Records', {}, function(error, results) {
+ should.not.exist(error);
+ should.exist(results);
+ results[0].should.have.property('title');
+ done();
+ });
+ });
+
+ it('should return an empty object if there are no results', function(done) {
+ books.search('JCEhrrpxF2E1s7aPW8zd2903tQ4AlCB9', {}, function(error, results) {
+ should.not.exist(error);
+ should.exist(results);
+ results.length.should.equal(0);
+ done();
+ });
+ });
+
+ it('should return a specified number of results', function(done) {
+ books.search('Guinness World Records', {
+ limit: 15
+ }, function(error, results) {
+ should.not.exist(error);
+ results.length.should.equal(15);
+ done();
+ });
+ });
+
+ it('should only accept an limit below 40', function(done) {
+ books.search('Guinness World Records', {
+ limit: 50
+ }, function(error, results) {
+ should.exist(error);
+ done();
+ });
+ });
+
+ it('should return an error if no query is specified', function(done) {
+ books.search(null, {}, function(error, results) {
+ should.exist(error);
+ should.not.exist(results);
+ done();
+ });
+ });
+
+});

0 comments on commit c262176

Please sign in to comment.