Skip to content

Commit

Permalink
fix(tests): added and updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leocabeza committed Jun 15, 2020
1 parent df01bb3 commit 3c77c08
Show file tree
Hide file tree
Showing 6 changed files with 361 additions and 48 deletions.
224 changes: 224 additions & 0 deletions src/__snapshots__/main.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`main api returns an object with methods 1`] = `
Object {
"account": Object {
"addToWatchlist": [Function],
"details": [Function],
"favoriteMovies": [Function],
"favoriteTvShows": [Function],
"lists": [Function],
"markAsFavorite": [Function],
"movieWatchlist": [Function],
"ratedMovies": [Function],
"ratedTvEpisodes": [Function],
"ratedTvShows": [Function],
"tvShowWatchlist": [Function],
},
"authentication": Object {
"logout": [Function],
"newGuestSession": [Function],
"newSession": [Function],
"newToken": [Function],
"sessionConvert": [Function],
"validateWithLogin": [Function],
},
"certification": Object {
"movies": [Function],
"tvShows": [Function],
},
"change": Object {
"movies": [Function],
"people": [Function],
"tvShows": [Function],
},
"collection": Object {
"details": [Function],
"images": [Function],
"translations": [Function],
},
"company": Object {
"alternativeNames": [Function],
"details": [Function],
"images": [Function],
},
"configuration": Object {
"api": [Function],
"countries": [Function],
"jobs": [Function],
"languages": [Function],
"primaryTranslations": [Function],
"timezones": [Function],
},
"credit": Object {
"details": [Function],
},
"discover": Object {
"movie": [Function],
"tvShows": [Function],
},
"find": Object {
"byId": [Function],
},
"genre": Object {
"movieList": [Function],
"tvList": [Function],
},
"guestSession": Object {
"ratedMovies": [Function],
"ratedTvEpisodes": [Function],
"ratedTvShows": [Function],
},
"keyword": Object {
"details": [Function],
"movies": [Function],
},
"list": Object {
"addMovie": [Function],
"clear": [Function],
"create": [Function],
"details": [Function],
"itemStatus": [Function],
"remove": [Function],
"removeMovie": [Function],
},
"movie": Object {
"accountStates": [Function],
"alternativeTitles": [Function],
"changes": [Function],
"credits": [Function],
"deleteRating": [Function],
"details": [Function],
"externalIds": [Function],
"images": [Function],
"keywords": [Function],
"latest": [Function],
"lists": [Function],
"nowPlaying": [Function],
"popular": [Function],
"rate": [Function],
"recommendations": [Function],
"releaseDates": [Function],
"reviews": [Function],
"similar": [Function],
"topRated": [Function],
"translations": [Function],
"upcoming": [Function],
"videos": [Function],
},
"network": Object {
"alternativeNames": [Function],
"details": [Function],
"images": [Function],
},
"people": Object {
"changes": [Function],
"combinedCredits": [Function],
"details": [Function],
"externalIds": [Function],
"images": [Function],
"latest": [Function],
"movieCredits": [Function],
"popular": [Function],
"taggedImages": [Function],
"translations": [Function],
"tvCredits": [Function],
},
"review": Object {
"details": [Function],
},
"search": Object {
"collections": [Function],
"companies": [Function],
"keywords": [Function],
"movies": [Function],
"multi": [Function],
"people": [Function],
"tv": [Function],
},
"trending": Object {
"items": [Function],
},
"tv": Object {
"accountStates": [Function],
"airingToday": [Function],
"alternativeTitles": [Function],
"changes": [Function],
"contentRatings": [Function],
"credits": [Function],
"deleteRating": [Function],
"details": [Function],
"episodeGroups": [Function],
"externalIds": [Function],
"images": [Function],
"keywords": [Function],
"latest": [Function],
"onTheAir": [Function],
"popular": [Function],
"rate": [Function],
"recommendations": [Function],
"reviews": [Function],
"screenedTheatrically": [Function],
"similar": [Function],
"topRated": [Function],
"translations": [Function],
"videos": [Function],
},
"tvEpisode": Object {
"accountStates": [Function],
"changes": [Function],
"credits": [Function],
"deleteRating": [Function],
"details": [Function],
"externalIds": [Function],
"images": [Function],
"rate": [Function],
"translations": [Function],
"videos": [Function],
},
"tvEpisodeGroup": Object {
"details": [Function],
},
"tvSeason": Object {
"accountStates": [Function],
"changes": [Function],
"credits": [Function],
"details": [Function],
"externalIds": [Function],
"images": [Function],
"videos": [Function],
},
}
`;

