UNPKG

2.02 kBJavaScriptView Raw
1var should = require('chai').should();
2var assert = require('chai').assert;
3var colors = require('colors');
4var apiKey = process.env.MOVIEDB_API_KEY || process.env.npm_config_key;
5var api;
6
7/**
8 * checks for missing API key
9 *
10 * the proper way to run the test
11 *
12 * npm test --key='{your api key}'
13 *
14 * @param {[type]} !apiKey || apiKey.length [description]
15 * @return {[type]} [description]
16 */
17if (!apiKey || apiKey.length === 0) {
18 console.log('You have not provided the API key'.red);
19 console.log(' Running tests:'.cyan);
20 console.log(' npm test --key="{your api key}"'.cyan);
21 throw new Error('Missing API key, please `run npm test --key="{your api key}"`');
22}
23
24api = require('../index.js')(apiKey);
25
26describe('moviedb', function() {
27
28 this.timeout(10000);
29
30 // basic movie search
31 it('should search for Zoolander', function(done) {
32 api.searchMovie({query: 'Zoolander' }, function(err, res){
33 if (err) done(err);
34 // console.log(res);
35 res.should.be.an('object');
36 res.should.have.property('results');
37 res.results.should.be.an('array');
38 done();
39 });
40 });
41
42 it('should get the tv shows airing today', function(done) {
43 api.tvAiringToday(function(err, res) {
44 if (err) done(err);
45 // console.log(data);
46 res.should.be.an('object');
47 res.should.have.property('results');
48 res.results.should.be.an('array');
49 done();
50 });
51 });
52
53 it('should get the tv shows OnTheAir', function(done) {
54 api.tvOnTheAir(function(err, res) {
55 if (err) done(err);
56 // console.log(data);
57 res.should.be.an('object');
58 res.should.have.property('results');
59 res.results.should.be.an('array');
60 done();
61 });
62 });
63
64 it ('should get the movie release dates', function(done) {
65 api.movieReleaseDates({id: 209112}, function(err, res) {
66 if (err) done(err);
67 res.should.be.an('object');
68 res.should.have.property('results');
69 res.results.should.be.an('array');
70 assert.equal(res.id, 209112);
71 done();
72 });
73 });
74
75});