diff --git a/coverage/index.html b/coverage/index.html index d6df1ca..e7c6c1e 100644 --- a/coverage/index.html +++ b/coverage/index.html @@ -20,9 +20,9 @@
- 69.95% + 74.35% Statements - 135/193 + 142/191
66.67% @@ -30,14 +30,14 @@ 16/24
- 50% + 60% Functions - 25/50 + 30/50
- 70.31% + 74.21% Lines - 135/192 + 141/190

@@ -89,15 +89,15 @@ recommend/server -

- 84.21% - 16/19 +
+ 83.33% + 15/18 100% 0/0 50% 3/6 - 84.21% - 16/19 + 83.33% + 15/18 @@ -130,26 +130,26 @@ recommend/server/routes
100% - 4/4 + 3/3 100% 0/0 100% 0/0 100% - 4/4 + 3/3 recommend/server/services/plex -
- 60.16% - 77/128 +
+ 67.19% + 86/128 72.22% 13/18 - 44.74% - 17/38 - 60.63% - 77/127 + 57.89% + 22/38 + 66.93% + 85/127 @@ -158,7 +158,7 @@ diff --git a/coverage/recommend/config/index.html b/coverage/recommend/config/index.html index 7118f1d..f2c3447 100644 --- a/coverage/recommend/config/index.html +++ b/coverage/recommend/config/index.html @@ -106,7 +106,7 @@ diff --git a/coverage/recommend/config/index.js.html b/coverage/recommend/config/index.js.html index 4757aec..2c23c15 100644 --- a/coverage/recommend/config/index.js.html +++ b/coverage/recommend/config/index.js.html @@ -94,7 +94,7 @@ export default {server: _.merge(defaultConfig, envConfig), plex: plexConfig}; diff --git a/coverage/recommend/config/plex.js.html b/coverage/recommend/config/plex.js.html index 35a98ea..7b11bae 100644 --- a/coverage/recommend/config/plex.js.html +++ b/coverage/recommend/config/plex.js.html @@ -73,7 +73,7 @@ export default plexConfig; diff --git a/coverage/recommend/config/test.js.html b/coverage/recommend/config/test.js.html index 018d966..cb913d4 100644 --- a/coverage/recommend/config/test.js.html +++ b/coverage/recommend/config/test.js.html @@ -70,7 +70,7 @@ export default testConfig; diff --git a/coverage/recommend/index.html b/coverage/recommend/index.html index 2da6e7d..d75d151 100644 --- a/coverage/recommend/index.html +++ b/coverage/recommend/index.html @@ -80,7 +80,7 @@ diff --git a/coverage/recommend/index.js.html b/coverage/recommend/index.js.html index 7b99500..12ad7ae 100644 --- a/coverage/recommend/index.js.html +++ b/coverage/recommend/index.js.html @@ -76,7 +76,7 @@ export default server.create(config); diff --git a/coverage/recommend/server/controllers/index.html b/coverage/recommend/server/controllers/index.html index 59398ae..403fe20 100644 --- a/coverage/recommend/server/controllers/index.html +++ b/coverage/recommend/server/controllers/index.html @@ -80,7 +80,7 @@ diff --git a/coverage/recommend/server/controllers/plex.controller.js.html b/coverage/recommend/server/controllers/plex.controller.js.html index 3723805..40bbdb1 100644 --- a/coverage/recommend/server/controllers/plex.controller.js.html +++ b/coverage/recommend/server/controllers/plex.controller.js.html @@ -112,7 +112,7 @@ export default router; diff --git a/coverage/recommend/server/index.html b/coverage/recommend/server/index.html index a6be69d..60cd239 100644 --- a/coverage/recommend/server/index.html +++ b/coverage/recommend/server/index.html @@ -20,9 +20,9 @@
- 84.21% + 83.33% Statements - 16/19 + 15/18
100% @@ -35,9 +35,9 @@ 3/6
- 84.21% + 83.33% Lines - 16/19 + 15/18

@@ -63,15 +63,15 @@ index.js -

