X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fmultiple-pods.js;h=552f10c6fe75356a57be38d8d1e0cb6594e80df5;hb=d38b82810638b9f664c9016fac2684454c273a77;hp=169a9f2e0d01c0e514e1200288e269468b52aa94;hpb=7f4e7c36373217b8e92cf227c71999a0ce9a15d9;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/multiple-pods.js b/server/tests/api/multiple-pods.js index 169a9f2e0..552f10c6f 100644 --- a/server/tests/api/multiple-pods.js +++ b/server/tests/api/multiple-pods.js @@ -1,8 +1,12 @@ +/* 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() @@ -312,7 +316,7 @@ describe('Test multiple pods', function () { expect(torrent.files.length).to.equal(1) expect(torrent.files[0].path).to.exist.and.to.not.equal('') - webtorrent.remove(video.magnetUri, done) + done() }) }) }) @@ -331,7 +335,7 @@ describe('Test multiple pods', function () { expect(torrent.files.length).to.equal(1) expect(torrent.files[0].path).to.exist.and.to.not.equal('') - webtorrent.remove(video.magnetUri, done) + done() }) }) }) @@ -350,7 +354,7 @@ describe('Test multiple pods', function () { expect(torrent.files.length).to.equal(1) expect(torrent.files[0].path).to.exist.and.to.not.equal('') - webtorrent.remove(video.magnetUri, done) + done() }) }) }) @@ -369,12 +373,231 @@ describe('Test multiple pods', function () { 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) @@ -419,7 +642,7 @@ describe('Test multiple pods', function () { expect(torrent.files.length).to.equal(1) expect(torrent.files[0].path).to.exist.and.to.not.equal('') - webtorrent.remove(videoUpdated.magnetUri, callback) + callback() }) }) })