From ac7bfd2925d231a0d89f692f1b67e80702b738ba Mon Sep 17 00:00:00 2001 From: Wise Colt Date: Wed, 2 Jan 2019 19:34:35 +0300 Subject: [PATCH] test update --- example/getinfo.js | 2 +- lib/index.js | 18 ++++++++++-------- test/flixinfo.test.js | 43 ++++++++++++++++++++++++++++++++----------- 3 files changed, 43 insertions(+), 20 deletions(-) diff --git a/example/getinfo.js b/example/getinfo.js index 9aa9246..6635f47 100644 --- a/example/getinfo.js +++ b/example/getinfo.js @@ -2,7 +2,7 @@ const GetFlix = require('../index'); try { const getflix = new GetFlix('f29e56ff85f361ff01b5c5403a343021'); - getflix.getInfo('70242311', (res) => { + getflix.getInfo('80040119', (res) => { if (res.error) { console.log(res.errorMsg); } diff --git a/lib/index.js b/lib/index.js index d525fa7..72136d8 100644 --- a/lib/index.js +++ b/lib/index.js @@ -41,14 +41,14 @@ class FlixInfo { if (imdbResult) { $('[class="imdbRatingPlugin"]').each(function (i, element) { + // find imdb id attribute and catch const imdbId = $(this).attr('data-title'); - + // create (find) tmdb api url const tmdbURL = theMovieDbURL + 'find/' + imdbId + '?api_key=' + tmdbApiKey + '&language=en-EN&external_source=imdb_id' - + request(tmdbURL, (err, resultBody, body) => { - + // Api find all result (for get tmdb id) const getJson = JSON.parse(resultBody.body); - if (getJson.status_code > 1) { // if wrong api key error returnResult = { error: 1, errorMsg: 'tmdb find id wrong api key error' }; @@ -62,8 +62,10 @@ class FlixInfo { cb(returnResult) } else { + + // if tmdb api result not empty if (getJson.tv_results.length || getJson.movie_results.length) { - + if (getJson.movie_results.length) { var watchParameter = 'movie'; var thmdbId = getJson.movie_results[0].id; @@ -93,7 +95,7 @@ class FlixInfo { cb(returnResult); } else { - returnResult = { result: 1, error: 0, tv_results: getDetailResult, credits: getCreditsResult, images: getImagesResult }; + returnResult = { result: 1, error: 0, watch: watchParameter, details: getDetailResult, credits: getCreditsResult, images: getImagesResult }; cb(returnResult); } }); @@ -104,7 +106,7 @@ class FlixInfo { } else { // Return the empty result if tmdb return empty - const returnResult = { result: 0, error: 0 }; + const returnResult = { result: 0, error: 0, msg: 'tmdb api return is empty'}; cb(returnResult) } } @@ -114,7 +116,7 @@ class FlixInfo { } else { // Return the empty result if imdb id cannot be found - const returnResult = { result: 0, error: 0 }; + const returnResult = { result: 0, error: 0, msg: 'imdb id cannot be found' }; cb(returnResult) } } diff --git a/test/flixinfo.test.js b/test/flixinfo.test.js index 0ab5032..5f0af52 100644 --- a/test/flixinfo.test.js +++ b/test/flixinfo.test.js @@ -23,7 +23,7 @@ describe('Flix Info', () => { flixinfoWrongApiKey.getInfo(70143836, (result) => { result.should.have.property('error').equal(1); - result.should.have.property('errorMsg').equal('tmdb wrong api key error'); + result.should.have.property('errorMsg').equal('tmdb find id wrong api key error'); done(); }); }); @@ -35,21 +35,42 @@ describe('Flix Info', () => { const flixinfo = new GetFlix('f29e56ff85f361ff01b5c5403a343021'); context('Return result infos', () => { - it('- return right result', (done) => { - flixinfo.getInfo(70143836, (result) => { + // Movie test + it('- movies return right result', (done) => { + flixinfo.getInfo(60033299, (result) => { result.should.have.property('result').equal(1); result.should.have.property('error').equal(0); - result.should.have.property('originalName').equal('Breaking Bad'); - result.should.have.property('name').equal('Breaking Bad'); - result.should.have.property('year').equal('2008-01-20'); - result.should.have.property('poster').equal('https://image.tmdb.org/t/p/original//1yeVJox3rjo2jBKrrihIMj7uoS9.jpg'); - result.should.have.property('backdrop').equal('https://image.tmdb.org/t/p/original//eSzpy96DwBujGFj0xMbXBcGcfxX.jpg'); - result.should.have.property('country').equal('US'); - result.should.have.property('rate').to.not.be.null - result.should.have.property('overviewEN').to.not.be.null + result.should.have.property('details').have.property('original_title').equal('The Butterfly Effect'); + result.should.have.property('details').have.property('title').equal('The Butterfly Effect'); + result.should.have.property('details').have.property('release_date').equal('2004-01-22'); + result.should.have.property('details').have.property('poster_path').equal('/3PAQy3CyNNJPES772OFMx47lFEE.jpg'); + result.should.have.property('details').have.property('backdrop_path').equal('/zXTUrm0BIrrZn3nEhybg0hlY275.jpg'); + result.should.have.property('details').have.property('id').equal(1954); + result.should.have.property('details').have.property('imdb_id').equal('tt0289879'); + result.should.have.property('details').have.property('original_language').equal('en'); + result.should.have.property('credits').have.property('id').equal(1954); + result.should.have.property('images').have.property('id').equal(1954); done(); }); }); + // Tv test + it('- tv series return right result', (done) => { + flixinfo.getInfo(80099656, (result) => { + result.should.have.property('result').equal(1); + result.should.have.property('error').equal(0); + result.should.have.property('details').have.property('original_name').equal('Frontier'); + result.should.have.property('details').have.property('name').equal('Frontier'); + result.should.have.property('details').have.property('first_air_date').equal('2016-11-06'); + result.should.have.property('details').have.property('poster_path').equal('/mhIeCeYgG4WJHNzaw2EyRpvmGX8.jpg'); + result.should.have.property('details').have.property('backdrop_path').equal('/hDYEGNX6CADoCqhyBbe2Qu7rKVG.jpg'); + result.should.have.property('details').have.property('id').equal(64555); + result.should.have.property('details').have.property('original_language').equal('en'); + result.should.have.property('credits').have.property('id').equal(64555); + result.should.have.property('images').have.property('id').equal(64555); + done(); + }); + }); + it('- return empty result', (done) => { flixinfo.getInfo(23424, (result) => { result.should.have.property('error').equal(0);