From 7e46d32e308944843e00b24e9feb74b7c233a25c Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 30 Oct 2018 20:32:55 +0100 Subject: [PATCH] More unit tests for checking correct definition of movie. Changed some test to match update functions in tmdb. --- seasoned_api/package.json | 2 +- seasoned_api/src/database/schemas/setup.sql | 8 +++++ .../src/database/schemas/teardown.sql | 1 + ...ade_runner_2049-info-success-response.json | 1 + ...rstellar-query-movie-success-response.json | 1 + .../system/asAUserIWantToRequestAMovie.js | 7 +++-- ...asAnAnonymousUserIWantToSearchForAMovie.js | 6 ++-- .../test/unit/tmdb/testConvertTmdbToMovie.js | 30 ++++++++++++++++++ seasoned_api/test/unit/tmdb/testTmdb.disabled | 31 +++++++++++++++++++ 9 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 seasoned_api/test/fixtures/blade_runner_2049-info-success-response.json create mode 100644 seasoned_api/test/fixtures/interstellar-query-movie-success-response.json create mode 100644 seasoned_api/test/unit/tmdb/testConvertTmdbToMovie.js create mode 100644 seasoned_api/test/unit/tmdb/testTmdb.disabled diff --git a/seasoned_api/package.json b/seasoned_api/package.json index d5a98ac..8d1b458 100644 --- a/seasoned_api/package.json +++ b/seasoned_api/package.json @@ -8,7 +8,7 @@ "main": "webserver/server.js", "scripts": { "start": "cross-env SEASONED_CONFIG=conf/development.json PROD=true NODE_PATH=. node src/webserver/server.js", - "test": "cross-env SEASONED_CONFIG=conf/test.json NODE_PATH=. mocha --recursive test", + "test": "cross-env SEASONED_CONFIG=conf/test.json NODE_PATH=. mocha --recursive test/unit test/system", "coverage": "cross-env SEASONED_CONFIG=conf/test.json NODE_PATH=. nyc mocha --recursive test && nyc report --reporter=text-lcov | coveralls", "lint": "./node_modules/.bin/eslint src/", "update": "cross-env SEASONED_CONFIG=conf/development.json NODE_PATH=. node src/plex/updateRequestsInPlex.js" diff --git a/seasoned_api/src/database/schemas/setup.sql b/seasoned_api/src/database/schemas/setup.sql index ed96de5..88a0a8c 100644 --- a/seasoned_api/src/database/schemas/setup.sql +++ b/seasoned_api/src/database/schemas/setup.sql @@ -36,6 +36,14 @@ CREATE TABLE IF NOT EXISTS requests( type CHAR(50) DEFAULT 'movie' ); +CREATE TABLE IF NOT EXISTS request( + id int not null, + title text not null, + year int not null, + type char(10) not null, + date default current_timestamp +); + CREATE TABLE IF NOT EXISTS stray_eps( id TEXT UNIQUE, diff --git a/seasoned_api/src/database/schemas/teardown.sql b/seasoned_api/src/database/schemas/teardown.sql index 750cbab..cf7e6e3 100644 --- a/seasoned_api/src/database/schemas/teardown.sql +++ b/seasoned_api/src/database/schemas/teardown.sql @@ -1,3 +1,4 @@ DROP TABLE IF EXISTS user; DROP TABLE IF EXISTS search_history; DROP TABLE IF EXISTS requests; +DROP TABLE IF EXISTS request; diff --git a/seasoned_api/test/fixtures/blade_runner_2049-info-success-response.json b/seasoned_api/test/fixtures/blade_runner_2049-info-success-response.json new file mode 100644 index 0000000..7e8e9f3 --- /dev/null +++ b/seasoned_api/test/fixtures/blade_runner_2049-info-success-response.json @@ -0,0 +1 @@ +{"adult":false,"backdrop_path":"/mVr0UiqyltcfqxbAUcLl9zWL8ah.jpg","belongs_to_collection":{"id":422837,"name":"Blade Runner Collection","poster_path":"/cWESb1o9lW2i2Z3Xllv9u40aNIk.jpg","backdrop_path":"/bSHZIvLoPBWyGLeiAudN1mXdvQX.jpg"},"budget":150000000,"genres":[{"id":9648,"name":"Mystery"},{"id":878,"name":"Science Fiction"},{"id":53,"name":"Thriller"}],"homepage":"http://bladerunnermovie.com/","id":335984,"imdb_id":"tt1856101","original_language":"en","original_title":"Blade Runner 2049","overview":"Thirty years after the events of the first film, a new blade runner, LAPD Officer K, unearths a long-buried secret that has the potential to plunge what's left of society into chaos. K's discovery leads him on a quest to find Rick Deckard, a former LAPD blade runner who has been missing for 30 years.","popularity":30.03,"poster_path":"/gajva2L0rPYkEWjzgFlBXCAVBE5.jpg","production_companies":[{"id":79529,"logo_path":"/gVN3k8emmKy4iV4KREWcCtxusZK.png","name":"Torridon Films","origin_country":"US"},{"id":101829,"logo_path":"/8IOjCvgjq0zTrtP91cWD3kL2jMK.png","name":"16:14 Entertainment","origin_country":"US"},{"id":1645,"logo_path":"/6Ry6uNBaa0IbbSs1XYIgX5DkA9r.png","name":"Scott Free Productions","origin_country":""},{"id":5,"logo_path":"/71BqEFAF4V3qjjMPCpLuyJFB9A.png","name":"Columbia Pictures","origin_country":"US"},{"id":1088,"logo_path":"/9WOE5AQUXbOtLU6GTwfjS8OMF0v.png","name":"Alcon Entertainment","origin_country":"US"},{"id":78028,"logo_path":"/sTFcDFfJaSVT3sv3DoaZDE4SlGB.png","name":"Thunderbird Entertainment","origin_country":"CA"},{"id":174,"logo_path":"/ky0xOc5OrhzkZ1N6KyUxacfQsCk.png","name":"Warner Bros. Pictures","origin_country":"US"}],"production_countries":[{"iso_3166_1":"CA","name":"Canada"},{"iso_3166_1":"US","name":"United States of America"},{"iso_3166_1":"HU","name":"Hungary"},{"iso_3166_1":"GB","name":"United Kingdom"}],"release_date":"2017-10-04","revenue":259239658,"runtime":163,"spoken_languages":[{"iso_639_1":"en","name":"English"},{"iso_639_1":"fi","name":"suomi"}],"status":"Released","tagline":"There's still a page left.","title":"Blade Runner 2049","video":false,"vote_average":7.3,"vote_count":5478} diff --git a/seasoned_api/test/fixtures/interstellar-query-movie-success-response.json b/seasoned_api/test/fixtures/interstellar-query-movie-success-response.json new file mode 100644 index 0000000..aca9a34 --- /dev/null +++ b/seasoned_api/test/fixtures/interstellar-query-movie-success-response.json @@ -0,0 +1 @@ +{"page":1,"total_results":11,"total_pages":1,"results":[{"vote_count":15920,"id":157336,"video":false,"vote_average":8.2,"title":"Interstellar","popularity":34.088,"poster_path":"/nBNZadXqJSdt05SHLqgT0HuC5Gm.jpg","original_language":"en","original_title":"Interstellar","genre_ids":[12,18,878],"backdrop_path":"/xu9zaAevzQ5nnrsXN6JcahLnG4i.jpg","adult":false,"overview":"Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.","release_date":"2014-11-05"},{"vote_count":126,"id":301959,"video":false,"vote_average":7.8,"title":"Interstellar: Nolan's Odyssey","popularity":4.961,"poster_path":"/xZwUIPqBHyJ2QIfMPANOZ1mAld6.jpg","original_language":"en","original_title":"Interstellar: Nolan's Odyssey","genre_ids":[99],"backdrop_path":"/bT5jpIZE50MI0COE8pOeq0kMpQo.jpg","adult":false,"overview":"Behind the scenes of Christopher Nolan's sci-fi drama, which stars Matthew McConaughey and Anne Hathaway","release_date":"2014-11-05"},{"vote_count":1,"id":287954,"video":false,"vote_average":7,"title":"Lolita from Interstellar Space","popularity":3.45,"poster_path":"/buoq7zYO4J3ttkEAqEMWelPDC0G.jpg","original_language":"en","original_title":"Lolita from Interstellar Space","genre_ids":[35],"backdrop_path":"/mgb6tVEieDYLpQt666ACzGz5cyE.jpg","adult":false,"overview":"An undeniably beautiful alien is sent to Earth to study the complex mating rituals of human beings, which leads to the young interstellar traveler experiencing the passion that surrounds the centuries-old ritual of the species.","release_date":"2014-03-08"},{"vote_count":0,"id":529107,"video":false,"vote_average":0,"title":"Inside Interstellar","popularity":1.102,"poster_path":"/vemBplPKQhVe5cRWL7kxtgp15Vq.jpg","original_language":"en","original_title":"Inside Interstellar","genre_ids":[99],"backdrop_path":null,"adult":false,"overview":"Cast and crew of Christopher Nolan's 'Interstellar' discuss project origins, the film's imagery, ambitions, incorporating IMAX footage, the human element within the film, arm shooting locations outside of Calgary, the set construction and design, working with real corn, mechanical characters, including backstory, design, the blend of practical and digital effects in bringing them to life, the differences in the characters, the human performances behind the characters, the creative process behind the film's music, Icelandic locations, vehicle interiors, the processes of simulating the absence of gravity, the crucial end-film visuals and influence and inspiration for future generations","release_date":"2015-03-31"},{"vote_count":6,"id":336592,"video":false,"vote_average":7.8,"title":"The Science of Interstellar","popularity":0.852,"poster_path":"/6KBD7YSBjCfgBgHwpsQo3G3GGdx.jpg","original_language":"en","original_title":"The Science of Interstellar","genre_ids":[99],"backdrop_path":null,"adult":false,"overview":"The science of Christopher Nolan's sci-fi, Interstellar.","release_date":"2014-11-25"},{"vote_count":7,"id":398188,"video":false,"vote_average":3.8,"title":"Interstellar Wars","popularity":0.6,"poster_path":"/cjvTebuqD8wmhchHE286ltVcbX6.jpg","original_language":"en","original_title":"Interstellar Wars","genre_ids":[878],"backdrop_path":"/yTnHa6lgIv8rNneSNBDkBe8MnZe.jpg","adult":false,"overview":"For Millennia the Aliien force has watched and waited, a brooding menace that has now at last decided to take over the Earth. Communications systems worldwide are sent into chaos by a strange atmospheric interference and this has turned into a global phenomenon. A massive spaceship headed towards Earth and smaller spaceships began to cover entire cities around the world. Suddenly, the wonder turns into horror as the spaceships destroy the cities with energy weapons. When the world counterattacks, the alien ships are invincible to military weapons. The survivors have to use their wits to kill the aliens, or die.","release_date":"2016-05-23"},{"vote_count":1,"id":460616,"video":false,"vote_average":4,"title":"Interstellar Civil War: Shadows of the Empire","popularity":0.959,"poster_path":"/7yTHKiVWZmUxgqGSzZv9yBx5bGI.jpg","original_language":"en","original_title":"Interstellar Civil War: Shadows of the Empire","genre_ids":[28,14,878],"backdrop_path":null,"adult":false,"overview":"The Imperial Empire is attacked by an Alliance of rebels led by fanatical mystics. The ruler, Empress Nobu, the 8th generation of her family, wants to execute a bold plan to rescue a cyborg, Leah C6, trapped on the battle ravaged planet Endor. The Empress believes Leah C6 holds the secret to destroying the Alliance of Rebels before their insurgency can kill millions of citizens of the Empire. She recruits her heroic fleet commander, Lord General Luka Raan and asks him to gather a team from the Empire's elite soldiers, the Galactic Rangers. Raan assembles the team in the ruins of Endor which was attacked by depraved Rebels and outlaws led by, Kindo-Ker, a fanatical mystic in Dark Energy. The Galactic Rangers begin a desperate search to find and rescue Leah C6 before the Alliance Rebels can.","release_date":"2018-04-15"},{"vote_count":0,"id":552531,"video":false,"vote_average":0,"title":"The Prom Goer's Interstellar Excursion","popularity":0.6,"poster_path":null,"original_language":"en","original_title":"The Prom Goer's Interstellar Excursion","genre_ids":[12],"backdrop_path":null,"adult":false,"overview":"High schooler Bennett lands the prom date of his dreams, Sophie, just days before the dance. Not long after, he witnesses Sophie being abducted by aliens in the middle of the New Mexico desert.","release_date":""},{"vote_count":11,"id":47662,"video":false,"vote_average":5.4,"title":"Trancers 4: Jack of Swords","popularity":3.221,"poster_path":"/69yr3oxBpSgua26RJkFmsm7plTG.jpg","original_language":"en","original_title":"Trancers 4: Jack of Swords","genre_ids":[878,28],"backdrop_path":"/5ism2HNUGuQi5a3ajYaN9ypMQMf.jpg","adult":false,"overview":"Jack is now back in the future. He had since lost Lena, and finds out that he's lost his other wife Alice to none other than Harris. While heading out for another assignment, something goes awry with the TCL chamber. Jack finds himself in a whole new dimension. He also runs across a different version of trancers. These guys seem to be in control of this planet. Jack manages to assist a rebel group known as the \"Tunnel Rats\" crush the rule of the evil Lord Calaban.","release_date":"1994-02-02"},{"vote_count":7,"id":47663,"video":false,"vote_average":5.3,"title":"Trancers 5: Sudden Deth","popularity":0.6,"poster_path":"/epMaTjPDMbgC8TbW1ZToh4RNv0i.jpg","original_language":"en","original_title":"Trancers 5: Sudden Deth","genre_ids":[28,53,878],"backdrop_path":"/an0xpUEX1P1BI80sCpkU1pSoREx.jpg","adult":false,"overview":"Jack Deth is back for one more round with the trancers. Jack must attempt to find his way home from the other-dimensional world of Orpheus, where magic works and the trancers were the ruling class (before Trancers IV, that is). Unfortunately, Jack's quest to find the mystical Tiamond in the Castle of Unrelenting Terror may be thwarted by the return of Caliban, king of the trancers who was thought dead.","release_date":"1994-11-04"},{"vote_count":1,"id":261443,"video":false,"vote_average":4.5,"title":"Angry Planet","popularity":0.6,"poster_path":"/ie5luS87ess1c5VgFhbGECJTQVK.jpg","original_language":"en","original_title":"Angry Planet","genre_ids":[878],"backdrop_path":"/u4JBwlGZN8hGeLxwu7Q0WmibACp.jpg","adult":false,"overview":"A criminal sentenced to life on a prison planet reveals his true purpose: to extract revenge on the killers who murdered his family.","release_date":"2008-01-01"}]} diff --git a/seasoned_api/test/system/asAUserIWantToRequestAMovie.js b/seasoned_api/test/system/asAUserIWantToRequestAMovie.js index 65b496f..218a0fa 100644 --- a/seasoned_api/test/system/asAUserIWantToRequestAMovie.js +++ b/seasoned_api/test/system/asAUserIWantToRequestAMovie.js @@ -4,18 +4,19 @@ const app = require('src/webserver/app'); const request = require('supertest-as-promised'); const createUser = require('test/helpers/createUser'); const createToken = require('test/helpers/createToken'); -const infoMovieSuccess = require('test/fixtures/arrival-info-success-response.json'); +const infoMovieSuccess = require('test/fixtures/blade_runner_2049-info-success-response.json'); describe('As a user I want to request a movie', () => { before(() => { return resetDatabase() .then(() => createUser('test_user', 'test@gmail.com', 'password')); }) - before(() => createCacheEntry('i:movie:329865', infoMovieSuccess)); + before(() => createCacheEntry('mi:335984', infoMovieSuccess)); it('should return 200 when item is requested', () => request(app) - .post('/api/v1/plex/request/329865') + .post('/api/v2/request/335984', {tmdbType: 'movie'}) + .send({ tmdbType: 'movie' }) .set('Authorization', createToken('test_user', 'secret')) .expect(200) ); diff --git a/seasoned_api/test/system/asAnAnonymousUserIWantToSearchForAMovie.js b/seasoned_api/test/system/asAnAnonymousUserIWantToSearchForAMovie.js index b9b2789..13e43ab 100644 --- a/seasoned_api/test/system/asAnAnonymousUserIWantToSearchForAMovie.js +++ b/seasoned_api/test/system/asAnAnonymousUserIWantToSearchForAMovie.js @@ -2,15 +2,15 @@ const createCacheEntry = require('test/helpers/createCacheEntry'); const resetDatabase = require('test/helpers/resetDatabase'); const request = require('supertest-as-promised'); const app = require('src/webserver/app'); -const interstellarQuerySuccess = require('test/fixtures/interstellar-query-success-response.json'); +const interstellarQuerySuccess = require('test/fixtures/interstellar-query-movie-success-response.json'); describe('As an anonymous user I want to search for a movie', () => { before(() => resetDatabase()); - before(() => createCacheEntry('se:1:multi:interstellar', interstellarQuerySuccess)); + before(() => createCacheEntry('mose:1:interstellar', interstellarQuerySuccess)); it('should return 200 with the search results even if user is not logged in', () => request(app) - .get('/api/v1/tmdb/search?query=interstellar&page=1') + .get('/api/v2/search/movie?query=interstellar&page=1') .expect(200) ); }); diff --git a/seasoned_api/test/unit/tmdb/testConvertTmdbToMovie.js b/seasoned_api/test/unit/tmdb/testConvertTmdbToMovie.js new file mode 100644 index 0000000..64c2e4f --- /dev/null +++ b/seasoned_api/test/unit/tmdb/testConvertTmdbToMovie.js @@ -0,0 +1,30 @@ +const assert = require('assert'); +const convertTmdbToMovie = require('src/tmdb/convertTmdbToMovie'); +const bladeRunnerQuerySuccess = require('test/fixtures/blade_runner_2049-info-success-response.json') + +describe('Convert tmdb movieInfo to movie', () => { + beforeEach(() => this.bladeRunnerTmdbMovie = bladeRunnerQuerySuccess); + + it('should translate the tmdb release date to movie year', () => { + const bladeRunner = convertTmdbToMovie(this.bladeRunnerTmdbMovie); + assert.strictEqual(bladeRunner.year, 2017); + }); + + it('should translate the tmdb release date to instance of Date', () => { + const bladeRunner = convertTmdbToMovie(this.bladeRunnerTmdbMovie); + assert(bladeRunner.release_date instanceof Date); + }); + + it('should translate the tmdb title to title', () => { + const bladeRunner = convertTmdbToMovie(this.bladeRunnerTmdbMovie); + assert.equal(bladeRunner.title, 'Blade Runner 2049'); + }); + + it('should translate the tmdb vote_average to rank', () => { + const bladeRunner = convertTmdbToMovie(this.bladeRunnerTmdbMovie); + assert.equal(bladeRunner.rank, 7.3); + }); + + + +}); diff --git a/seasoned_api/test/unit/tmdb/testTmdb.disabled b/seasoned_api/test/unit/tmdb/testTmdb.disabled new file mode 100644 index 0000000..cb5c5eb --- /dev/null +++ b/seasoned_api/test/unit/tmdb/testTmdb.disabled @@ -0,0 +1,31 @@ +const assert = require('assert'); +// const Movie = require('src/movie/movie'); +const TMDB = require('src/tmdb/tmdb'); +const Cache = require('src/tmdb/cache'); +const SqliteDatabase = require('src/database/sqliteDatabase'); +const tmdbMock = require('test/helpers/tmdbMock'); + +const emptyQuerySuccess = require('test/fixtures/empty-query-success-response.json'); +const interstellarQuerySuccess = require('test/fixtures/arrival-info-success-response.json'); +const popularMovieSuccessResponse = require('test/fixtures/popular-movies-success-response.json'); + +describe('TMDB', function test() { + beforeEach(() => { + this.mockMoviedb = tmdbMock(); + this.database = new SqliteDatabase(':memory:'); + return Promise.resolve() + .then(() => this.database.setUp()); + }); + + describe('popular', () => { + it('should return the "Blade Runner 2049" year in the collection of popular movies', () => { + this.mockMoviedb.response = popularMovieSuccessResponse; + const cache = new Cache(this.database); + const tmdb = new TMDB(cache, 'bogus-api-key', this.mockMoviedb); + return tmdb.popular() + .then(movies => + assert.equal(movies[0].title, "Blade Runner 2049") + ); + }); + }) +});