diff --git a/server/services/plexApi/helpers.js b/server/services/plexApi/helpers.js index bb4daba..918643b 100644 --- a/server/services/plexApi/helpers.js +++ b/server/services/plexApi/helpers.js @@ -5,6 +5,7 @@ const formatResponse = response => { if (xmlResponse) { return JSON.parse(parser.toJson(response.data)); } + // console.log(JSON.stringify(response.data)); return response.data; }; diff --git a/server/services/plexApi/plexApi.js b/server/services/plexApi/plexApi.js index bca5849..af45697 100644 --- a/server/services/plexApi/plexApi.js +++ b/server/services/plexApi/plexApi.js @@ -63,17 +63,13 @@ PlexApiClient.prototype.request = async function(url) { return resolve(formatResponse(response)); }) .catch(error => { - // Error if (error.response) { - // The request was made and the server responded with a status code - // that falls out of the range of 2xx console.log('data', error.response.data); console.log('status', error.response.status); console.log('headers', error.response.headers); return reject(error.response); } if (error.request) { - // The request was made but no response was received console.log('request', error.request); } else { console.log('Error', error.message); diff --git a/test/server/services/plexApi/index.test.js b/test/server/services/plexApi/index.test.js index c201d91..9379eed 100644 --- a/test/server/services/plexApi/index.test.js +++ b/test/server/services/plexApi/index.test.js @@ -31,7 +31,7 @@ describe('Users', () => { }); describe('Most Watched', () => { - describe('GET /api/v1/plex/most-watched', async () => { + describe('GET /api/v1/plex/most-watched?:type', async () => { it('should return most watched history', (done) => { nock('https://plex.mjrflix.com') .get( @@ -52,6 +52,27 @@ describe('Most Watched', () => { }); }); }); + describe('GET /api/v1/plex/most-watched?:accountID&:type', async () => { + it('should return most watched history per account', (done) => { + nock('https://plex.mjrflix.com') + .get( + '/library/all/top?accountID=22099864&type=2&limit=10&X-Plex-Token=hhnKQYskVjepfkhixqJu', + ) + .reply(200, responses.mostWatchedByAccountRaw, { + 'Content-Type': 'text/json', + }); + + chai + .request(app) + .get('/api/v1/plex/most-watched?accountID=22099864&type=2') + .end((err, res) => { + res.should.have.status(200); + res.body.should.be.a('array'); + res.body.should.deep.equal(responses.mostWatchedByAccountParsed); + done(); + }); + }); + }); }); describe('Sections', () => { diff --git a/test/server/services/plexApi/mocks/parsedResponses.js b/test/server/services/plexApi/mocks/parsedResponses.js index 71aee69..695b581 100644 --- a/test/server/services/plexApi/mocks/parsedResponses.js +++ b/test/server/services/plexApi/mocks/parsedResponses.js @@ -1061,4 +1061,405 @@ export default { ], }, ], + mostWatchedByAccountParsed: [ + { + ratingKey: '5485', + key: '/library/metadata/5485/children', + librarySectionTitle: 'TV Shows', + librarySectionID: 3, + librarySectionKey: '/library/sections/3', + studio: 'FOX (US)', + type: 'show', + title: 'New Girl', + contentRating: 'TV-14', + summary: + "Jessica Day is an offbeat and adorable girl in her late 20s who, after a bad breakup, moves in with three single guys. Goofy, positive, vulnerable and honest to a fault, Jess has faith in people, even when she shouldn't. Although she's dorky and awkward, she's comfortable in her own skin. More prone to friendships with women, she's not used to hanging with the boys--especially at home.", + index: 1, + rating: 8, + year: 2011, + thumb: '/library/metadata/5485/thumb/1549851602', + art: '/library/metadata/5485/art/1549851602', + banner: '/library/metadata/5485/banner/1549851602', + theme: '/library/metadata/5485/theme/1549851602', + duration: 1500000, + originallyAvailableAt: '2011-09-20', + leafCount: 132, + viewedLeafCount: 2, + childCount: 7, + addedAt: 1548827347, + updatedAt: 1549851602, + globalViewCount: '80', + userCount: '1', + Genre: [ + { + tag: 'Comedy', + }, + ], + Role: [ + { + tag: 'Damon Wayans Jr.', + }, + { + tag: 'Danielle Rockoff', + }, + { + tag: 'Hannah Simone', + }, + ], + }, + { + ratingKey: '5627', + key: '/library/metadata/5627/children', + librarySectionTitle: 'TV Shows', + librarySectionID: 3, + librarySectionKey: '/library/sections/3', + studio: 'ABC (US)', + type: 'show', + title: 'black-ish', + contentRating: 'TV-14', + summary: + 'An upper-middle-class black man struggles to raise his children with a sense of cultural identity despite constant contradictions and obstacles coming from his liberal wife, old-school father and his assimilated, color-blind kids.', + index: 1, + rating: 8.1, + year: 2014, + thumb: '/library/metadata/5627/thumb/1548828648', + art: '/library/metadata/5627/art/1548828648', + banner: '/library/metadata/5627/banner/1548828648', + theme: '/library/metadata/5627/theme/1548828648', + duration: 1500000, + originallyAvailableAt: '2014-09-24', + leafCount: 106, + viewedLeafCount: 0, + childCount: 5, + addedAt: 1548827357, + updatedAt: 1548828648, + globalViewCount: '21', + userCount: '1', + Genre: [ + { + tag: 'Comedy', + }, + { + tag: 'Family', + }, + ], + Role: [ + { + tag: 'Anthony Anderson', + }, + { + tag: 'August Gross', + }, + { + tag: 'Deon Cole', + }, + ], + }, + { + ratingKey: '8056', + key: '/library/metadata/8056/children', + librarySectionTitle: 'TV Shows', + librarySectionID: 3, + librarySectionKey: '/library/sections/3', + studio: 'HBO', + type: 'show', + title: 'Game of Thrones', + contentRating: 'TV-MA', + summary: + "Seven noble families fight for control of the mythical land of Westeros. Friction between the houses leads to full-scale war. All while a very ancient evil awakens in the farthest north. Amidst the war, a neglected military order of misfits, the Night's Watch, is all that stands between the realms of men and the icy horrors beyond.", + index: 1, + rating: 9.5, + year: 2011, + thumb: '/library/metadata/8056/thumb/1550064900', + art: '/library/metadata/8056/art/1550064900', + banner: '/library/metadata/8056/banner/1550064900', + theme: '/library/metadata/8056/theme/1550064900', + duration: 3300000, + originallyAvailableAt: '2011-04-17', + leafCount: 46, + viewedLeafCount: 0, + childCount: 7, + addedAt: 1549299231, + updatedAt: 1550064900, + globalViewCount: '4', + userCount: '1', + Genre: [ + { + tag: 'Adventure', + }, + { + tag: 'Drama', + }, + ], + Role: [ + { + tag: 'Aidan Gillen', + }, + { + tag: 'Aimee Richardson', + }, + { + tag: 'Alexander Siddig', + }, + ], + }, + { + ratingKey: '5896', + key: '/library/metadata/5896/children', + librarySectionTitle: 'TV Shows', + librarySectionID: 3, + librarySectionKey: '/library/sections/3', + studio: 'Lifetime (US)', + type: 'show', + title: 'Surviving R. Kelly', + contentRating: 'TV-MA', + summary: + 'Celebrated as one of the greatest R&B singers of all time, R. Kelly’s genre defining career and playboy lifestyle has been riddled with rumors of abuse, predatory behavior, and pedophilia. Despite damning evidence and multiple witnesses, to date, none of these accusations have seemingly affected him. For the first time ever, survivors and people from R. Kelly’s inner circle, are coming forward with new allegations about his sexual, mental, and physical abuse. They are now finally ready to share their full story and shed light on the secret life the public has never seen.', + index: 1, + thumb: '/library/metadata/5896/thumb/1548827857', + art: '/library/metadata/5896/art/1548827857', + banner: '/library/metadata/5896/banner/1548827857', + duration: 2700000, + leafCount: 6, + viewedLeafCount: 0, + childCount: 1, + addedAt: 1548827369, + updatedAt: 1548827857, + globalViewCount: '2', + userCount: '1', + Genre: [ + { + tag: 'Documentary', + }, + { + tag: 'Mini-Series', + }, + ], + }, + { + ratingKey: '5335', + key: '/library/metadata/5335/children', + librarySectionTitle: 'TV Shows', + librarySectionID: 3, + librarySectionKey: '/library/sections/3', + studio: 'FX (US)', + type: 'show', + title: 'Louie (2010)', + contentRating: 'TV-MA', + summary: + 'Louis C.K. stars as a fictionalized version of himself; a comedian and newly divorced father raising his two daughters in New York City.', + index: 1, + rating: 8.8, + year: 2010, + thumb: '/library/metadata/5335/thumb/1549004096', + art: '/library/metadata/5335/art/1549004096', + banner: '/library/metadata/5335/banner/1549004096', + theme: '/library/metadata/5335/theme/1549004096', + duration: 1200000, + originallyAvailableAt: '2010-06-29', + leafCount: 34, + viewedLeafCount: 0, + childCount: 3, + addedAt: 1548827341, + updatedAt: 1549004096, + globalViewCount: '1', + userCount: '1', + Genre: [ + { + tag: 'Comedy', + }, + { + tag: 'Drama', + }, + ], + Role: [ + { + tag: 'Hadley Delany', + }, + { + tag: 'Louis C.K.', + }, + { + tag: 'Pamela Adlon', + }, + ], + }, + ], + mostWatchedByAccountRaw: { + MediaContainer: { + size: 5, + allowSync: false, + identifier: 'com.plexapp.plugins.library', + mediaTagPrefix: '/system/bundle/media/flags/', + mediaTagVersion: 1544818278, + Metadata: [ + { + ratingKey: '5485', + key: '/library/metadata/5485/children', + librarySectionTitle: 'TV Shows', + librarySectionID: 3, + librarySectionKey: '/library/sections/3', + studio: 'FOX (US)', + type: 'show', + title: 'New Girl', + contentRating: 'TV-14', + summary: + "Jessica Day is an offbeat and adorable girl in her late 20s who, after a bad breakup, moves in with three single guys. Goofy, positive, vulnerable and honest to a fault, Jess has faith in people, even when she shouldn't. Although she's dorky and awkward, she's comfortable in her own skin. More prone to friendships with women, she's not used to hanging with the boys--especially at home.", + index: 1, + rating: 8, + year: 2011, + thumb: '/library/metadata/5485/thumb/1549851602', + art: '/library/metadata/5485/art/1549851602', + banner: '/library/metadata/5485/banner/1549851602', + theme: '/library/metadata/5485/theme/1549851602', + duration: 1500000, + originallyAvailableAt: '2011-09-20', + leafCount: 132, + viewedLeafCount: 2, + childCount: 7, + addedAt: 1548827347, + updatedAt: 1549851602, + globalViewCount: '80', + userCount: '1', + Genre: [{ tag: 'Comedy' }], + Role: [ + { tag: 'Damon Wayans Jr.' }, + { tag: 'Danielle Rockoff' }, + { tag: 'Hannah Simone' }, + ], + }, + { + ratingKey: '5627', + key: '/library/metadata/5627/children', + librarySectionTitle: 'TV Shows', + librarySectionID: 3, + librarySectionKey: '/library/sections/3', + studio: 'ABC (US)', + type: 'show', + title: 'black-ish', + contentRating: 'TV-14', + summary: + 'An upper-middle-class black man struggles to raise his children with a sense of cultural identity despite constant contradictions and obstacles coming from his liberal wife, old-school father and his assimilated, color-blind kids.', + index: 1, + rating: 8.1, + year: 2014, + thumb: '/library/metadata/5627/thumb/1548828648', + art: '/library/metadata/5627/art/1548828648', + banner: '/library/metadata/5627/banner/1548828648', + theme: '/library/metadata/5627/theme/1548828648', + duration: 1500000, + originallyAvailableAt: '2014-09-24', + leafCount: 106, + viewedLeafCount: 0, + childCount: 5, + addedAt: 1548827357, + updatedAt: 1548828648, + globalViewCount: '21', + userCount: '1', + Genre: [{ tag: 'Comedy' }, { tag: 'Family' }], + Role: [ + { tag: 'Anthony Anderson' }, + { tag: 'August Gross' }, + { tag: 'Deon Cole' }, + ], + }, + { + ratingKey: '8056', + key: '/library/metadata/8056/children', + librarySectionTitle: 'TV Shows', + librarySectionID: 3, + librarySectionKey: '/library/sections/3', + studio: 'HBO', + type: 'show', + title: 'Game of Thrones', + contentRating: 'TV-MA', + summary: + "Seven noble families fight for control of the mythical land of Westeros. Friction between the houses leads to full-scale war. All while a very ancient evil awakens in the farthest north. Amidst the war, a neglected military order of misfits, the Night's Watch, is all that stands between the realms of men and the icy horrors beyond.", + index: 1, + rating: 9.5, + year: 2011, + thumb: '/library/metadata/8056/thumb/1550064900', + art: '/library/metadata/8056/art/1550064900', + banner: '/library/metadata/8056/banner/1550064900', + theme: '/library/metadata/8056/theme/1550064900', + duration: 3300000, + originallyAvailableAt: '2011-04-17', + leafCount: 46, + viewedLeafCount: 0, + childCount: 7, + addedAt: 1549299231, + updatedAt: 1550064900, + globalViewCount: '4', + userCount: '1', + Genre: [{ tag: 'Adventure' }, { tag: 'Drama' }], + Role: [ + { tag: 'Aidan Gillen' }, + { tag: 'Aimee Richardson' }, + { tag: 'Alexander Siddig' }, + ], + }, + { + ratingKey: '5896', + key: '/library/metadata/5896/children', + librarySectionTitle: 'TV Shows', + librarySectionID: 3, + librarySectionKey: '/library/sections/3', + studio: 'Lifetime (US)', + type: 'show', + title: 'Surviving R. Kelly', + contentRating: 'TV-MA', + summary: + 'Celebrated as one of the greatest R&B singers of all time, R. Kelly’s genre defining career and playboy lifestyle has been riddled with rumors of abuse, predatory behavior, and pedophilia. Despite damning evidence and multiple witnesses, to date, none of these accusations have seemingly affected him. For the first time ever, survivors and people from R. Kelly’s inner circle, are coming forward with new allegations about his sexual, mental, and physical abuse. They are now finally ready to share their full story and shed light on the secret life the public has never seen.', + index: 1, + thumb: '/library/metadata/5896/thumb/1548827857', + art: '/library/metadata/5896/art/1548827857', + banner: '/library/metadata/5896/banner/1548827857', + duration: 2700000, + leafCount: 6, + viewedLeafCount: 0, + childCount: 1, + addedAt: 1548827369, + updatedAt: 1548827857, + globalViewCount: '2', + userCount: '1', + Genre: [{ tag: 'Documentary' }, { tag: 'Mini-Series' }], + }, + { + ratingKey: '5335', + key: '/library/metadata/5335/children', + librarySectionTitle: 'TV Shows', + librarySectionID: 3, + librarySectionKey: '/library/sections/3', + studio: 'FX (US)', + type: 'show', + title: 'Louie (2010)', + contentRating: 'TV-MA', + summary: + 'Louis C.K. stars as a fictionalized version of himself; a comedian and newly divorced father raising his two daughters in New York City.', + index: 1, + rating: 8.8, + year: 2010, + thumb: '/library/metadata/5335/thumb/1549004096', + art: '/library/metadata/5335/art/1549004096', + banner: '/library/metadata/5335/banner/1549004096', + theme: '/library/metadata/5335/theme/1549004096', + duration: 1200000, + originallyAvailableAt: '2010-06-29', + leafCount: 34, + viewedLeafCount: 0, + childCount: 3, + addedAt: 1548827341, + updatedAt: 1549004096, + globalViewCount: '1', + userCount: '1', + Genre: [{ tag: 'Comedy' }, { tag: 'Drama' }], + Role: [ + { tag: 'Hadley Delany' }, + { tag: 'Louis C.K.' }, + { tag: 'Pamela Adlon' }, + ], + }, + ], + }, + }, }; diff --git a/test/server/services/plexApi/plexApi.test.js b/test/server/services/plexApi/plexApi.test.js index c9b268c..503c2b5 100644 --- a/test/server/services/plexApi/plexApi.test.js +++ b/test/server/services/plexApi/plexApi.test.js @@ -6,8 +6,6 @@ import nock from 'nock'; import parsedResponses from './mocks/parsedResponses'; import plexApiClient from '../../../../server/services/plexApi/plexApi'; -nock.enableNetConnect; - const should = chai.should(); describe('plexApi', () => {