]>
Commit | Line | Data |
---|---|---|
843aa7ba C |
1 | /* eslint-disable no-unused-expressions */ |
2 | ||
3 | 'use strict' | |
4 | ||
5 | const chai = require('chai') | |
6 | const each = require('async/each') | |
7 | const expect = chai.expect | |
8 | const series = require('async/series') | |
9 | ||
10 | const loginUtils = require('../utils/login') | |
11 | const podsUtils = require('../utils/pods') | |
12 | const serversUtils = require('../utils/servers') | |
13 | const videosUtils = require('../utils/videos') | |
14 | const videoBlacklistsUtils = require('../utils/video-blacklists') | |
15 | ||
16 | describe('Test video blacklists', function () { | |
17 | let servers = [] | |
18 | ||
19 | before(function (done) { | |
20 | this.timeout(30000) | |
21 | ||
22 | series([ | |
23 | // Run servers | |
24 | function (next) { | |
25 | serversUtils.flushAndRunMultipleServers(2, function (serversRun) { | |
26 | servers = serversRun | |
27 | next() | |
28 | }) | |
29 | }, | |
30 | // Get the access tokens | |
31 | function (next) { | |
32 | each(servers, function (server, callbackEach) { | |
33 | loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { | |
34 | if (err) return callbackEach(err) | |
35 | ||
36 | server.accessToken = accessToken | |
37 | callbackEach() | |
38 | }) | |
39 | }, next) | |
40 | }, | |
41 | // Pod 1 makes friend with pod 2 | |
42 | function (next) { | |
43 | const server = servers[0] | |
44 | podsUtils.makeFriends(server.url, server.accessToken, next) | |
45 | }, | |
46 | // Upload a video on pod 2 | |
47 | function (next) { | |
48 | const videoAttributes = { | |
49 | name: 'my super name for pod 2', | |
50 | description: 'my super description for pod 2' | |
51 | } | |
52 | videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes, next) | |
53 | }, | |
54 | // Wait videos propagation | |
55 | function (next) { | |
b1ed2217 | 56 | setTimeout(next, 22000) |
843aa7ba C |
57 | }, |
58 | function (next) { | |
59 | videosUtils.getVideosList(servers[0].url, function (err, res) { | |
60 | if (err) throw err | |
61 | ||
62 | const videos = res.body.data | |
63 | ||
64 | expect(videos.length).to.equal(1) | |
65 | ||
66 | servers[0].remoteVideo = videos.find(function (video) { return video.name === 'my super name for pod 2' }) | |
67 | ||
68 | next() | |
69 | }) | |
70 | } | |
71 | ], done) | |
72 | }) | |
73 | ||
74 | it('Should blacklist a remote video on pod 1', function (done) { | |
75 | videoBlacklistsUtils.addVideoToBlacklist(servers[0].url, servers[0].accessToken, servers[0].remoteVideo.id, done) | |
76 | }) | |
77 | ||
78 | it('Should not have the video blacklisted in videos list on pod 1', function (done) { | |
79 | videosUtils.getVideosList(servers[0].url, function (err, res) { | |
80 | if (err) throw err | |
81 | ||
82 | expect(res.body.total).to.equal(0) | |
83 | expect(res.body.data).to.be.an('array') | |
84 | expect(res.body.data.length).to.equal(0) | |
85 | ||
86 | done() | |
87 | }) | |
88 | }) | |
89 | ||
90 | it('Should not have the video blacklisted in videos search on pod 1', function (done) { | |
91 | videosUtils.searchVideo(servers[0].url, 'name', function (err, res) { | |
92 | if (err) throw err | |
93 | ||
94 | expect(res.body.total).to.equal(0) | |
95 | expect(res.body.data).to.be.an('array') | |
96 | expect(res.body.data.length).to.equal(0) | |
97 | ||
98 | done() | |
99 | }) | |
100 | }) | |
101 | ||
102 | it('Should have the blacklisted video in videos list on pod 2', function (done) { | |
103 | videosUtils.getVideosList(servers[1].url, function (err, res) { | |
104 | if (err) throw err | |
105 | ||
106 | expect(res.body.total).to.equal(1) | |
107 | expect(res.body.data).to.be.an('array') | |
108 | expect(res.body.data.length).to.equal(1) | |
109 | ||
110 | done() | |
111 | }) | |
112 | }) | |
113 | ||
114 | it('Should have the video blacklisted in videos search on pod 2', function (done) { | |
115 | videosUtils.searchVideo(servers[1].url, 'name', function (err, res) { | |
116 | if (err) throw err | |
117 | ||
118 | expect(res.body.total).to.equal(1) | |
119 | expect(res.body.data).to.be.an('array') | |
120 | expect(res.body.data.length).to.equal(1) | |
121 | ||
122 | done() | |
123 | }) | |
124 | }) | |
125 | ||
126 | after(function (done) { | |
127 | servers.forEach(function (server) { | |
128 | process.kill(-server.app.pid) | |
129 | }) | |
130 | ||
131 | // Keep the logs if the test failed | |
132 | if (this.ok) { | |
133 | serversUtils.flushTests(done) | |
134 | } else { | |
135 | done() | |
136 | } | |
137 | }) | |
138 | }) |