Add test for authentication endpoint.

This commit is contained in:
mike.rode
2019-02-23 18:29:18 -06:00
parent 2a32fd445d
commit 32a6cfbad4
13 changed files with 230 additions and 106 deletions

View File

@@ -28,15 +28,18 @@ export default () => {
const port = server.get('port');
sequelize.sync().then(() => {
server.listen(port, () => {
console.log(`Express server listening on - http://${hostname}:${port}`);
});
if (!module.parent) {
server.listen(port, () => {
console.log(
`Express server listening on - http://${hostname}:${port}`,
);
});
}
});
};
process.on('unhandledRejection', (reason, p) => {
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
// application specific logging, throwing an error, or other logic here
});
return {create, start};

View File

@@ -7,7 +7,7 @@ const sequelize = new Sequelize(
{
dialect: 'postgres',
host: 'localhost',
// logging: false,
logging: false,
},
);

View File

@@ -7,6 +7,12 @@ const init = server => {
});
server.use('/api', apiRoute);
server.use((err, req, res, next) => {
if (err) {
console.log('Error in routes/index', err);
}
});
};
export default {

View File

@@ -1,10 +1,10 @@
import uuid from 'uuid/v1';
import uuid from 'uuid';
import btoa from 'btoa';
import request from 'request-promise';
const rxAuthToken = /authenticationToken="([^"]+)"/;
const options = (username, password) => ({
const urlParams = (username, password) => ({
url: 'https://plex.tv/users/sign_in.xml',
headers: {
'X-Plex-Client-Identifier': uuid(),
@@ -18,8 +18,7 @@ const encryptUserCreds = (username, password) => {
};
const fetchToken = async (username, password) => {
const res = await request.post(options(username, password));
console.log(res);
const res = await request.post(urlParams(username, password));
const token = res.match(rxAuthToken)[1];
return token;
};

View File

@@ -30,7 +30,6 @@ const importLibraries = async () => {
const importMostWatched = async req => {
const plexApi = plexApiClient();
const mostWatched = await plexApi.getMostWatched(req);
console.log('6========', mostWatched);
mostWatched.forEach(async libraryData => {
await updateLibrary([libraryData]);
});
@@ -70,7 +69,6 @@ const updateLibrary = libraryData => {
};
const createLibrary = libraryData => {
console.log(libraryData[1]);
libraryData.forEach(async data => {
await models.PlexLibrary.upsert(
{

View File

@@ -8,7 +8,6 @@ const getAuthToken = async (req, res) => {
const {password} = req.query;
auth(username, password).then(data => {
console.log(data);
return res.json(data);
});
};

View File

@@ -74,7 +74,6 @@ const request = async function(url) {
})
.catch(error => {
if (error.response) {
// console.log('data', error.response.data);
console.log('status', error.response.status);
console.log('headers', error.response.headers);
return reject(error.response);
@@ -100,7 +99,6 @@ const getMostWatched = async function(req) {
const urlParams = mostWatchedUrlParams(req);
const mostWatchedUrl = buildUrl(urlParams);
const response = await request(mostWatchedUrl);
console.log(response.MediaContainer.Metadata);
return response.MediaContainer.Metadata;
};