From d13b34ecc035f806d11e1de0bd69dbd9ca6e8857 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 20 Nov 2015 15:13:32 -0800 Subject: [PATCH] tvAiringToday and some unit tests --- Makefile | 4 +++ lib/endpoints.json | 2 ++ package.json | 16 +++++++----- test/index.js | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 Makefile create mode 100644 test/index.js diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b2a02a8 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +test: + ./node_modules/.bin/mocha --reporter spec + + .PHONY: test \ No newline at end of file diff --git a/lib/endpoints.json b/lib/endpoints.json index 281a87d..6a0fc30 100644 --- a/lib/endpoints.json +++ b/lib/endpoints.json @@ -61,6 +61,8 @@ , "EpisodeCredits" : { "resource": "tv/:id/season/:season_number/episode/:episode_number/credits", "method": "get" } , "EpisodeExternalIds" : { "resource": "tv/:id/season/:season_number/episode/:episode_number/external_ids", "method": "get" } , "EpisodeImages" : { "resource": "tv/:id/season/:season_number/episode/:episode_number/images", "method": "get" } + , "OnTheAir" : { "resource": "tv/on_the_air", "method": "get" } + , "AiringToday" : { "resource": "tv/airing_today", "method": "get" } } , "person" : { "Info" : { "resource": "person/:id", "method": "get" } diff --git a/package.json b/package.json index ca936cc..6ba123c 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,12 @@ "name": "moviedb", "description": "Library for interacting with themoviedb.com API", "version": "0.2.2", + "scripts": { + "test": "clear; make test" + }, "repository": { "type": "git", - "url": "https://github.com/impronunciable/moviedb.git" + "url": "git+https://github.com/impronunciable/moviedb.git" }, "license": "MIT", "keywords": [ @@ -12,11 +15,6 @@ "api", "tmdb" ], - "repository": { - "type": "git", - "url": "git+https://github.com/impronunciable/moviedb.git" - }, - "license": "MIT", "bugs": { "url": "https://github.com/impronunciable/moviedb/issues" }, @@ -27,6 +25,12 @@ "main": "index.js", "author": "Dan Zajdband ", "dependencies": { + "chai": "^3.4.1", + "colors": "^1.1.2", "superagent": "0.21.0" + }, + "devDependencies": { + "chai": "^3.4.1", + "mocha": "^2.3.4" } } diff --git a/test/index.js b/test/index.js new file mode 100644 index 0000000..0077363 --- /dev/null +++ b/test/index.js @@ -0,0 +1,64 @@ +var should = require('chai').should(); +var assert = require('chai').assert; +var colors = require('colors'); +var apiKey = process.env.npm_config_key; +var api; + +/** + * checks for missing API key + * + * the proper way to run the test + * + * npm test --key='{your api key}' + * + * @param {[type]} !apiKey || apiKey.length [description] + * @return {[type]} [description] + */ +if (!apiKey || apiKey.length === 0) { + console.log('You have not provided the API key'.red); + console.log(' Running tests:'.cyan); + console.log(' npm test --key="{your api key}"'.cyan); + throw new Error('Missing API key, please `run npm test --key="{your api key}"`'); +} + +api = require('../index.js')(apiKey); + +describe('moviedb', function() { + + this.timeout(10000); + + // basic movie search + it('should search for Zoolander', function(done) { + api.searchMovie({query: 'Zoolander' }, function(err, res){ + if (err) done(err); + // console.log(res); + res.should.be.an('object'); + res.should.have.property('results'); + res.results.should.be.an('array'); + done(); + }); + }); + + it('should get the tv shows airing today', function(done) { + api.tvAiringToday(function(err, res) { + if (err) done(err); + // console.log(data); + res.should.be.an('object'); + res.should.have.property('results'); + res.results.should.be.an('array'); + done(); + }); + }); + + it('should get the tv shows OnTheAir', function(done) { + api.tvOnTheAir(function(err, res) { + if (err) done(err); + // console.log(data); + res.should.be.an('object'); + res.should.have.property('results'); + res.results.should.be.an('array'); + done(); + }); + }); + +}); \ No newline at end of file