mirror of
https://github.com/mjrode/WhatToWatch.git
synced 2026-05-07 04:59:09 -05:00
Refactor importData to use custom updateOrCreate function, updated all tests.
This commit is contained in:
@@ -27,7 +27,6 @@ export const fetchPin = () => async dispatch => {
|
||||
|
||||
export const fetchMedia = () => async dispatch => {
|
||||
dispatch({type: types.SET_LOADING, payload: true});
|
||||
console.log('I WAS CALLED MIKE--');
|
||||
const res = await axios.get('/api/plex/import/all');
|
||||
console.log('fetchMedia', res);
|
||||
dispatch({type: types.SET_LOADING, payload: false});
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"test": "cross-env NODE_ENV=test PLEX_API_TOKEN=testPlexApiToken TDAW_API_TOKEN=testTdawToken nyc --reporter=html --reporter=text mocha --require babel-core/register 'test/**/*.test.js' --exit",
|
||||
"debug:test": "cross-env NODE_ENV=test PLEX_API_TOKEN=testPlexApiToken TDAW_API_TOKEN=testTdawToken nyc --reporter=html --reporter=text mocha --inspect-brk --require babel-core/register 'test/**/*.test.js' --exit",
|
||||
"db:clean": "npm run db:drop && npm run db:create && npm run db:migrate",
|
||||
"db:create:test": "NODE_ENV=test npx sequelize db:create",
|
||||
"db:create-migration": "babel-node ./scripts/db/createMigration",
|
||||
|
||||
+192
-3
@@ -1,5 +1,5 @@
|
||||
export default {
|
||||
User: [
|
||||
Users: [
|
||||
{
|
||||
id: 1,
|
||||
firstName: 'Mike',
|
||||
@@ -11,8 +11,197 @@ export default {
|
||||
plexToken: 'testPlexApiToken',
|
||||
sonarrUrl: null,
|
||||
sonarrApiKey: null,
|
||||
createdAt: '2019-09-01 14:36:57.418-05',
|
||||
updatedAt: '2019-09-01 14:37:09.415-05',
|
||||
},
|
||||
{
|
||||
id: 999,
|
||||
firstName: 'Test',
|
||||
lastName: 'User',
|
||||
googleId: '111111111111',
|
||||
email: 'test@email.com',
|
||||
plexUrl: 'https://plex.testlix.com',
|
||||
plexPinId: '11111',
|
||||
plexToken: 'testPlexApiToken',
|
||||
sonarrUrl: null,
|
||||
sonarrApiKey: null,
|
||||
},
|
||||
],
|
||||
|
||||
PlexLibrary: [
|
||||
{
|
||||
id: 1,
|
||||
title: 'Ash vs Evil Dead',
|
||||
type: 'show',
|
||||
views: null,
|
||||
rating_key: 5471,
|
||||
poster_path: null,
|
||||
summary:
|
||||
"Ash has spent the last thirty years avoiding responsibility, maturity, and the terrors of the Evil Dead until a Deadite plague threatens to destroy all of mankind and Ash becomes mankind's only hope. ",
|
||||
rating: 8.7,
|
||||
year: 2015,
|
||||
genre: '[{"tag":"Comedy"},{"tag":"Horror"}]',
|
||||
createdAt: '2019-09-01 18:34:42.659-05',
|
||||
updatedAt: '2019-09-01 18:34:42.796-05',
|
||||
UserId: 999,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
title: 'Anthony Bourdain: Parts Unknown',
|
||||
type: 'show',
|
||||
views: null,
|
||||
rating_key: 8121,
|
||||
poster_path: null,
|
||||
summary:
|
||||
'Bourdain traveled across the globe to uncover little-known areas of the world and celebrate diverse cultures by exploring food and dining rituals. Known for his curiosity, candor, and acerbic wit, Bourdain took viewers off the beaten path of tourist destinations – including some war-torn parts of the world – and met with a variety of local citizens to offer a window into their lifestyles, and occasionally communed with an internationally lauded chef on his journey. We can all hope to find ourselves to enjoy a life as amazing as Anthony Bourdain did. Rest in peace.',
|
||||
rating: 8.3,
|
||||
year: 2013,
|
||||
genre: null,
|
||||
createdAt: '2019-09-01 18:34:42.659-05',
|
||||
updatedAt: '2019-09-01 18:34:42.784-05',
|
||||
UserId: 999,
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
title: 'Atlanta',
|
||||
type: 'show',
|
||||
views: null,
|
||||
rating_key: 6937,
|
||||
poster_path: null,
|
||||
summary:
|
||||
"Two cousins, with different views on art versus commerce, on their way up through the Atlanta rap scene; Earnest 'Earn' Marks, an ambitious college dropout and his estranged cousin, who suddenly becomes a star.",
|
||||
rating: 8.5,
|
||||
year: 2016,
|
||||
genre: '[{"tag":"Comedy"},{"tag":"Drama"}]',
|
||||
createdAt: '2019-09-01 18:34:42.666-05',
|
||||
updatedAt: '2019-09-01 18:34:42.796-05',
|
||||
UserId: 999,
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
title: 'Avatar: The Last Airbender',
|
||||
type: 'show',
|
||||
views: null,
|
||||
rating_key: 7060,
|
||||
poster_path: null,
|
||||
summary:
|
||||
'With the Fire Nation on the brink of global domination, a young girl and her brother discover a 12-year old Airbender who reveals himself as the Avatar. Will this irresponsible kid accept his destiny in time to save the world?',
|
||||
rating: 9,
|
||||
year: 2005,
|
||||
genre: '[{"tag":"Action"},{"tag":"Adventure"}]',
|
||||
createdAt: '2019-09-01 18:34:42.666-05',
|
||||
updatedAt: '2019-09-01 18:34:42.801-05',
|
||||
UserId: 999,
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
title: '30 Rock',
|
||||
type: 'show',
|
||||
views: null,
|
||||
rating_key: 2529,
|
||||
poster_path: null,
|
||||
summary:
|
||||
"Emmy Award Winner Tina Fey writes, executive produces and stars as Liz Lemon, the head writer of a live variety programme in New York City. Liz's life is turned upside down when brash new network executive Jack Donaghy (Alec Baldwin in his Golden Globe winning role) interferes with her show, bringing the wildly unpredictable Tracy Jordan (Tracy Morgan) into the cast. Now its up to Liz to manage the mayhem and still try to have a life.\r\n",
|
||||
rating: 8.6,
|
||||
year: 2006,
|
||||
genre: '[{"tag":"Comedy"}]',
|
||||
createdAt: '2019-09-01 18:34:42.666-05',
|
||||
updatedAt: '2019-09-01 18:34:42.783-05',
|
||||
UserId: 999,
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
title: 'Band of Brothers',
|
||||
type: 'show',
|
||||
views: null,
|
||||
rating_key: 6925,
|
||||
poster_path: null,
|
||||
summary:
|
||||
'The miniseries follows Easy Company, an army unit during World War II, from their initial training at Camp Toccoa to the conclusion of the war. The series is based on the book written by the late Stephen E. Ambrose. \r\n\r\nBand of Brothers is executive produced by Steven Spielberg and Tom Hanks, the series won 6 Emmy Awards. ',
|
||||
rating: 9.4,
|
||||
year: 2001,
|
||||
genre: '[{"tag":"Action"},{"tag":"Adventure"}]',
|
||||
createdAt: '2019-09-01 18:34:42.672-05',
|
||||
updatedAt: '2019-09-01 18:34:42.801-05',
|
||||
UserId: 999,
|
||||
},
|
||||
{
|
||||
id: 7,
|
||||
title: 'Barry',
|
||||
type: 'show',
|
||||
views: null,
|
||||
rating_key: 7026,
|
||||
poster_path: null,
|
||||
summary:
|
||||
'After following his intended target to an acting class, a hitman finds himself intrigued and decides to become an actor and change his life.',
|
||||
rating: 7.8,
|
||||
year: 2018,
|
||||
genre: '[{"tag":"Comedy"},{"tag":"Crime"}]',
|
||||
createdAt: '2019-09-01 18:34:42.672-05',
|
||||
updatedAt: '2019-09-01 18:34:42.801-05',
|
||||
UserId: 999,
|
||||
},
|
||||
{
|
||||
id: 8,
|
||||
title: 'Better Call Saul',
|
||||
type: 'show',
|
||||
views: null,
|
||||
rating_key: 5836,
|
||||
poster_path: null,
|
||||
summary:
|
||||
"See the rise and rise of Jimmy McGill, a small-time lawyer searching for his destiny, but hustling to make ends meet. Working alongside, and often against Jimmy, is ‘fixer’ Mike Erhmantraut. The series tracks Jimmy's evolution into Saul Goodman, the man who puts the word ‘criminal’ in ‘criminal lawyer’.",
|
||||
rating: 8.9,
|
||||
year: 2015,
|
||||
genre: '[{"tag":"Crime"},{"tag":"Drama"}]',
|
||||
createdAt: '2019-09-01 18:34:42.672-05',
|
||||
updatedAt: '2019-09-01 18:34:42.812-05',
|
||||
UserId: 999,
|
||||
},
|
||||
{
|
||||
id: 9,
|
||||
title: 'Big Mouth',
|
||||
type: 'show',
|
||||
views: null,
|
||||
rating_key: 8257,
|
||||
poster_path: null,
|
||||
summary:
|
||||
'Teenage friends find their lives upended by the wonders and horrors of puberty in this edgy comedy from real-life pals Nick Kroll and Andrew Goldberg.',
|
||||
rating: 8.3,
|
||||
year: 2017,
|
||||
genre: '[{"tag":"Animation"},{"tag":"Comedy"}]',
|
||||
createdAt: '2019-09-01 18:34:42.678-05',
|
||||
updatedAt: '2019-09-01 18:34:42.812-05',
|
||||
UserId: 999,
|
||||
},
|
||||
{
|
||||
id: 10,
|
||||
title: 'Big Time in Hollywood, FL',
|
||||
type: 'show before import',
|
||||
views: null,
|
||||
rating_key: 8102,
|
||||
poster_path: null,
|
||||
summary:
|
||||
"Follows two delusional brothers, who are self-proclaimed filmmakers, as they are kicked out of their parent's house and end up on an epic cinematic journey.",
|
||||
rating: 8,
|
||||
year: 2015,
|
||||
genre: '[{"tag":"Comedy"}]',
|
||||
createdAt: '2019-09-01 18:34:42.678-05',
|
||||
updatedAt: '2019-09-01 18:34:42.817-05',
|
||||
UserId: 1,
|
||||
},
|
||||
],
|
||||
PlexSections: [
|
||||
{
|
||||
id: 2,
|
||||
title: 'TV Shows',
|
||||
type: 'show',
|
||||
key: 3,
|
||||
UserId: 999,
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
title: 'Movies',
|
||||
type: 'movie',
|
||||
key: 2,
|
||||
UserId: 999,
|
||||
},
|
||||
],
|
||||
|
||||
|
||||
@@ -6,36 +6,28 @@ import MovieDb from 'moviedb-promise';
|
||||
import {Op} from 'sequelize';
|
||||
const mdb = new MovieDb(config.server.movieApiKey);
|
||||
|
||||
const updateOrCreate = (model, where, newItem, beforeCreate) => {
|
||||
const updateOrCreate = async (model, where, newItem, beforeCreate) => {
|
||||
// Try to find record using findOne
|
||||
return model.findOne({where}).then(item => {
|
||||
if (!item) {
|
||||
// Item doesn't exist, so we create it
|
||||
const item = await model.findOne({where});
|
||||
if (!item) {
|
||||
// Item doesn't exist, so we create it
|
||||
|
||||
// Custom promise to add more data to the record
|
||||
// Being saved (optional)
|
||||
Promise.resolve(beforeCreate).then(() =>
|
||||
model
|
||||
.create(newItem, {returning: true, plain: true, raw: true})
|
||||
.then(item => ({item, created: true})),
|
||||
);
|
||||
}
|
||||
const createItem = await model.create(newItem, {
|
||||
returning: true,
|
||||
plain: true,
|
||||
raw: true,
|
||||
});
|
||||
|
||||
return {createItem, created: true};
|
||||
} else {
|
||||
// Item already exists, so we update it
|
||||
return model
|
||||
.update(
|
||||
newItem,
|
||||
{where: where},
|
||||
{returning: true, plain: true, raw: true},
|
||||
)
|
||||
.then(item => ({item, created: false}));
|
||||
});
|
||||
};
|
||||
|
||||
const importSections = async user => {
|
||||
const sections = await plexApi.getSections(user);
|
||||
const dbSections = await createSections(sections, user);
|
||||
return dbSections;
|
||||
const updatedItem = await model.update(
|
||||
newItem,
|
||||
{where: where},
|
||||
{returning: true, plain: true, raw: true},
|
||||
);
|
||||
return {item, created: false};
|
||||
}
|
||||
};
|
||||
|
||||
const importTvPosters = async user => {
|
||||
@@ -60,6 +52,12 @@ const importTvPosters = async user => {
|
||||
}
|
||||
};
|
||||
|
||||
const importSections = async user => {
|
||||
const sections = await plexApi.getSections(user);
|
||||
const dbSections = await createSections(sections, user);
|
||||
return dbSections;
|
||||
};
|
||||
|
||||
const createSections = async (sections, user) => {
|
||||
const updatedSections = await Promise.map(sections, section => {
|
||||
const newSection = {
|
||||
@@ -72,7 +70,6 @@ const createSections = async (sections, user) => {
|
||||
models.PlexSection,
|
||||
{
|
||||
title: section.title,
|
||||
type: section.type,
|
||||
UserId: user.id,
|
||||
},
|
||||
newSection,
|
||||
@@ -85,9 +82,47 @@ const createSections = async (sections, user) => {
|
||||
|
||||
const importLibraries = async user => {
|
||||
const sections = await plexApi.getSections(user);
|
||||
const dbSections = await createSections(sections, user);
|
||||
return Promise.map(sections, section => {
|
||||
return importLibrary(section.key, user);
|
||||
});
|
||||
}).catch(err => console.log('ImportLibraries', err));
|
||||
};
|
||||
|
||||
const importLibrary = async (sectionKey, user) => {
|
||||
const libraryData = await plexApi.getLibraryDataBySection(
|
||||
{
|
||||
sectionKey,
|
||||
},
|
||||
user,
|
||||
);
|
||||
const dbLibraryData = await createLibrary(libraryData, user);
|
||||
return dbLibraryData;
|
||||
};
|
||||
|
||||
const createLibrary = async (libraryData, user) => {
|
||||
const updatedLibrary = await Promise.map(libraryData, sectionLibraryData => {
|
||||
const newSectionLibraryData = {
|
||||
title: sectionLibraryData.title,
|
||||
type: sectionLibraryData.type,
|
||||
views: sectionLibraryData.views,
|
||||
rating_key: sectionLibraryData.ratingKey,
|
||||
meta_data_path: sectionLibraryData.key,
|
||||
UserId: user.id,
|
||||
summary: sectionLibraryData.summary,
|
||||
rating: sectionLibraryData.rating,
|
||||
year: sectionLibraryData.year,
|
||||
genre: JSON.stringify(sectionLibraryData.Genre),
|
||||
};
|
||||
return updateOrCreate(
|
||||
models.PlexLibrary,
|
||||
{
|
||||
UserId: user.id,
|
||||
title: sectionLibraryData.title,
|
||||
},
|
||||
newSectionLibraryData,
|
||||
);
|
||||
}).catch(err => console.log(err));
|
||||
return updatedLibrary;
|
||||
};
|
||||
|
||||
const importMostWatched = async user => {
|
||||
@@ -107,70 +142,32 @@ const importMostWatchedData = async (sectionKey, user) => {
|
||||
return mostWatchedDbData;
|
||||
};
|
||||
|
||||
const importLibrary = async (sectionKey, user) => {
|
||||
const libraryData = await plexApi.getLibraryDataBySection(
|
||||
{
|
||||
sectionKey,
|
||||
},
|
||||
user,
|
||||
);
|
||||
const dbLibraryData = await createLibrary(libraryData, user);
|
||||
return dbLibraryData;
|
||||
};
|
||||
|
||||
const updateLibrary = (libraryData, user) => {
|
||||
return Promise.map(libraryData, data => {
|
||||
return models.PlexLibrary.upsert(
|
||||
const updateLibrary = async (libraryData, user) => {
|
||||
const updatedLibrary = await Promise.map(libraryData, data => {
|
||||
const newData = {
|
||||
title: data.title,
|
||||
type: data.type,
|
||||
views: data.globalViewCount,
|
||||
rating_key: data.ratingKey,
|
||||
summary: data.summary,
|
||||
UserId: user.id,
|
||||
rating: data.rating,
|
||||
year: data.year,
|
||||
genre: JSON.stringify(data.Genre),
|
||||
};
|
||||
return updateOrCreate(
|
||||
models.PlexLibrary,
|
||||
{
|
||||
title: data.title,
|
||||
type: data.type,
|
||||
views: data.globalViewCount,
|
||||
rating_key: data.ratingKey,
|
||||
summary: data.summary,
|
||||
UserId: user.id,
|
||||
rating: data.rating,
|
||||
year: data.year,
|
||||
genre: JSON.stringify(data.Genre),
|
||||
},
|
||||
{
|
||||
where: {
|
||||
UserId: user.id,
|
||||
title: data.title,
|
||||
},
|
||||
title: data.title,
|
||||
},
|
||||
newData,
|
||||
);
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
};
|
||||
|
||||
const createLibrary = (libraryData, user) => {
|
||||
const userId = user.id;
|
||||
return Promise.map(libraryData, sectionLibraryData => {
|
||||
return models.PlexLibrary.upsert(
|
||||
{
|
||||
title: sectionLibraryData.title,
|
||||
UserId: userId,
|
||||
type: sectionLibraryData.type,
|
||||
views: sectionLibraryData.views,
|
||||
rating_key: sectionLibraryData.ratingKey,
|
||||
meta_data_path: sectionLibraryData.key,
|
||||
UserId: user.id,
|
||||
summary: sectionLibraryData.summary,
|
||||
rating: sectionLibraryData.rating,
|
||||
year: sectionLibraryData.year,
|
||||
genre: JSON.stringify(sectionLibraryData.Genre),
|
||||
},
|
||||
{
|
||||
where: {
|
||||
UserId: user.id,
|
||||
title: sectionLibraryData.title,
|
||||
},
|
||||
},
|
||||
);
|
||||
}).catch(err => console.log(err));
|
||||
};
|
||||
|
||||
export default {
|
||||
importSections,
|
||||
importLibraries,
|
||||
|
||||
+999
-979
File diff suppressed because it is too large
Load Diff
+8
-7
@@ -14,17 +14,18 @@ export const plexSections = () => {
|
||||
});
|
||||
};
|
||||
|
||||
export const plexLibrary = () => nock('https://plex.mjrflix.com')
|
||||
.persist()
|
||||
.get(url => url.includes('/library/sections/'))
|
||||
.reply(200, plexResponses.getLibraryDataBySectionRaw, {
|
||||
'Content-Type': 'text/json',
|
||||
});
|
||||
export const plexLibrary = () =>
|
||||
nock('https://plex.mjrflix.com')
|
||||
.persist()
|
||||
.get(url => url.includes('/library/sections/3'))
|
||||
.reply(200, plexResponses.getLibraryDataBySectionRaw, {
|
||||
'Content-Type': 'text/json',
|
||||
});
|
||||
|
||||
export const plexUsers = () => {
|
||||
nock('https://plex.tv')
|
||||
.get('/api/users?X-Plex-Token=testPlexApiToken')
|
||||
.replyWithFile(200, usersResponse, { 'Content-Type': 'text/xml' });
|
||||
.replyWithFile(200, usersResponse, {'Content-Type': 'text/xml'});
|
||||
};
|
||||
|
||||
export const mostWatched = () => {
|
||||
|
||||
@@ -11,13 +11,15 @@ describe('ImportData', () => {
|
||||
await truncate('User');
|
||||
await truncate('PlexLibrary');
|
||||
await truncate('PlexSection');
|
||||
await seed('User');
|
||||
await seed('User', 'Users');
|
||||
await seed('PlexSection');
|
||||
await seed('PlexSection', 'PlexSections');
|
||||
await seed('PlexLibrary');
|
||||
});
|
||||
after(() => {});
|
||||
|
||||
describe('GET /plex/import/sections', () => {
|
||||
it.only('should find and store sections in the database', async () => {
|
||||
it.only('should find and store sections in the database for the user that is passed in', async () => {
|
||||
nocks.plexSections();
|
||||
|
||||
const user = await models.User.findOne({
|
||||
@@ -25,9 +27,11 @@ describe('ImportData', () => {
|
||||
});
|
||||
|
||||
const sectionsBeforeUpdate = await models.PlexSection.findOne({
|
||||
UserId: 1,
|
||||
type: 'show',
|
||||
title: 'TV Shows',
|
||||
where: {
|
||||
UserId: 1,
|
||||
type: 'show',
|
||||
title: 'TV Shows',
|
||||
},
|
||||
});
|
||||
|
||||
sectionsBeforeUpdate.dataValues.title.should.eq('TV Shows');
|
||||
@@ -38,58 +42,102 @@ describe('ImportData', () => {
|
||||
const sections = await models.PlexSection.findAll();
|
||||
|
||||
const movies = sections.filter(
|
||||
data => data.dataValues.title === 'Movies',
|
||||
data =>
|
||||
data.dataValues.title === 'Movies' &&
|
||||
data.dataValues.UserId === user.id,
|
||||
);
|
||||
|
||||
movies[0].dataValues.title.should.eq('Movies');
|
||||
movies[0].dataValues.type.should.eq('movie');
|
||||
movies[0].dataValues.type.should.eq('movie User 1');
|
||||
movies[0].dataValues.key.should.eq(2);
|
||||
|
||||
const tvShows = sections.filter(
|
||||
data => data.dataValues.title === 'TV Shows',
|
||||
data =>
|
||||
data.dataValues.title === 'TV Shows' &&
|
||||
data.dataValues.UserId === user.id,
|
||||
);
|
||||
tvShows[0].dataValues.title.should.eq('TV Shows');
|
||||
tvShows[0].dataValues.type.should.eq('show');
|
||||
tvShows[0].dataValues.type.should.eq('show User 1');
|
||||
tvShows[0].dataValues.key.should.eq(3);
|
||||
|
||||
sections.should.be.length(2);
|
||||
sections.should.be.length(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /plex/import/libraries', () => {
|
||||
it('should find and store libraries in the database', async () => {
|
||||
nocks.plexSections();
|
||||
nocks.plexLibrary();
|
||||
await importData.importLibraries();
|
||||
const library = await models.PlexLibrary.findAll();
|
||||
library.should.be.length(56);
|
||||
it.only('should find and store libraries in the database for the user that is passed in', async () => {
|
||||
const libraryBeforeImport = await models.PlexLibrary.findAll();
|
||||
libraryBeforeImport.should.be.length(10);
|
||||
|
||||
const user = await models.User.findOne({
|
||||
where: {googleId: '101111197386111111151'},
|
||||
});
|
||||
|
||||
const movieBeforeUpdate = await models.PlexLibrary.findOne({
|
||||
where: {
|
||||
title: 'Big Time in Hollywood, FL',
|
||||
UserId: 1,
|
||||
},
|
||||
});
|
||||
|
||||
movieBeforeUpdate.dataValues.title.should.eq('Big Time in Hollywood, FL');
|
||||
movieBeforeUpdate.dataValues.type.should.eq('show before import');
|
||||
|
||||
const testUserLibrary = await models.PlexLibrary.findAll({
|
||||
where: {UserId: 999},
|
||||
});
|
||||
|
||||
testUserLibrary.should.be.length(9);
|
||||
|
||||
nocks.plexSections();
|
||||
nocks.plexLibrary();
|
||||
await importData.importLibraries();
|
||||
await importData.importLibraries(user);
|
||||
const library = await models.PlexLibrary.findAll();
|
||||
library.should.be.length(65);
|
||||
|
||||
nocks.plexSections();
|
||||
nocks.plexLibrary();
|
||||
await importData.importLibraries(user);
|
||||
const librarySecondRequest = await models.PlexLibrary.findAll();
|
||||
librarySecondRequest.should.be.length(56);
|
||||
librarySecondRequest.should.be.length(65);
|
||||
|
||||
const movieAfterUpdate = await models.PlexLibrary.findOne({
|
||||
where: {
|
||||
title: 'Big Time in Hollywood, FL',
|
||||
UserId: 1,
|
||||
},
|
||||
});
|
||||
|
||||
movieAfterUpdate.dataValues.title.should.eq('Big Time in Hollywood, FL');
|
||||
movieAfterUpdate.dataValues.type.should.eq('show');
|
||||
|
||||
const testUserLibraryAfterImport = await models.PlexLibrary.findAll({
|
||||
where: {UserId: 999},
|
||||
});
|
||||
|
||||
testUserLibraryAfterImport.should.be.length(9);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /plex/import/most-watched', () => {
|
||||
it('should find and store libraries in the database', async () => {
|
||||
it.only('should find and store libraries in the database', async () => {
|
||||
const user = await models.User.findOne({
|
||||
where: {googleId: '101111197386111111151'},
|
||||
});
|
||||
|
||||
nocks.plexSections();
|
||||
nocks.plexLibrary();
|
||||
await importData.importLibraries();
|
||||
await importData.importLibraries(user);
|
||||
const library = await models.PlexLibrary.findAll();
|
||||
library.should.be.length(56);
|
||||
library.should.be.length(65);
|
||||
|
||||
nocks.mostWatched();
|
||||
await importData.importMostWatched();
|
||||
const libraryMostWatched = await models.PlexLibrary.findAll();
|
||||
const newGirl = libraryMostWatched.filter(
|
||||
data => data.dataValues.title === 'New Girl',
|
||||
);
|
||||
newGirl[0].dataValues.views.should.eq(74);
|
||||
newGirl[0].dataValues.poster_path.should.eq(
|
||||
'/library/metadata/5485/children',
|
||||
);
|
||||
libraryMostWatched.should.be.length(56);
|
||||
await importData.importMostWatched(user);
|
||||
const newGirl = await models.PlexLibrary.findOne({
|
||||
where: {UserId: user.id, title: 'New Girl'},
|
||||
});
|
||||
newGirl.dataValues.views.should.eq(74);
|
||||
library.should.be.length(65);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user