Skip to content

Commit

Permalink
Added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hakovala committed Dec 13, 2012
1 parent 9ac580a commit 349da11
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
7 changes: 5 additions & 2 deletions Makefile
Expand Up @@ -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
1 change: 0 additions & 1 deletion lib/trakt.js
Expand Up @@ -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
}
}
Expand Down
36 changes: 35 additions & 1 deletion test/testTrakt.js
Expand Up @@ -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() {
Expand Down Expand Up @@ -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')
})
})
})
})
})

0 comments on commit 349da11

Please sign in to comment.