exports[`main api returns an object with methods 2`] = `
Object {
"account": Object {
"favoriteMovies": [Function],
"favoriteTvShows": [Function],
"lists": [Function],
"movieRecommendations": [Function],
"movieWatchlist": [Function],
"ratedMovies": [Function],
"ratedTvShows": [Function],
"tvShowRecommendations": [Function],
"tvShowWatchlist": [Function],
},
"authentication": Object {
"createAccessToken": [Function],
"createRequestToken": [Function],
"deleteAccessToken": [Function],
},
"list": Object {
"addItems": [Function],
"clearItems": [Function],
"create": [Function],
"deleteItems": [Function],
"details": [Function],
"itemStatus": [Function],
"remove": [Function],
"update": [Function],
"updateItems": [Function],
},
}
`;
4 changes: 2 additions & 2 deletions src/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('main api', () => {
});

it('returns an object with methods', () => {
expect(typeof entryPoint.v3('v3 api key')).toEqual('object');
expect(typeof entryPoint.v4('v4 api key')).toEqual('object');
expect(entryPoint.v3('v3 api key')).toMatchSnapshot();
expect(entryPoint.v4('v4 api key')).toMatchSnapshot();
});
});
29 changes: 29 additions & 0 deletions src/parser/__snapshots__/parser.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`parser must parse correctly a mocked response 1`] = `
Object {
"page": 1,
"results": Array [
Object {
"adult": false,
"backdrop_path": "/VuukZLgaCrho2Ar8Scl9HtV3yD.jpg",
"genre_ids": Array [
878,
],
"id": 335983,
"original_language": "en",
"original_title": "Venom",
"overview": "When Eddie Brock acquires the powers of a symbiote, he will have to release his alter-ego \\"Venom\\" to save his life.",
"popularity": 240.47,
"poster_path": "/2uNW4WbgBXL25BAbXGLnLqX71Sw.jpg",
"release_date": "2018-10-03",
"title": "Venom",
"video": false,
"vote_average": 6.6,
"vote_count": 2113,
},
],
"total_pages": 993,
"total_results": 19847,
}
`;
26 changes: 1 addition & 25 deletions src/parser/parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,8 @@ import popularMoviesMockResponse from './mock.json';
describe('parser', () => {
it('must parse correctly a mocked response', () => {
const parsedResponse = parseData(popularMoviesMockResponse);
const parsedResponseData = parsedResponse;

expect(typeof parsedResponseData.page === 'number').toBeTruthy();
expect(typeof parsedResponseData.total_pages === 'number').toBeTruthy();
expect(typeof parsedResponseData.total_results === 'number').toBeTruthy();

expect(Array.isArray(parsedResponseData.results)).toBeTruthy();
const firstResult = parsedResponseData.results[0];

expect(typeof firstResult.vote_count === 'number').toBeTruthy();
expect(typeof firstResult.id === 'number').toBeTruthy();
expect(typeof firstResult.video === 'boolean').toBeTruthy();
expect(typeof firstResult.vote_average === 'number').toBeTruthy();
expect(typeof firstResult.title === 'string').toBeTruthy();
expect(typeof firstResult.popularity === 'number').toBeTruthy();
expect(typeof firstResult.poster_path === 'string').toBeTruthy();
expect(typeof firstResult.original_language === 'string').toBeTruthy();
expect(typeof firstResult.original_title === 'string').toBeTruthy();
expect(Array.isArray(firstResult.genre_ids)).toBeTruthy();
expect(
firstResult.genre_ids.every(genreId => typeof genreId === 'number')
).toBeTruthy();
expect(typeof firstResult.backdrop_path === 'string').toBeTruthy();
expect(typeof firstResult.adult === 'boolean').toBeTruthy();
expect(typeof firstResult.overview === 'string').toBeTruthy();
expect(typeof firstResult.release_date === 'string').toBeTruthy();
expect(parsedResponse).toMatchSnapshot();
});

it('must set the same data type that it was passed in key', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const HOST = 'https://api.themoviedb.org/';
let v3Key;
let v4Key;

export const removeUndefinedValues = (paramsObject) => {
const removeUndefinedValues = (paramsObject) => {
const finalParams = {};

Object.keys(paramsObject).forEach((paramKey) => {
Expand Down
Loading

0 comments on commit 3c77c08

Please sign in to comment.