test update
This commit is contained in:
@@ -2,7 +2,7 @@ const GetFlix = require('../index');
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const getflix = new GetFlix('f29e56ff85f361ff01b5c5403a343021');
|
const getflix = new GetFlix('f29e56ff85f361ff01b5c5403a343021');
|
||||||
getflix.getInfo('70242311', (res) => {
|
getflix.getInfo('80040119', (res) => {
|
||||||
if (res.error) {
|
if (res.error) {
|
||||||
console.log(res.errorMsg);
|
console.log(res.errorMsg);
|
||||||
}
|
}
|
||||||
|
|||||||
14
lib/index.js
14
lib/index.js
@@ -41,14 +41,14 @@ class FlixInfo {
|
|||||||
if (imdbResult) {
|
if (imdbResult) {
|
||||||
$('[class="imdbRatingPlugin"]').each(function (i, element) {
|
$('[class="imdbRatingPlugin"]').each(function (i, element) {
|
||||||
|
|
||||||
|
// find imdb id attribute and catch
|
||||||
const imdbId = $(this).attr('data-title');
|
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'
|
const tmdbURL = theMovieDbURL + 'find/' + imdbId + '?api_key=' + tmdbApiKey + '&language=en-EN&external_source=imdb_id'
|
||||||
|
|
||||||
request(tmdbURL, (err, resultBody, body) => {
|
request(tmdbURL, (err, resultBody, body) => {
|
||||||
|
// Api find all result (for get tmdb id)
|
||||||
const getJson = JSON.parse(resultBody.body);
|
const getJson = JSON.parse(resultBody.body);
|
||||||
|
|
||||||
if (getJson.status_code > 1) {
|
if (getJson.status_code > 1) {
|
||||||
// if wrong api key error
|
// if wrong api key error
|
||||||
returnResult = { error: 1, errorMsg: 'tmdb find id wrong api key error' };
|
returnResult = { error: 1, errorMsg: 'tmdb find id wrong api key error' };
|
||||||
@@ -62,6 +62,8 @@ class FlixInfo {
|
|||||||
cb(returnResult)
|
cb(returnResult)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
|
// if tmdb api result not empty
|
||||||
if (getJson.tv_results.length || getJson.movie_results.length) {
|
if (getJson.tv_results.length || getJson.movie_results.length) {
|
||||||
|
|
||||||
if (getJson.movie_results.length) {
|
if (getJson.movie_results.length) {
|
||||||
@@ -93,7 +95,7 @@ class FlixInfo {
|
|||||||
cb(returnResult);
|
cb(returnResult);
|
||||||
}
|
}
|
||||||
else {
|
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);
|
cb(returnResult);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -104,7 +106,7 @@ class FlixInfo {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Return the empty result if tmdb return empty
|
// 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)
|
cb(returnResult)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,7 +116,7 @@ class FlixInfo {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Return the empty result if imdb id cannot be found
|
// 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)
|
cb(returnResult)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ describe('Flix Info', () => {
|
|||||||
|
|
||||||
flixinfoWrongApiKey.getInfo(70143836, (result) => {
|
flixinfoWrongApiKey.getInfo(70143836, (result) => {
|
||||||
result.should.have.property('error').equal(1);
|
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();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -35,21 +35,42 @@ describe('Flix Info', () => {
|
|||||||
const flixinfo = new GetFlix('f29e56ff85f361ff01b5c5403a343021');
|
const flixinfo = new GetFlix('f29e56ff85f361ff01b5c5403a343021');
|
||||||
|
|
||||||
context('Return result infos', () => {
|
context('Return result infos', () => {
|
||||||
it('- return right result', (done) => {
|
// Movie test
|
||||||
flixinfo.getInfo(70143836, (result) => {
|
it('- movies return right result', (done) => {
|
||||||
|
flixinfo.getInfo(60033299, (result) => {
|
||||||
result.should.have.property('result').equal(1);
|
result.should.have.property('result').equal(1);
|
||||||
result.should.have.property('error').equal(0);
|
result.should.have.property('error').equal(0);
|
||||||
result.should.have.property('originalName').equal('Breaking Bad');
|
result.should.have.property('details').have.property('original_title').equal('The Butterfly Effect');
|
||||||
result.should.have.property('name').equal('Breaking Bad');
|
result.should.have.property('details').have.property('title').equal('The Butterfly Effect');
|
||||||
result.should.have.property('year').equal('2008-01-20');
|
result.should.have.property('details').have.property('release_date').equal('2004-01-22');
|
||||||
result.should.have.property('poster').equal('https://image.tmdb.org/t/p/original//1yeVJox3rjo2jBKrrihIMj7uoS9.jpg');
|
result.should.have.property('details').have.property('poster_path').equal('/3PAQy3CyNNJPES772OFMx47lFEE.jpg');
|
||||||
result.should.have.property('backdrop').equal('https://image.tmdb.org/t/p/original//eSzpy96DwBujGFj0xMbXBcGcfxX.jpg');
|
result.should.have.property('details').have.property('backdrop_path').equal('/zXTUrm0BIrrZn3nEhybg0hlY275.jpg');
|
||||||
result.should.have.property('country').equal('US');
|
result.should.have.property('details').have.property('id').equal(1954);
|
||||||
result.should.have.property('rate').to.not.be.null
|
result.should.have.property('details').have.property('imdb_id').equal('tt0289879');
|
||||||
result.should.have.property('overviewEN').to.not.be.null
|
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();
|
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) => {
|
it('- return empty result', (done) => {
|
||||||
flixinfo.getInfo(23424, (result) => {
|
flixinfo.getInfo(23424, (result) => {
|
||||||
result.should.have.property('error').equal(0);
|
result.should.have.property('error').equal(0);
|
||||||
|
|||||||
Reference in New Issue
Block a user