From 0b57be42784653a35511528719a3c1d3b3413653 Mon Sep 17 00:00:00 2001 From: Hugh Rawlinson Date: Mon, 9 Mar 2015 20:17:53 +0000 Subject: [PATCH] adds more tests, switches coverage library to istanbul --- Makefile | 4 ++-- lib/search.js | 4 ++++ package.json | 1 + test/Albums.js | 15 ++++++++++++++- test/Artists.js | 15 ++++++++++++++- test/Search.js | 8 +++++++- test/Tracks.js | 15 ++++++++++++++- 7 files changed, 56 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 795238c..9b9b3c8 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ test: ./node_modules/.bin/jscoverage lib lib-cov - ./node_modules/.bin/mocha -R mocha-lcov-reporter | ./node_modules/coveralls/bin/coveralls.js + istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage clean: - rm -rf coverage lib-cov node_modules coverage.html + rm -rf coverage lib-cov coverage.html .PHONY: test \ No newline at end of file diff --git a/lib/search.js b/lib/search.js index 462fde7..baff6cf 100644 --- a/lib/search.js +++ b/lib/search.js @@ -47,6 +47,10 @@ module.exports = function search(randr) { 'mood[happy_songs][to]', 'mood[happy_songs][from' ]); + + if (!params.q) { + return callback(new Error('Must specify a query'), null); + } var query = randr.network._buildQuery(params); var uri = 'search/tracks?' + query; diff --git a/package.json b/package.json index e765344..be61125 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ }, "devDependencies": { "coveralls": "^2.11.2", + "istanbul": "^0.3.7", "jscoverage": "^0.5.9", "mocha": "^2.2.0", "mocha-lcov-reporter": "0.0.2" diff --git a/test/Albums.js b/test/Albums.js index b80b8a0..4bca1e4 100644 --- a/test/Albums.js +++ b/test/Albums.js @@ -1,5 +1,4 @@ var assert = require("assert"); -var app = require('../lib-cov/albums'); // setup var RandR = require("../index"); var randr = new RandR(process.env.RANDRMUSICAPIACCESSTOKEN); @@ -39,6 +38,13 @@ describe('Albums', function(){ } ); }); + it('should fail when called without a required parameter',function(done){ + randr.albums.id({},function(err,data){ + assert(err!=null); + done(); + } + ); + }); }); describe('Similar', function(){ it('should return a list of similar albums when called with a valid id', function(done){ @@ -73,5 +79,12 @@ describe('Albums', function(){ } ); }); + it('should fail when called without a required parameter',function(done){ + randr.albums.similar({},function(err,data){ + assert(err!=null); + done(); + } + ); + }); }); }); \ No newline at end of file diff --git a/test/Artists.js b/test/Artists.js index bd1085a..5aefe17 100644 --- a/test/Artists.js +++ b/test/Artists.js @@ -1,5 +1,4 @@ var assert = require("assert"); -var app = require('../lib-cov/artists'); // setup var RandR = require("../index"); var randr = new RandR(process.env.RANDRMUSICAPIACCESSTOKEN); @@ -39,6 +38,13 @@ describe('Artists', function(){ } ); }); + it('should fail when called without a required parameter',function(done){ + randr.artists.id({},function(err,data){ + assert(err!=null); + done(); + } + ); + }); }); describe('Similar', function(){ it('should return a list of similar artists when called with a valid id', function(done){ @@ -73,5 +79,12 @@ describe('Artists', function(){ } ); }); + it('should fail when called without a required parameter',function(done){ + randr.artists.similar({},function(err,data){ + assert(err!=null); + done(); + } + ); + }); }); }); \ No newline at end of file diff --git a/test/Search.js b/test/Search.js index 5ca4a54..2d6a6ea 100644 --- a/test/Search.js +++ b/test/Search.js @@ -1,5 +1,4 @@ var assert = require("assert"); -var app = require('../lib-cov/search'); // setup var RandR = require("../index"); var randr = new RandR(process.env.RANDRMUSICAPIACCESSTOKEN); @@ -20,5 +19,12 @@ describe('Search', function(){ ); }) }); + it('should fail when called without a required parameter',function(done){ + randr.search.tracks({},function(err,data){ + assert(err!=null); + done(); + } + ); + }); }); }); \ No newline at end of file diff --git a/test/Tracks.js b/test/Tracks.js index 70f5ee0..9262097 100644 --- a/test/Tracks.js +++ b/test/Tracks.js @@ -1,5 +1,4 @@ var assert = require("assert"); -var app = require('../lib-cov/tracks'); // setup var RandR = require("../index"); var randr = new RandR(process.env.RANDRMUSICAPIACCESSTOKEN); @@ -39,6 +38,13 @@ describe('Tracks', function(){ } ); }); + it('should fail when called without a required parameter',function(done){ + randr.tracks.id({},function(err,data){ + assert(err!=null); + done(); + } + ); + }); }); describe('Recommendations', function(){ it('should return a list of recommendations when called with a valid id', function(done){ @@ -73,5 +79,12 @@ describe('Tracks', function(){ } ); }); + it('should fail when called without a required parameter',function(done){ + randr.tracks.recommendations({},function(err,data){ + assert(err!=null); + done(); + } + ); + }); }); }); \ No newline at end of file