+/* eslint-disable no-unused-expressions */
+
'use strict'
const chai = require('chai')
const each = require('async/each')
+const eachSeries = require('async/eachSeries')
const expect = chai.expect
+const parallel = require('async/parallel')
const series = require('async/series')
const WebTorrent = require('webtorrent')
const webtorrent = new WebTorrent()
expect(torrent.files.length).to.equal(1)
expect(torrent.files[0].path).to.exist.and.to.not.equal('')
- webtorrent.remove(video.magnetUri, done)
+ done()
})
})
})
expect(torrent.files.length).to.equal(1)
expect(torrent.files[0].path).to.exist.and.to.not.equal('')
- webtorrent.remove(video.magnetUri, done)
+ done()
})
})
})
expect(torrent.files.length).to.equal(1)
expect(torrent.files[0].path).to.exist.and.to.not.equal('')
- webtorrent.remove(video.magnetUri, done)
+ done()
})
})
})
expect(torrent.files.length).to.equal(1)
expect(torrent.files[0].path).to.exist.and.to.not.equal('')
- webtorrent.remove(video.magnetUri, done)
+ done()
})
})
})
})
+ describe('Should update video views, likes and dislikes', function () {
+ let localVideosPod3 = []
+ let remoteVideosPod1 = []
+ let remoteVideosPod2 = []
+ let remoteVideosPod3 = []
+
+ before(function (done) {
+ parallel([
+ function (callback) {
+ videosUtils.getVideosList(servers[0].url, function (err, res) {
+ if (err) throw err
+
+ remoteVideosPod1 = res.body.data.filter(video => video.isLocal === false).map(video => video.id)
+
+ callback()
+ })
+ },
+
+ function (callback) {
+ videosUtils.getVideosList(servers[1].url, function (err, res) {
+ if (err) throw err
+
+ remoteVideosPod2 = res.body.data.filter(video => video.isLocal === false).map(video => video.id)
+
+ callback()
+ })
+ },
+
+ function (callback) {
+ videosUtils.getVideosList(servers[2].url, function (err, res) {
+ if (err) throw err
+
+ localVideosPod3 = res.body.data.filter(video => video.isLocal === true).map(video => video.id)
+ remoteVideosPod3 = res.body.data.filter(video => video.isLocal === false).map(video => video.id)
+
+ callback()
+ })
+ }
+ ], done)
+ })
+
+ it('Should view multiple videos on owned servers', function (done) {
+ this.timeout(30000)
+
+ parallel([
+ function (callback) {
+ videosUtils.getVideo(servers[2].url, localVideosPod3[0], callback)
+ },
+
+ function (callback) {
+ videosUtils.getVideo(servers[2].url, localVideosPod3[0], callback)
+ },
+
+ function (callback) {
+ videosUtils.getVideo(servers[2].url, localVideosPod3[0], callback)
+ },
+
+ function (callback) {
+ videosUtils.getVideo(servers[2].url, localVideosPod3[1], callback)
+ },
+
+ function (callback) {
+ setTimeout(callback, 22000)
+ }
+ ], function (err) {
+ if (err) throw err
+
+ eachSeries(servers, function (server, callback) {
+ videosUtils.getVideosList(server.url, function (err, res) {
+ if (err) throw err
+
+ const videos = res.body.data
+ expect(videos.find(video => video.views === 3)).to.exist
+ expect(videos.find(video => video.views === 1)).to.exist
+
+ callback()
+ })
+ }, done)
+ })
+ })
+
+ it('Should view multiple videos on each servers', function (done) {
+ this.timeout(30000)
+
+ parallel([
+ function (callback) {
+ videosUtils.getVideo(servers[0].url, remoteVideosPod1[0], callback)
+ },
+
+ function (callback) {
+ videosUtils.getVideo(servers[1].url, remoteVideosPod2[0], callback)
+ },
+
+ function (callback) {
+ videosUtils.getVideo(servers[1].url, remoteVideosPod2[0], callback)
+ },
+
+ function (callback) {
+ videosUtils.getVideo(servers[2].url, remoteVideosPod3[0], callback)
+ },
+
+ function (callback) {
+ videosUtils.getVideo(servers[2].url, remoteVideosPod3[1], callback)
+ },
+
+ function (callback) {
+ videosUtils.getVideo(servers[2].url, remoteVideosPod3[1], callback)
+ },
+
+ function (callback) {
+ videosUtils.getVideo(servers[2].url, remoteVideosPod3[1], callback)
+ },
+
+ function (callback) {
+ videosUtils.getVideo(servers[2].url, localVideosPod3[1], callback)
+ },
+
+ function (callback) {
+ videosUtils.getVideo(servers[2].url, localVideosPod3[1], callback)
+ },
+
+ function (callback) {
+ videosUtils.getVideo(servers[2].url, localVideosPod3[1], callback)
+ },
+
+ function (callback) {
+ setTimeout(callback, 22000)
+ }
+ ], function (err) {
+ if (err) throw err
+
+ let baseVideos = null
+ eachSeries(servers, function (server, callback) {
+ videosUtils.getVideosList(server.url, function (err, res) {
+ if (err) throw err
+
+ const videos = res.body.data
+
+ // Initialize base videos for future comparisons
+ if (baseVideos === null) {
+ baseVideos = videos
+ return callback()
+ }
+
+ baseVideos.forEach(baseVideo => {
+ const sameVideo = videos.find(video => video.name === baseVideo.name)
+ expect(baseVideo.views).to.equal(sameVideo.views)
+ })
+
+ callback()
+ })
+ }, done)
+ })
+ })
+
+ it('Should like and dislikes videos on different services', function (done) {
+ this.timeout(30000)
+
+ parallel([
+ function (callback) {
+ videosUtils.rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'like', callback)
+ },
+
+ function (callback) {
+ videosUtils.rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'dislike', callback)
+ },
+
+ function (callback) {
+ videosUtils.rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'like', callback)
+ },
+
+ function (callback) {
+ videosUtils.rateVideo(servers[2].url, servers[2].accessToken, localVideosPod3[1], 'like', callback)
+ },
+
+ function (callback) {
+ videosUtils.rateVideo(servers[2].url, servers[2].accessToken, localVideosPod3[1], 'dislike', callback)
+ },
+
+ function (callback) {
+ videosUtils.rateVideo(servers[2].url, servers[2].accessToken, remoteVideosPod3[1], 'dislike', callback)
+ },
+
+ function (callback) {
+ videosUtils.rateVideo(servers[2].url, servers[2].accessToken, remoteVideosPod3[0], 'like', callback)
+ },
+
+ function (callback) {
+ setTimeout(callback, 22000)
+ }
+ ], function (err) {
+ if (err) throw err
+
+ let baseVideos = null
+ eachSeries(servers, function (server, callback) {
+ videosUtils.getVideosList(server.url, function (err, res) {
+ if (err) throw err
+
+ const videos = res.body.data
+
+ // Initialize base videos for future comparisons
+ if (baseVideos === null) {
+ baseVideos = videos
+ return callback()
+ }
+
+ baseVideos.forEach(baseVideo => {
+ const sameVideo = videos.find(video => video.name === baseVideo.name)
+ expect(baseVideo.likes).to.equal(sameVideo.likes)
+ expect(baseVideo.dislikes).to.equal(sameVideo.dislikes)
+ })
+
+ callback()
+ })
+ }, done)
+ })
+ })
+ })
+
describe('Should manipulate these videos', function () {
it('Should update the video 3 by asking pod 3', function (done) {
this.timeout(15000)
expect(torrent.files.length).to.equal(1)
expect(torrent.files[0].path).to.exist.and.to.not.equal('')
- webtorrent.remove(videoUpdated.magnetUri, callback)
+ callback()
})
})
})