@ -42,6 +42,25 @@ const { uuid } = require('uuidv4');
db _api . initialize ( db , users _db ) ;
const sample _video _json = {
id : "Sample Video" ,
title : "Sample Video" ,
thumbnailURL : "https://sampleurl.jpg" ,
isAudio : false ,
duration : 177.413 ,
url : "sampleurl.com" ,
uploader : "Sample Uploader" ,
size : 2838445 ,
path : "users\\admin\\video\\Sample Video.mp4" ,
upload _date : "2017-07-28" ,
description : null ,
view _count : 230 ,
abr : 128 ,
thumbnailPath : null ,
user _uid : "admin" ,
uid : "1ada04ab-2773-4dd4-bbdd-3e2d40761c50" ,
registered : 1628469039377
}
describe ( 'Database' , async function ( ) {
describe ( 'Import' , async function ( ) {
@ -214,7 +233,7 @@ describe('Database', async function() {
for ( let i = 0 ; i < NUM _RECORDS _TO _ADD ; i ++ ) {
const uid = uuid ( ) ;
if ( i === NUM _RECORDS _TO _ADD / 2 ) random _uid = uid ;
test _records . push ( { "id" : " A$AP Mob - Yamborghini High (Official Music Video) ft. Juicy J", "title" : "A$AP Mob - Yamborghini High (Official Music Video) ft. Juicy J" , "thumbnailURL" : "https://i.ytimg.com/vi/tt7gP_IW-1w /maxresdefault.jpg", "isAudio" : true , "duration" : 312 , "url" : "https://www.youtube.com/watch?v= tt7gP_IW-1w", "uploader" : "asapmobVEVO ", "size" : 5060157 , "path" : "audio\\ A$AP Mob - Yamborghini High (Official Music Video) ft. Juicy J .mp3", "upload_date" : "2016-05-11" , "description" : " A$AP Mob ft. Juicy J - \"Yamborghini High\" Get it now on:\niTunes: http://smarturl.it/iYAMH?IQid=yt\nListen on Spotify: http://smarturl.it/sYAMH?IQid=yt\nGoogle Play: http://smarturl.it/gYAMH?IQid=yt\nAmazon: http://smarturl.it/aYAMH?IQid=yt\n\nFollow A$AP Mob:\nhttps://www.facebook.com/asapmobofficial\nhttps://twitter.com/ASAPMOB\nhttp://instagram.com/asapmob \nhttp://www.asapmob.com/\n\n#AsapMob #YamborghiniHigh #Vevo #HipHop #OfficialMusicVideo #JuicyJ ", "view_count" : 118689353 , "height" : null , "abr" : 160 , "uid" : uid , "registered" : 1626672120632 } ) ;
test _records . push ( { "id" : " RandomTextRandomText", "title" : "RandomTextRandomTextRandomTextRandomTextRandomTextRandomTextRandomTextRandomText" , "thumbnailURL" : "https://i.ytimg.com/vi/randomurl /maxresdefault.jpg", "isAudio" : true , "duration" : 312 , "url" : "https://www.youtube.com/watch?v= randomvideo", "uploader" : "randomUploader ", "size" : 5060157 , "path" : "audio\\ RandomTextRandomText .mp3", "upload_date" : "2016-05-11" , "description" : " RandomTextRandomTextRandomTextRandomTextRandomTextRandomTextRandomTextRandomTextRandomTextRandomTextRandomTextRandomText ", "view_count" : 118689353 , "height" : null , "abr" : 160 , "uid" : uid , "registered" : 1626672120632 } ) ;
}
const insert _start = Date . now ( ) ;
let success = await db _api . bulkInsertRecordsIntoTable ( 'test' , test _records ) ;
@ -235,6 +254,30 @@ describe('Database', async function() {
assert ( success ) ;
} ) ;
} ) ;
describe ( 'Local DB Filters' , async function ( ) {
it ( 'Basic' , async function ( ) {
const result = db _api . applyFilterLocalDB ( [ { test : 'test' } , { test : 'test1' } ] , { test : 'test' } , 'find' ) ;
assert ( result && result [ 'test' ] === 'test' ) ;
} ) ;
it ( 'Regex' , async function ( ) {
const filter = { $regex : ` \\ w+ \\ d ` , $options : 'i' } ;
const result = db _api . applyFilterLocalDB ( [ { test : 'test' } , { test : 'test1' } ] , { test : filter } , 'find' ) ;
assert ( result && result [ 'test' ] === 'test1' ) ;
} ) ;
it ( 'Not equals' , async function ( ) {
const filter = { $ne : 'test' } ;
const result = db _api . applyFilterLocalDB ( [ { test : 'test' } , { test : 'test1' } ] , { test : filter } , 'find' ) ;
assert ( result && result [ 'test' ] === 'test1' ) ;
} ) ;
it ( 'Nested' , async function ( ) {
const result = db _api . applyFilterLocalDB ( [ { test1 : { test2 : 'test3' } } , { test4 : 'test5' } ] , { 'test1.test2' : 'test3' } , 'find' ) ;
assert ( result && result [ 'test1' ] [ 'test2' ] === 'test3' ) ;
} ) ;
} )
} ) ;
describe ( 'Multi User' , async function ( ) {
@ -253,10 +296,12 @@ describe('Multi User', async function() {
assert ( user ) ;
} ) ;
} ) ;
describe ( 'Video player - normal' , function ( ) {
const video _to _test = 'ebbcfffb-d6f1-4510-ad25-d1ec82e0477e' ;
describe ( 'Video player - normal' , async function ( ) {
await db _api . removeRecord ( 'files' , { uid : sample _video _json [ 'uid' ] } ) ;
await db _api . insertRecordIntoTable ( 'files' , sample _video _json ) ;
const video _to _test = sample _video _json [ 'uid' ] ;
it ( 'Get video' , async function ( ) {
const video _obj = db _api . getVideo ( video _to _test , 'admin' ) ;
const video _obj = await db _api . getVideo ( video _to _test ) ;
assert ( video _obj ) ;
} ) ;
@ -341,7 +386,9 @@ describe('Downloader', function() {
} ) ;
it ( 'Get file info' , async function ( ) {
this . timeout ( 300000 ) ;
const info = await downloader _api . getVideoInfoByURL ( url ) ;
assert ( ! ! info ) ;
} ) ;
it ( 'Download file' , async function ( ) {
@ -360,20 +407,23 @@ describe('Downloader', function() {
} ) ;
it ( 'Pause file' , async function ( ) {
const returned _download = await downloader _api . createDownload ( url , 'video' , options ) ;
await downloader _api . pauseDownload ( returned _download [ 'uid' ] ) ;
const updated _download = await db _api . getRecord ( 'download_queue' , { uid : returned _download [ 'uid' ] } ) ;
assert ( updated _download [ 'paused' ] && ! updated _download [ 'running' ] ) ;
} ) ;
it ( 'Generate args' , async function ( ) {
const args = await downloader _api . generateArgs ( url , 'video' , options ) ;
console. log ( args ) ;
assert( args . length > 0 ) ;
} ) ;
it ( 'Generate args - subscription' , async function ( ) {
subscriptions _api . initialize ( db _api , logger ) ;
const sub = await subscriptions _api . getSubscription ( sub _id ) ;
const sub _options = subscriptions _api . generateOptionsForSubscriptionDownload ( sub , 'admin' ) ;
const args = await downloader _api . generateArgs ( url , 'video' , sub _options , 'admin' ) ;
console . log ( args ) ;
const args _normal = await downloader _api . generateArgs ( url , 'video' , options ) ;
const args _sub = await downloader _api . generateArgs ( url , 'video' , sub _options , 'admin' ) ;
console . log ( JSON . stringify ( args _normal ) !== JSON . stringify ( args _sub ) ) ;
} ) ;
it ( 'Generate kodi NFO file' , async function ( ) {
@ -417,7 +467,7 @@ describe('Tasks', function() {
} ;
tasks _api . TASKS [ 'dummy_task' ] = dummy _task ;
await tasks _api . initialize ( ) ;
await tasks _api . setupTasks ( ) ;
} ) ;
it ( 'Backup db' , async function ( ) {
const backups _original = await utils . recFindByExt ( 'appdata' , 'bak' ) ;
@ -429,12 +479,13 @@ describe('Tasks', function() {
} ) ;
it ( 'Check for missing files' , async function ( ) {
this . timeout ( 300000 ) ;
await db _api . removeAllRecords ( 'files' , { uid : 'test' } ) ;
const test _missing _file = { uid : 'test' , path : 'test/missing_file.mp4' } ;
await db _api . insertRecordIntoTable ( 'files' , test _missing _file ) ;
await tasks _api . executeTask ( 'missing_files_check' ) ;
const task_obj = await db _api . getRecord ( 'tasks' , { key : 'missing_files_check '} ) ;
assert ( task _obj [ 'data' ] && task _obj [ 'data' ] [ 'uids' ] && task _obj [ 'data' ] [ 'uids' ] . length >= 1 , true ) ;
const missing_file _db _record = await db _api . getRecord ( 'files' , { uid : 'test '} ) ;
assert ( ! missing _file _db _record , true ) ;
} ) ;
it ( 'Check for duplicate files' , async function ( ) {
@ -447,10 +498,13 @@ describe('Tasks', function() {
await db _api . insertRecordIntoTable ( 'files' , test _duplicate _file1 ) ;
await db _api . insertRecordIntoTable ( 'files' , test _duplicate _file2 ) ;
await db _api . insertRecordIntoTable ( 'files' , test _duplicate _file3 ) ;
await tasks _api . executeTask ( 'duplicate_files_check' ) ;
await tasks _api . executeRun ( 'duplicate_files_check' ) ;
const task _obj = await db _api . getRecord ( 'tasks' , { key : 'duplicate_files_check' } ) ;
const duplicated _record _count = await db _api . getRecords ( 'files' , { path : 'test/missing_file.mp4' } , true ) ;
assert ( task _obj [ 'data' ] && task _obj [ 'data' ] [ 'uids' ] && task _obj [ 'data' ] [ 'uids' ] . length >= 1 , true ) ;
await tasks _api . executeTask ( 'duplicate_files_check' ) ;
const duplicated _record _count = await db _api . getRecords ( 'files' , { path : 'test/missing_file.mp4' } , true ) ;
assert ( duplicated _record _count == 1 , true ) ;
} ) ;
@ -475,22 +529,36 @@ describe('Tasks', function() {
} ) ;
it ( 'Schedule and cancel task' , async function ( ) {
const today _4 _hours = new Date ( ) ;
today _4 _hours . setHours ( today _4 _hours . getHours ( ) + 4 ) ;
await tasks _api . updateTaskSchedule ( 'dummy_task' , today _4 _hours ) ;
assert ( ! ! tasks _api . TASKS [ 'dummy_task' ] [ 'job' ] , true ) ;
this . timeout ( 5000 ) ;
const today _one _year = new Date ( ) ;
today _one _year . setFullYear ( today _one _year . getFullYear ( ) + 1 ) ;
const schedule _obj = {
type : 'timestamp' ,
data : { timestamp : today _one _year . getTime ( ) }
}
await tasks _api . updateTaskSchedule ( 'dummy_task' , schedule _obj ) ;
const dummy _task = await db _api . getRecord ( 'tasks' , { key : 'dummy_task' } ) ;
assert ( ! ! tasks _api . TASKS [ 'dummy_task' ] [ 'job' ] ) ;
assert ( ! ! dummy _task [ 'schedule' ] ) ;
await tasks _api . updateTaskSchedule ( 'dummy_task' , null ) ;
assert ( ! ! tasks _api . TASKS [ 'dummy_task' ] [ 'job' ] , false ) ;
const dummy _task _updated = await db _api . getRecord ( 'tasks' , { key : 'dummy_task' } ) ;
assert ( ! tasks _api . TASKS [ 'dummy_task' ] [ 'job' ] ) ;
assert ( ! dummy _task _updated [ 'schedule' ] ) ;
} ) ;
it ( 'Schedule and run task' , async function ( ) {
this . timeout ( 5000 ) ;
const today _1 _second = new Date ( ) ;
today _1 _second . setSeconds ( today _1 _second . getSeconds ( ) + 1 ) ;
await tasks _api . updateTaskSchedule ( 'dummy_task' , today _1 _second ) ;
assert ( ! ! tasks _api . TASKS [ 'dummy_task' ] [ 'job' ] , true ) ;
const schedule _obj = {
type : 'timestamp' ,
data : { timestamp : today _1 _second . getTime ( ) }
}
await tasks _api . updateTaskSchedule ( 'dummy_task' , schedule _obj ) ;
assert ( ! ! tasks _api . TASKS [ 'dummy_task' ] [ 'job' ] ) ;
await utils . wait ( 2000 ) ;
const dummy _task _obj = await db _api . getRecord ( 'tasks' , { key : 'dummy_task' } ) ;
assert ( dummy _task _obj [ 'data' ] , true ) ;
assert ( dummy _task _obj [ 'data' ] );
} ) ;
} ) ;