From f4fee56397021358ecaeb7065a96e3dfdcb61e97 Mon Sep 17 00:00:00 2001 From: "mike.rode" Date: Wed, 13 Feb 2019 00:01:11 -0600 Subject: [PATCH] Parse getUsers response. --- server/services/plexApi/plexApi.js | 5 +- test/server/services/plexApi/index.test.js | 5 +- .../services/plexApi/mocks/parsedResponses.js | 196 +++++++++++++++++- test/server/services/plexApi/plexApi.test.js | 4 +- 4 files changed, 202 insertions(+), 8 deletions(-) diff --git a/server/services/plexApi/plexApi.js b/server/services/plexApi/plexApi.js index 816bf7c..25f80f2 100644 --- a/server/services/plexApi/plexApi.js +++ b/server/services/plexApi/plexApi.js @@ -59,10 +59,11 @@ PlexApiClient.prototype.request = async function(url) { }); }; -PlexApiClient.prototype.getUsers = function() { +PlexApiClient.prototype.getUsers = async function() { const urlParams = this.getUsersUrlParams(); const getUsersUrl = this.buildUrl(urlParams); - return this.request(getUsersUrl); + const response = await this.request(getUsersUrl); + return response.MediaContainer.User; }; const plexApiClient = (options = []) => { diff --git a/test/server/services/plexApi/index.test.js b/test/server/services/plexApi/index.test.js index 5f151df..c1533ee 100644 --- a/test/server/services/plexApi/index.test.js +++ b/test/server/services/plexApi/index.test.js @@ -11,7 +11,6 @@ const should = chai.should(); describe('Users', () => { describe('GET /api/v1/plex/users', async () => { - // Test to get all students record it('should get all plex users', (done) => { const usersResponse = `${__dirname}/mocks/getUsersResponse.xml`; nock('https://plex.tv') @@ -23,8 +22,8 @@ describe('Users', () => { .get('/api/v1/plex/users') .end((err, res) => { res.should.have.status(200); - res.body.should.be.a('object'); - res.body.should.deep.equal(responses.getUsers); + res.body.should.be.a('array'); + res.body.should.deep.equal(responses.getUsersParsed); done(); }); }); diff --git a/test/server/services/plexApi/mocks/parsedResponses.js b/test/server/services/plexApi/mocks/parsedResponses.js index 136bce1..fd2fe04 100644 --- a/test/server/services/plexApi/mocks/parsedResponses.js +++ b/test/server/services/plexApi/mocks/parsedResponses.js @@ -1,5 +1,5 @@ export default { - getUsers: { + getUsersRaw: { MediaContainer: { friendlyName: 'myPlex', identifier: 'com.plexapp.plugins.myplex', @@ -202,4 +202,198 @@ export default { ], }, }, + getUsersParsed: [ + { + id: '22100504', + title: 'e311connell@gmail.com', + username: 'e311connell@gmail.com', + email: 'e311connell@gmail.com', + recommendationsPlaylistId: 'a3ab3b4756506985', + thumb: 'https://plex.tv/users/1a12ace72ecebbff/avatar?c=1549164875', + protected: '0', + home: '0', + allowSync: '0', + allowCameraUpload: '0', + allowChannels: '0', + allowTuners: '0', + allowSubtitleAdmin: '0', + filterAll: '', + filterMovies: '', + filterMusic: '', + filterPhotos: '', + filterTelevision: '', + restricted: '0', + Server: { + id: '11520061', + serverId: '15932286', + machineIdentifier: 'f1adbb16fead548bd0fd8dc723166dfa9ae6cd0a', + name: 'mjrflix', + lastSeenAt: '1549854842', + numLibraries: '2', + allLibraries: '1', + owned: '1', + pending: '0', + }, + }, + { + id: '22099864', + title: 'mike.rode@malauzai.com', + username: 'mike.rode@malauzai.com', + email: 'mike.rode@malauzai.com', + recommendationsPlaylistId: '4f34e0b774a38c55', + thumb: 'https://plex.tv/users/d269a00326accf58/avatar?c=1549783460', + protected: '0', + home: '0', + allowSync: '0', + allowCameraUpload: '0', + allowChannels: '0', + allowTuners: '0', + allowSubtitleAdmin: '0', + filterAll: '', + filterMovies: '', + filterMusic: '', + filterPhotos: '', + filterTelevision: '', + restricted: '0', + Server: { + id: '11519703', + serverId: '15932286', + machineIdentifier: 'f1adbb16fead548bd0fd8dc723166dfa9ae6cd0a', + name: 'mjrflix', + lastSeenAt: '1549854842', + numLibraries: '2', + allLibraries: '1', + owned: '1', + pending: '0', + }, + }, + { + id: '22160998', + title: 'mjrflix+carson@gmail.com', + username: 'mjrflix+carson@gmail.com', + email: 'mjrflix+carson@gmail.com', + recommendationsPlaylistId: 'ffe32f53e19fad28', + thumb: 'https://plex.tv/users/b70f48ce01d53a73/avatar?c=1549214882', + protected: '0', + home: '0', + allowSync: '0', + allowCameraUpload: '0', + allowChannels: '0', + allowTuners: '0', + allowSubtitleAdmin: '0', + filterAll: '', + filterMovies: '', + filterMusic: '', + filterPhotos: '', + filterTelevision: '', + restricted: '0', + Server: { + id: '11562729', + serverId: '15932286', + machineIdentifier: 'f1adbb16fead548bd0fd8dc723166dfa9ae6cd0a', + name: 'mjrflix', + lastSeenAt: '1549854842', + numLibraries: '2', + allLibraries: '1', + owned: '1', + pending: '0', + }, + }, + { + id: '22160913', + title: 'mjrflix+jazz@gmail.com', + username: 'mjrflix+jazz@gmail.com', + email: 'mjrflix+jazz@gmail.com', + recommendationsPlaylistId: '98a2337ca26c7420', + thumb: 'https://plex.tv/users/df0eb846405fb1b6/avatar?c=1549214755', + protected: '0', + home: '0', + allowSync: '0', + allowCameraUpload: '0', + allowChannels: '0', + allowTuners: '0', + allowSubtitleAdmin: '0', + filterAll: '', + filterMovies: '', + filterMusic: '', + filterPhotos: '', + filterTelevision: '', + restricted: '0', + Server: { + id: '11562688', + serverId: '15932286', + machineIdentifier: 'f1adbb16fead548bd0fd8dc723166dfa9ae6cd0a', + name: 'mjrflix', + lastSeenAt: '1549854842', + numLibraries: '2', + allLibraries: '1', + owned: '1', + pending: '0', + }, + }, + { + id: '22161020', + title: 'mjrflix+wade@gmail.com', + username: 'mjrflix+wade@gmail.com', + email: 'mjrflix+wade@gmail.com', + recommendationsPlaylistId: '1d63c4534b40fd82', + thumb: 'https://plex.tv/users/52e6cac0635b4f05/avatar?c=1549214823', + protected: '0', + home: '0', + allowSync: '0', + allowCameraUpload: '0', + allowChannels: '0', + allowTuners: '0', + allowSubtitleAdmin: '0', + filterAll: '', + filterMovies: '', + filterMusic: '', + filterPhotos: '', + filterTelevision: '', + restricted: '0', + Server: { + id: '11562742', + serverId: '15932286', + machineIdentifier: 'f1adbb16fead548bd0fd8dc723166dfa9ae6cd0a', + name: 'mjrflix', + lastSeenAt: '1549854842', + numLibraries: '2', + allLibraries: '1', + owned: '1', + pending: '0', + }, + }, + { + id: '22110937', + title: 'rode4@gmail.com', + username: 'rode4@gmail.com', + email: 'rode4@gmail.com', + recommendationsPlaylistId: 'ccb87923782deff9', + thumb: 'https://plex.tv/users/7c0d31791846bc6a/avatar?c=1548902067', + protected: '0', + home: '0', + allowSync: '0', + allowCameraUpload: '0', + allowChannels: '0', + allowTuners: '0', + allowSubtitleAdmin: '0', + filterAll: '', + filterMovies: '', + filterMusic: '', + filterPhotos: '', + filterTelevision: '', + restricted: '0', + Server: { + id: '11527625', + serverId: '15932286', + machineIdentifier: 'f1adbb16fead548bd0fd8dc723166dfa9ae6cd0a', + name: 'mjrflix', + lastSeenAt: '1549854842', + numLibraries: '2', + allLibraries: '1', + owned: '1', + pending: '0', + }, + }, + ], }; diff --git a/test/server/services/plexApi/plexApi.test.js b/test/server/services/plexApi/plexApi.test.js index dfcd3aa..5dc7018 100644 --- a/test/server/services/plexApi/plexApi.test.js +++ b/test/server/services/plexApi/plexApi.test.js @@ -50,7 +50,7 @@ describe('plexApi', () => { const urlParams = PlexApi.getUsersUrlParams(); const url = PlexApi.buildUrl(urlParams); const result = await PlexApi.request(url); - result.should.deep.equal(parsedResponses.getUsers); + result.should.deep.equal(parsedResponses.getUsersRaw); }); it('returns users using getUsers', async () => { @@ -62,6 +62,6 @@ describe('plexApi', () => { const options = { token: 'plexToken' }; const PlexApi = plexApiClient(options); const result = await PlexApi.getUsers(); - result.should.deep.equal(parsedResponses.getUsers); + result.should.deep.equal(parsedResponses.getUsersParsed); }); });