- 84.21% - 16/19 +
+ 83.33% + 15/18 100% 0/0 50% 3/6 - 84.21% - 16/19 + 83.33% + 15/18 @@ -80,7 +80,7 @@ diff --git a/coverage/recommend/server/index.js.html b/coverage/recommend/server/index.js.html index d709d97..6fa0f12 100644 --- a/coverage/recommend/server/index.js.html +++ b/coverage/recommend/server/index.js.html @@ -20,9 +20,9 @@
- 84.21% + 83.33% Statements - 16/19 + 15/18
100% @@ -35,9 +35,9 @@ 3/6
- 84.21% + 83.33% Lines - 16/19 + 15/18

@@ -88,8 +88,7 @@ 40 41 42 -43 -44  +43        @@ -119,7 +118,6 @@ 1x   1x -1x       @@ -161,7 +159,6 @@ export default () => {   const port = server.get('port');   - console.log('port', port); sequelize.sync().then(() => { server.listen(port, () => { console.log(`Express server listening on - http://${hostname}:${port}`); @@ -181,7 +178,7 @@ export default () => {

diff --git a/coverage/recommend/server/models/index.html b/coverage/recommend/server/models/index.html index bcce8b9..7f45467 100644 --- a/coverage/recommend/server/models/index.html +++ b/coverage/recommend/server/models/index.html @@ -119,7 +119,7 @@ diff --git a/coverage/recommend/server/models/index.js.html b/coverage/recommend/server/models/index.js.html index 3fc192a..9fde98d 100644 --- a/coverage/recommend/server/models/index.js.html +++ b/coverage/recommend/server/models/index.js.html @@ -136,7 +136,7 @@ export default models; diff --git a/coverage/recommend/server/models/plexLibrary.js.html b/coverage/recommend/server/models/plexLibrary.js.html index 845df04..56f247e 100644 --- a/coverage/recommend/server/models/plexLibrary.js.html +++ b/coverage/recommend/server/models/plexLibrary.js.html @@ -112,7 +112,7 @@ export default plexLibrary; diff --git a/coverage/recommend/server/models/plexSection.js.html b/coverage/recommend/server/models/plexSection.js.html index f944a44..7e75d54 100644 --- a/coverage/recommend/server/models/plexSection.js.html +++ b/coverage/recommend/server/models/plexSection.js.html @@ -97,7 +97,7 @@ export default plexSection; diff --git a/coverage/recommend/server/models/user.js.html b/coverage/recommend/server/models/user.js.html index 914aae5..6fb11c0 100644 --- a/coverage/recommend/server/models/user.js.html +++ b/coverage/recommend/server/models/user.js.html @@ -142,7 +142,7 @@ export default user; diff --git a/coverage/recommend/server/routes/index.html b/coverage/recommend/server/routes/index.html index f1a22f1..d8bd03a 100644 --- a/coverage/recommend/server/routes/index.html +++ b/coverage/recommend/server/routes/index.html @@ -22,7 +22,7 @@
100% Statements - 4/4 + 3/3
100% @@ -37,7 +37,7 @@
100% Lines - 4/4 + 3/3

@@ -65,13 +65,13 @@ plex.route.js

100% - 4/4 + 3/3 100% 0/0 100% 0/0 100% - 4/4 + 3/3 @@ -80,7 +80,7 @@ diff --git a/coverage/recommend/server/routes/plex.route.js.html b/coverage/recommend/server/routes/plex.route.js.html index 5de0769..54abb86 100644 --- a/coverage/recommend/server/routes/plex.route.js.html +++ b/coverage/recommend/server/routes/plex.route.js.html @@ -22,7 +22,7 @@
100% Statements - 4/4 + 3/3
100% @@ -37,7 +37,7 @@
100% Lines - 4/4 + 3/3

@@ -55,15 +55,13 @@ 7 8 9 -10 -11  +10    1x   1x   1x -1x      

import plexController from '../controllers/plex.controller';
@@ -72,7 +70,6 @@ const express = require('express');
  
 const router = express.Router();
  
-console.log('Made it here');
 router.use(plexController);
  
 export default router;
@@ -82,7 +79,7 @@ export default router;
 
 
 
 
diff --git a/coverage/recommend/server/services/plex/auth.js.html b/coverage/recommend/server/services/plex/auth.js.html
index a80bfb1..61592ac 100644
--- a/coverage/recommend/server/services/plex/auth.js.html
+++ b/coverage/recommend/server/services/plex/auth.js.html
@@ -20,9 +20,9 @@
     
     
- 40% + 100% Statements - 4/10 + 10/10
100% @@ -30,21 +30,21 @@ 0/0
- 0% + 100% Functions - 0/3 + 3/3
- 44.44% + 100% Lines - 4/9 + 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

-
+

-	
-	
-	
-	
+	
+	
+	
+	
-	
-	
-	
-	
+	
+	
+	
+	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
@@ -102,28 +102,28 @@
 
 
-	
-	
-	
+	
+	
+	
-	
-	
-	
-	
+	
+	
+	
+	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
@@ -132,7 +132,7 @@
 
diff --git a/coverage/recommend/server/services/plex/index.js.html b/coverage/recommend/server/services/plex/index.js.html
index 8429ff0..a88954a 100644
--- a/coverage/recommend/server/services/plex/index.js.html
+++ b/coverage/recommend/server/services/plex/index.js.html
@@ -20,9 +20,9 @@
     
- 60% + 70% Statements - 18/30 + 21/30
100% @@ -30,14 +30,14 @@ 0/0
- 44.44% + 66.67% Functions - 4/9 + 6/9
- 60% + 70% Lines - 18/30 + 21/30

@@ -115,16 +115,15 @@     1x -  -  -  -  -  -  -  +1x +1x   1x 1x +  +  +  +1x 1x 1x   @@ -145,6 +144,7 @@ 1x     +        @@ -178,17 +178,16 @@ import importData from './importData'; import auth from './auth';   -const getAuthToken = async (req, res) => { - const {username} = req.query; - const {password} = req.query; +const getAuthToken = async (req, res) => { + const {username} = req.query; + const {password} = req.query;   - auth(username, password).then(data => { - return res.json(data); + auth(username, password).then(data => { + return res.json(data); }); };   const getUsers = async (req, res) => { - console.log('getUsers-mike-'); const users = await plexApi.getUsers(); res.json(users); }; @@ -209,6 +208,7 @@ const getLibraryDataBySection = async (req, res) => { res.json(sections); } catch (error) { console.log(error); + res.json(error); } };   @@ -244,7 +244,7 @@ export default {

diff --git a/coverage/recommend/server/services/plex/plexApi.js.html b/coverage/recommend/server/services/plex/plexApi.js.html index 8ba1b56..b976847 100644 --- a/coverage/recommend/server/services/plex/plexApi.js.html +++ b/coverage/recommend/server/services/plex/plexApi.js.html @@ -20,31 +20,31 @@
- 79.63% + 96.77% Statements - 43/54 + 30/31
- 68.75% + 91.67% Branches - 11/16 + 11/12
- 92.31% + 100% Functions - 12/13 + 8/8
- 79.63% + 96.77% Lines - 43/54 + 30/31

Press n or j to go to the next uncovered block, b, p or k for the previous block.

-
+
1 2 @@ -87,14 +87,14 @@     1x -  -  +1x +1x     1x -  -  -  +1x +1x +1x       @@ -104,7 +104,7 @@ import request from 'request-promise';   const rxAuthToken = /authenticationToken="([^"]+)"/;   -const urlParams = (username, password) => ({ +const urlParams = (username, password) => ({ url: 'https://plex.tv/users/sign_in.xml', headers: { 'X-Plex-Client-Identifier': uuid(), @@ -112,15 +112,15 @@ const urlParams = (u }, });   -const encryptUserCreds = (username, password) => { - const creds = `${username}:${password}`; - return btoa(creds); +const encryptUserCreds = (username, password) => { + const creds = `${username}:${password}`; + return btoa(creds); };   -const fetchToken = async (username, password) => { - const res = await request.post(urlParams(username, password)); - const token = res.match(rxAuthToken)[1]; - return token; +const fetchToken = async (username, password) => { + const res = await request.post(urlParams(username, password)); + const token = res.match(rxAuthToken)[1]; + return token; };   export default fetchToken; @@ -130,7 +130,7 @@ export default fetchToken; diff --git a/coverage/recommend/server/services/plex/helpers.js.html b/coverage/recommend/server/services/plex/helpers.js.html index 676e62b..afe1c79 100644 --- a/coverage/recommend/server/services/plex/helpers.js.html +++ b/coverage/recommend/server/services/plex/helpers.js.html @@ -20,31 +20,31 @@
- 100% + 64.29% Statements - 5/5 + 18/28
- 100% + 33.33% Branches - 2/2 + 2/6
- 100% + 83.33% Functions - 1/1 + 5/6
- 100% + 64.29% Lines - 5/5 + 18/28

Press n or j to go to the next uncovered block, b, p or k for the previous block.

-
+
1 2 @@ -57,7 +57,50 @@ 9 10 11 -12  +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53  +  +    1x 7x @@ -67,8 +110,49 @@ 4x     +1x +8x +8x +8x +8x +8x   - 
import parser from 'xml2json';
+8x
+ 
+ 
+ 
+ 
+ 
+ 
+1x
+7x
+7x
+7x
+7x
+ 
+ 
+7x
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
import axios from 'axios';
+import parser from 'xml2json';
+import buildUrlLibrary from 'build-url';
  
 const formatResponse = response => {
   const xmlResponse = response.headers['content-type'].includes('xml');
@@ -78,14 +162,53 @@ const formatResponse = response => {
   return response.data;
 };
  
-export default formatResponse;
+const buildUrl = function(urlParams) {
+  try {
+    const params = urlParams;
+    const {host} = params;
+    delete params.host;
+    const urlHash = params;
+ 
+    return buildUrlLibrary(host, urlHash);
+  } catch (error) {
+    console.log(error);
+    return error;
+  }
+};
+ 
+const request = async function(url) {
+  console.log('Request URL', url);
+  return new Promise((resolve, reject) => {
+    const httpClient = axios;
+    httpClient
+      .get(url)
+      .then(response => {
+        return resolve(formatResponse(response));
+      })
+      .catch(error => {
+        if (error.response) {
+          console.log('status', error.response.status);
+          console.log('headers', error.response.headers);
+          return reject(error.response);
+        }
+        if (error.request) {
+          console.log('request', error.request);
+        } else {
+          console.log('Error', error.message);
+        }
+        return reject(error);
+      });
+  });
+};
+ 
+export default {formatResponse, buildUrl, request};
  
diff --git a/coverage/recommend/server/services/plex/importData.js.html b/coverage/recommend/server/services/plex/importData.js.html index 3cc76fc..3e345c3 100644 --- a/coverage/recommend/server/services/plex/importData.js.html +++ b/coverage/recommend/server/services/plex/importData.js.html @@ -337,7 +337,7 @@ export default {importSections, importLibraries, importMostWatched}; diff --git a/coverage/recommend/server/services/plex/index.html b/coverage/recommend/server/services/plex/index.html index 67e096d..8b1791a 100644 --- a/coverage/recommend/server/services/plex/index.html +++ b/coverage/recommend/server/services/plex/index.html @@ -20,9 +20,9 @@
- 60.16% + 67.19% Statements - 77/128 + 86/128
72.22% @@ -30,14 +30,14 @@ 13/18
- 44.74% + 57.89% Functions - 17/38 + 22/38
- 60.63% + 66.93% Lines - 77/127 + 85/127

@@ -62,29 +62,29 @@

auth.js
40%4/10auth.js
100%10/10 100% 0/00%0/344.44%4/9100%3/3100%9/9
helpers.js
100%5/5100%2/2100%1/1100%5/5helpers.js
64.29%18/2833.33%2/683.33%5/664.29%18/28
index.js
60%18/30
70%21/30 100% 0/044.44%4/960%18/3066.67%6/970%21/30
plexApi.js
79.63%43/5468.75%11/1692.31%12/1379.63%43/54plexApi.js
96.77%30/3191.67%11/12100%8/896.77%30/31
1 2 @@ -136,52 +136,7 @@ 88 89 90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134  -  -  +91      1x @@ -231,45 +186,6 @@     1x -8x -8x -8x -8x -8x -  -8x -  -  -  -  -  -  -1x -7x -7x -7x -7x -  -  -7x -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -1x 2x 2x 2x @@ -310,12 +226,8 @@       -  -  - 
import axios from 'axios';
-import buildUrlPack from 'build-url';
-import config from '../../../config';
-import formatResponse from './helpers';
+ 
import config from '../../../config';
+import helpers from './helpers';
  
 const getUsersUrlParams = function() {
   return {
@@ -363,71 +275,32 @@ const getLibraryDataBySectionUrlParams = function(req) {
   };
 };
  
-const buildUrl = function(urlParams) {
-  try {
-    const params = urlParams;
-    const {host} = params;
-    delete params.host;
-    const urlHash = params;
- 
-    return buildUrlPack(host, urlHash);
-  } catch (error) {
-    console.log(error);
-    return error;
-  }
-};
- 
-const request = async function(url) {
-  console.log('Request URL', url);
-  return new Promise((resolve, reject) => {
-    const httpClient = axios;
-    httpClient
-      .get(url)
-      .then(response => {
-        return resolve(formatResponse(response));
-      })
-      .catch(error => {
-        if (error.response) {
-          console.log('status', error.response.status);
-          console.log('headers', error.response.headers);
-          return reject(error.response);
-        }
-        if (error.request) {
-          console.log('request', error.request);
-        } else {
-          console.log('Error', error.message);
-        }
-        return reject(error);
-      });
-  });
-};
- 
 const getUsers = async function() {
   const urlParams = getUsersUrlParams();
-  const getUsersUrl = buildUrl(urlParams);
-  const response = await request(getUsersUrl);
+  const getUsersUrl = helpers.buildUrl(urlParams);
+  const response = await helpers.request(getUsersUrl);
   return response.MediaContainer.User;
 };
  
 const getMostWatched = async function(req) {
   const urlParams = mostWatchedUrlParams(req);
-  const mostWatchedUrl = buildUrl(urlParams);
-  const response = await request(mostWatchedUrl);
+  const mostWatchedUrl = helpers.buildUrl(urlParams);
+  const response = await helpers.request(mostWatchedUrl);
   return response.MediaContainer.Metadata;
 };
  
 const getSections = async function() {
   const urlParams = getSectionsUrlParams();
-  const getSectionsUrl = buildUrl(urlParams);
-  const response = await request(getSectionsUrl);
+  const getSectionsUrl = helpers.buildUrl(urlParams);
+  const response = await helpers.request(getSectionsUrl);
   return response.MediaContainer.Directory;
 };
  
 const getLibraryDataBySection = async function(req) {
   try {
     const urlParams = getLibraryDataBySectionUrlParams(req);
-    const getLibraryDataBySectionUrl = buildUrl(urlParams);
-    const response = await request(getLibraryDataBySectionUrl);
+    const getLibraryDataBySectionUrl = helpers.buildUrl(urlParams);
+    const response = await helpers.request(getLibraryDataBySectionUrl);
     return response.MediaContainer.Metadata;
   } catch (error) {
     return error;
@@ -442,8 +315,6 @@ export default {
   getUsersUrlParams,
   getLibraryDataBySectionUrlParams,
   getSectionsUrlParams,
-  buildUrl,
-  request,
 };
  
@@ -451,7 +322,7 @@ export default { diff --git a/server/index.js b/server/index.js index 34e7af5..032c2f9 100644 --- a/server/index.js +++ b/server/index.js @@ -27,7 +27,6 @@ export default () => { const port = server.get('port'); - console.log('port', port); sequelize.sync().then(() => { server.listen(port, () => { console.log(`Express server listening on - http://${hostname}:${port}`); diff --git a/server/routes/plex.route.js b/server/routes/plex.route.js index f9c9a36..3f5c549 100644 --- a/server/routes/plex.route.js +++ b/server/routes/plex.route.js @@ -4,7 +4,6 @@ const express = require('express'); const router = express.Router(); -console.log('Made it here'); router.use(plexController); export default router; diff --git a/server/services/plex/helpers.js b/server/services/plex/helpers.js index bb4daba..cd3dd2a 100644 --- a/server/services/plex/helpers.js +++ b/server/services/plex/helpers.js @@ -1,4 +1,6 @@ +import axios from 'axios'; import parser from 'xml2json'; +import buildUrlLibrary from 'build-url'; const formatResponse = response => { const xmlResponse = response.headers['content-type'].includes('xml'); @@ -8,4 +10,43 @@ const formatResponse = response => { return response.data; }; -export default formatResponse; +const buildUrl = function(urlParams) { + try { + const params = urlParams; + const {host} = params; + delete params.host; + const urlHash = params; + + return buildUrlLibrary(host, urlHash); + } catch (error) { + console.log(error); + return error; + } +}; + +const request = async function(url) { + console.log('Request URL', url); + return new Promise((resolve, reject) => { + const httpClient = axios; + httpClient + .get(url) + .then(response => { + return resolve(formatResponse(response)); + }) + .catch(error => { + if (error.response) { + console.log('status', error.response.status); + console.log('headers', error.response.headers); + return reject(error.response); + } + if (error.request) { + console.log('request', error.request); + } else { + console.log('Error', error.message); + } + return reject(error); + }); + }); +}; + +export default {formatResponse, buildUrl, request}; diff --git a/server/services/plex/index.js b/server/services/plex/index.js index 4f55e62..8cc95ca 100644 --- a/server/services/plex/index.js +++ b/server/services/plex/index.js @@ -12,7 +12,6 @@ const getAuthToken = async (req, res) => { }; const getUsers = async (req, res) => { - console.log('getUsers-mike-'); const users = await plexApi.getUsers(); res.json(users); }; @@ -33,6 +32,7 @@ const getLibraryDataBySection = async (req, res) => { res.json(sections); } catch (error) { console.log(error); + res.json(error); } }; diff --git a/server/services/plex/plexApi.js b/server/services/plex/plexApi.js index b88257e..45c7f8d 100644 --- a/server/services/plex/plexApi.js +++ b/server/services/plex/plexApi.js @@ -1,7 +1,5 @@ -import axios from 'axios'; -import buildUrlPack from 'build-url'; import config from '../../../config'; -import formatResponse from './helpers'; +import helpers from './helpers'; const getUsersUrlParams = function() { return { @@ -49,71 +47,32 @@ const getLibraryDataBySectionUrlParams = function(req) { }; }; -const buildUrl = function(urlParams) { - try { - const params = urlParams; - const {host} = params; - delete params.host; - const urlHash = params; - - return buildUrlPack(host, urlHash); - } catch (error) { - console.log(error); - return error; - } -}; - -const request = async function(url) { - console.log('Request URL', url); - return new Promise((resolve, reject) => { - const httpClient = axios; - httpClient - .get(url) - .then(response => { - return resolve(formatResponse(response)); - }) - .catch(error => { - if (error.response) { - console.log('status', error.response.status); - console.log('headers', error.response.headers); - return reject(error.response); - } - if (error.request) { - console.log('request', error.request); - } else { - console.log('Error', error.message); - } - return reject(error); - }); - }); -}; - const getUsers = async function() { const urlParams = getUsersUrlParams(); - const getUsersUrl = buildUrl(urlParams); - const response = await request(getUsersUrl); + const getUsersUrl = helpers.buildUrl(urlParams); + const response = await helpers.request(getUsersUrl); return response.MediaContainer.User; }; const getMostWatched = async function(req) { const urlParams = mostWatchedUrlParams(req); - const mostWatchedUrl = buildUrl(urlParams); - const response = await request(mostWatchedUrl); + const mostWatchedUrl = helpers.buildUrl(urlParams); + const response = await helpers.request(mostWatchedUrl); return response.MediaContainer.Metadata; }; const getSections = async function() { const urlParams = getSectionsUrlParams(); - const getSectionsUrl = buildUrl(urlParams); - const response = await request(getSectionsUrl); + const getSectionsUrl = helpers.buildUrl(urlParams); + const response = await helpers.request(getSectionsUrl); return response.MediaContainer.Directory; }; const getLibraryDataBySection = async function(req) { try { const urlParams = getLibraryDataBySectionUrlParams(req); - const getLibraryDataBySectionUrl = buildUrl(urlParams); - const response = await request(getLibraryDataBySectionUrl); + const getLibraryDataBySectionUrl = helpers.buildUrl(urlParams); + const response = await helpers.request(getLibraryDataBySectionUrl); return response.MediaContainer.Metadata; } catch (error) { return error; @@ -128,6 +87,4 @@ export default { getUsersUrlParams, getLibraryDataBySectionUrlParams, getSectionsUrlParams, - buildUrl, - request, }; diff --git a/test/server/services/plex/auth.test.js b/test/server/services/plex/auth.test.js index 2d52a0b..41ac2aa 100644 --- a/test/server/services/plex/auth.test.js +++ b/test/server/services/plex/auth.test.js @@ -1,32 +1,32 @@ -// import chai from 'chai'; -// import chaiHttp from 'chai-http'; -// import nock from 'nock'; -// import sinon from 'sinon'; -// import responses from './mocks/plexResponses'; -// import app from '../../../../index'; +import chai from 'chai'; +import chaiHttp from 'chai-http'; +import nock from 'nock'; +import sinon from 'sinon'; +import responses from './mocks/plexResponses'; +import app from '../../../../index'; -// chai.use(chaiHttp); -// const should = chai.should(); -// describe('Users', () => { -// describe('GET /api/v1/plex/auth', async () => { -// it('should get plex auth token', (done) => { -// const response = `${__dirname}/mocks/authResponse.xml`; -// nock('https://plex.tv') -// .post(uri => uri.includes('/users/sign_in.xml')) -// .replyWithFile(200, response, { -// 'Content-Type': 'text/xml', -// }); +chai.use(chaiHttp); +const should = chai.should(); +describe('Users', () => { + describe('GET /api/v1/plex/auth', async () => { + it('should get plex auth token', (done) => { + const response = `${__dirname}/mocks/authResponse.xml`; + nock('https://plex.tv') + .post(uri => uri.includes('/users/sign_in.xml')) + .replyWithFile(200, response, { + 'Content-Type': 'text/xml', + }); -// chai -// .request(app) -// .get('/api/v1/plex/auth') -// .query({ username: 'username', password: 'password' }) -// .end((err, res) => { -// console.log('mike', res.body); -// res.should.have.status(200); -// res.body.should.equal('testPlexApiToken'); -// done(); -// }); -// }); -// }); -// }); + chai + .request(app) + .get('/plex/auth') + .query({ username: 'username', password: 'password' }) + .end((err, res) => { + console.log('mike', res.body); + res.should.have.status(200); + res.body.should.equal('testPlexApiToken'); + done(); + }); + }); + }); +}); diff --git a/test/server/services/plex/index.test.js b/test/server/services/plex/index.test.js index 192daa0..0d43677 100644 --- a/test/server/services/plex/index.test.js +++ b/test/server/services/plex/index.test.js @@ -48,6 +48,7 @@ describe('Most Watched', () => { }); }); }); + describe('GET plex/most-watched?:accountID&:type', async () => { it('should return most watched history per account', (done) => { nock('https://plex.mjrflix.com') diff --git a/test/server/services/plex/plexApi.test.js b/test/server/services/plex/plexApi.test.js index dc82b08..756bd76 100644 --- a/test/server/services/plex/plexApi.test.js +++ b/test/server/services/plex/plexApi.test.js @@ -1,12 +1,7 @@ -import request from 'supertest'; -import mocha from 'mocha'; -import chai from 'chai'; -import chaiHttp from 'chai-http'; import nock from 'nock'; import plexResponses from './mocks/plexResponses'; import plexApi from '../../../../server/services/plex/plexApi'; - -const should = chai.should(); +import helpers from '../../../../server/services/plex/helpers'; describe('plexApi', () => { it('return url params object', () => { @@ -23,7 +18,7 @@ describe('plexApi', () => { it('returns url', () => { const PlexApi = plexApi; const urlParams = PlexApi.getUsersUrlParams(); - const url = PlexApi.buildUrl(urlParams); + const url = helpers.buildUrl(urlParams); url.should.equal('https://plex.tv/api/users?X-Plex-Token=testPlexApiToken'); }); @@ -35,8 +30,8 @@ describe('plexApi', () => { const PlexApi = plexApi; const urlParams = PlexApi.getUsersUrlParams(); - const url = PlexApi.buildUrl(urlParams); - const result = await PlexApi.request(url); + const url = helpers.buildUrl(urlParams); + const result = await helpers.request(url); result.should.deep.equal(plexResponses.getUsersRaw); });