Added rating and release_date when parsing movies and fixed respective tests
This commit is contained in:
@@ -1,14 +1,15 @@
|
|||||||
class Movie {
|
class Movie {
|
||||||
constructor(id, title, year=undefined, overview=undefined, poster=undefined,
|
constructor(id, title, year=undefined, overview=undefined, poster=undefined, backdrop=undefined,
|
||||||
backdrop=undefined, rank=undefined, genres=undefined, productionStatus=undefined,
|
releaseDate=undefined, rating=undefined, genres=undefined, productionStatus=undefined,
|
||||||
tagline=undefined, runtime=undefined, imdb_id=undefined, popularity) {
|
tagline=undefined, runtime=undefined, imdb_id=undefined, popularity=undefined) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.year = year;
|
this.year = year;
|
||||||
this.overview = overview;
|
this.overview = overview;
|
||||||
this.poster = poster;
|
this.poster = poster;
|
||||||
this.backdrop = backdrop;
|
this.backdrop = backdrop;
|
||||||
this.rank = rank;
|
this.releaseDate = releaseDate;
|
||||||
|
this.rating = rating;
|
||||||
this.genres = genres;
|
this.genres = genres;
|
||||||
this.productionStatus = productionStatus;
|
this.productionStatus = productionStatus;
|
||||||
this.tagline = tagline;
|
this.tagline = tagline;
|
||||||
@@ -19,13 +20,14 @@ class Movie {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static convertFromTmdbResponse(response) {
|
static convertFromTmdbResponse(response) {
|
||||||
const { id, title, release_date, overview, poster_path, backdrop_path, rank, genres, status,
|
const { id, title, release_date, overview, poster_path, backdrop_path, vote_average, genres, status,
|
||||||
tagline, runtime, imdb_id, popularity } = response;
|
tagline, runtime, imdb_id, popularity } = response;
|
||||||
|
|
||||||
const year = new Date(release_date).getFullYear()
|
const releaseDate = new Date(release_date);
|
||||||
|
const year = releaseDate.getFullYear();
|
||||||
const genreNames = genres ? genres.map(g => g.name) : undefined
|
const genreNames = genres ? genres.map(g => g.name) : undefined
|
||||||
|
|
||||||
return new Movie(id, title, year, overview, poster_path, backdrop_path, rank, genreNames, status,
|
return new Movie(id, title, year, overview, poster_path, backdrop_path, releaseDate, vote_average, genreNames, status,
|
||||||
tagline, runtime, imdb_id, popularity)
|
tagline, runtime, imdb_id, popularity)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,7 +36,7 @@ class Movie {
|
|||||||
const { title, year, rating, tagline, summary } = response;
|
const { title, year, rating, tagline, summary } = response;
|
||||||
const _ = undefined
|
const _ = undefined
|
||||||
|
|
||||||
return new Movie(null, title, year, summary, _, _, rating, _, _, tagline)
|
return new Movie(null, title, year, summary, _, _, _, rating, _, _, tagline)
|
||||||
}
|
}
|
||||||
|
|
||||||
createJsonResponse() {
|
createJsonResponse() {
|
||||||
@@ -45,7 +47,8 @@ class Movie {
|
|||||||
overview: this.overview,
|
overview: this.overview,
|
||||||
poster: this.poster,
|
poster: this.poster,
|
||||||
backdrop: this.backdrop,
|
backdrop: this.backdrop,
|
||||||
rank: this.rank,
|
release_date: this.releaseDate,
|
||||||
|
rating: this.rating,
|
||||||
genres: this.genres,
|
genres: this.genres,
|
||||||
production_status: this.productionStatus,
|
production_status: this.productionStatus,
|
||||||
tagline: this.tagline,
|
tagline: this.tagline,
|
||||||
|
|||||||
@@ -32,11 +32,11 @@ function handleListResponse(response, res) {
|
|||||||
.catch(error => handleError(error, res))
|
.catch(error => handleError(error, res))
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchTmdbList(req, res, listName, type) {
|
function fetchTmdbList(req, res, listname, type) {
|
||||||
const { page } = req.query;
|
const { page } = req.query;
|
||||||
|
|
||||||
if (type === 'movie') {
|
if (type === 'movie') {
|
||||||
return tmdb.movieList(listName, page)
|
return tmdb.movieList(listname, page)
|
||||||
.then(listResponse => res.send(listResponse))
|
.then(listResponse => res.send(listResponse))
|
||||||
.catch(error => handleError(error, res))
|
.catch(error => handleError(error, res))
|
||||||
} else if (type === 'show') {
|
} else if (type === 'show') {
|
||||||
|
|||||||
6
seasoned_api/test/fixtures/empty-query-success-response.json
vendored
Normal file
6
seasoned_api/test/fixtures/empty-query-success-response.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"page":1,
|
||||||
|
"results":[],
|
||||||
|
"total_results":0,
|
||||||
|
"total_pages":1
|
||||||
|
}
|
||||||
16
seasoned_api/test/helpers/tmdbMock2.js
Normal file
16
seasoned_api/test/helpers/tmdbMock2.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
const tmdbMock = () => ({
|
||||||
|
error: null,
|
||||||
|
response: null,
|
||||||
|
searchMovie(query, callback) {
|
||||||
|
callback(this.error, this.response);
|
||||||
|
},
|
||||||
|
movieInfo(query, callback) {
|
||||||
|
callback(this.error, this.response);
|
||||||
|
},
|
||||||
|
miscPopularMovies(callback) {
|
||||||
|
console.log('miscPopMovies callback', callback)
|
||||||
|
callback(this.error, this.response);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = tmdbMock;
|
||||||
@@ -1,28 +1,29 @@
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const convertTmdbToMovie = require('src/tmdb/convertTmdbToMovie');
|
// const convertTmdbToMovie = require('src/tmdb/convertTmdbToMovie');
|
||||||
|
const { Movie } = require('src/tmdb/types');
|
||||||
const bladeRunnerQuerySuccess = require('test/fixtures/blade_runner_2049-info-success-response.json')
|
const bladeRunnerQuerySuccess = require('test/fixtures/blade_runner_2049-info-success-response.json')
|
||||||
|
|
||||||
describe('Convert tmdb movieInfo to movie', () => {
|
describe('Convert tmdb movieInfo to movie', () => {
|
||||||
beforeEach(() => [this.bladeRunnerTmdbMovie] = bladeRunnerQuerySuccess);
|
beforeEach(() => [this.bladeRunnerTmdbMovie] = bladeRunnerQuerySuccess);
|
||||||
|
|
||||||
it('should translate the tmdb release date to movie year', () => {
|
it('should translate the tmdb release date to movie year', () => {
|
||||||
const bladeRunner = convertTmdbToMovie(this.bladeRunnerTmdbMovie);
|
const bladeRunner = Movie.convertFromTmdbResponse(this.bladeRunnerTmdbMovie);
|
||||||
assert.strictEqual(bladeRunner.year, 2017);
|
assert.strictEqual(bladeRunner.year, 2017);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should translate the tmdb release date to instance of Date', () => {
|
it('should translate the tmdb release date to instance of Date', () => {
|
||||||
const bladeRunner = convertTmdbToMovie(this.bladeRunnerTmdbMovie);
|
const bladeRunner = Movie.convertFromTmdbResponse(this.bladeRunnerTmdbMovie);
|
||||||
assert(bladeRunner.release_date instanceof Date);
|
assert(bladeRunner.releaseDate instanceof Date);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should translate the tmdb title to title', () => {
|
it('should translate the tmdb title to title', () => {
|
||||||
const bladeRunner = convertTmdbToMovie(this.bladeRunnerTmdbMovie);
|
const bladeRunner = Movie.convertFromTmdbResponse(this.bladeRunnerTmdbMovie);
|
||||||
assert.equal(bladeRunner.title, 'Blade Runner 2049');
|
assert.equal(bladeRunner.title, 'Blade Runner 2049');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should translate the tmdb vote_average to rank', () => {
|
it('should translate the tmdb vote_average to rating', () => {
|
||||||
const bladeRunner = convertTmdbToMovie(this.bladeRunnerTmdbMovie);
|
const bladeRunner = Movie.convertFromTmdbResponse(this.bladeRunnerTmdbMovie);
|
||||||
assert.equal(bladeRunner.rank, 7.3);
|
assert.equal(bladeRunner.rating, 7.3);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ describe('TMDB', function test() {
|
|||||||
it('should return the "Blade Runner 2049" year in the collection of popular movies', () => {
|
it('should return the "Blade Runner 2049" year in the collection of popular movies', () => {
|
||||||
this.mockMoviedb.response = popularMovieSuccessResponse;
|
this.mockMoviedb.response = popularMovieSuccessResponse;
|
||||||
const cache = new Cache(this.database);
|
const cache = new Cache(this.database);
|
||||||
const tmdb = new TMDB(cache, 'bogus-api-key', this.mockMoviedb);
|
const tmdb = new TMDB(cache, 'bogus-pi-key', this.mockMoviedb);
|
||||||
return tmdb.popular()
|
return tmdb.popular()
|
||||||
.then(movies =>
|
.then(movies =>
|
||||||
assert.equal(movies[0].title, "Blade Runner 2049")
|
assert.equal(movies[0].title, "Blade Runner 2049")
|
||||||
|
|||||||
Reference in New Issue
Block a user