From 349da1155893a1509524c2d08f150088db0b90c4 Mon Sep 17 00:00:00 2001 From: hakovala Date: Fri, 14 Dec 2012 00:45:28 +0200 Subject: [PATCH] Added unit tests --- Makefile | 7 +++++-- lib/trakt.js | 1 - test/testTrakt.js | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 6f9e9a0..e66d4eb 100644 --- a/Makefile +++ b/Makefile @@ -9,8 +9,11 @@ test-w: --watch test-cov: - @rm -r lib-cov + @rm -rf lib-cov @jscoverage lib lib-cov @TEST_COV=1 $(MAKE) test REPORTER=html-cov > coverage.html -.PHONY: test test-w +clean: + @rm -rf lib-cov coverage.html + +.PHONY: test test-w clean diff --git a/lib/trakt.js b/lib/trakt.js index 76303f8..4ab2658 100644 --- a/lib/trakt.js +++ b/lib/trakt.js @@ -142,7 +142,6 @@ var getPostParams = function(action, opts, options) { if (options[param.name]) { result[param.name] = options[param.name] } else if(!param.optional) { - console.log('wtf'); return undefined } } diff --git a/test/testTrakt.js b/test/testTrakt.js index 3768a2f..3da6af6 100644 --- a/test/testTrakt.js +++ b/test/testTrakt.js @@ -61,6 +61,17 @@ describe('Trakt requests', function() { res.should.includeEql({title: "hello"}) }) }) + it('should discard extra optional arguments', function() { + var get = nock(url) + .get('/activity/shows.json/' + config.api_key + '/title') + .reply(200, {status: 'success'}) + trakt.request('activity', 'shows', {title: 'title', start_ts: '12345678'}, function(err, res) { + should.not.exist(err) + should.exist(res) + res.should.have.property('status') + res.status.should.equal('success') + }) + }) }) describe('Post request', function() { it('should give error, no auth', function() { @@ -96,5 +107,28 @@ describe('Trakt requests', function() { res.message.should.equal('all good!') }) }) + it('should discard extra arguments', function() { + var post = nock(url) + .post('/show/library/' + config.api_key, { + tvdb_id: 'tvdb', + title: 'title', + year: 2000, + username: config.user, + password: config.pass + }) + .reply(200, {status: 'success'}) + + trakt.request('show', 'library', {dummy: 'dummy', title: 'title', year: 2000}, function(err, res) { + should.exist(err) + err.message.should.equal('Missing parameters') + }) + + trakt.request('show', 'library', {tvdb_id: 'tvdb', dummy: 'dummy', title: 'title', year: 2000}, function(err, res) { + should.not.exist(err) + should.exist(res) + res.should.have.property('status') + res.status.should.equal('success') + }) + }) }) -}) \ No newline at end of file +})