]>
Commit | Line | Data |
---|---|---|
0e1dc3e7 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
0e1dc3e7 | 3 | import * as chai from 'chai' |
d50acfab | 4 | import 'mocha' |
b1a134ee | 5 | import { join } from 'path' |
f595d394 | 6 | import * as request from 'supertest' |
b1f5b93e | 7 | import { VideoPrivacy } from '../../../../shared/models/videos' |
c5d31dba | 8 | import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' |
0e1dc3e7 C |
9 | |
10 | import { | |
f05a1c30 C |
11 | addVideoChannel, checkVideoFilesWereRemoved, completeVideoCheck, createUser, dateIsValid, doubleFollow, flushAndRunMultipleServers, |
12 | flushTests, getVideo, | |
13 | getVideoChannelsList, getVideosList, killallServers, rateVideo, removeVideo, ServerInfo, setAccessTokensToServers, testImage, | |
b1f5b93e C |
14 | updateVideo, uploadVideo, userLogin, viewVideo, wait, webtorrentAdd |
15 | } from '../../utils' | |
c5d31dba | 16 | import { |
4cb6d457 | 17 | addVideoCommentReply, addVideoCommentThread, deleteVideoComment, getVideoCommentThreads, |
c5d31dba C |
18 | getVideoThreadComments |
19 | } from '../../utils/videos/video-comments' | |
0e1dc3e7 C |
20 | |
21 | const expect = chai.expect | |
22 | ||
9a27cdc2 | 23 | describe('Test multiple servers', function () { |
0e1dc3e7 C |
24 | let servers: ServerInfo[] = [] |
25 | const toRemove = [] | |
26 | let videoUUID = '' | |
5f04dd2f | 27 | let videoChannelId: number |
0e1dc3e7 C |
28 | |
29 | before(async function () { | |
30 | this.timeout(120000) | |
31 | ||
32 | servers = await flushAndRunMultipleServers(3) | |
33 | ||
34 | // Get the access tokens | |
35 | await setAccessTokensToServers(servers) | |
36 | ||
5f04dd2f C |
37 | const videoChannel = { |
38 | name: 'my channel', | |
39 | description: 'super channel' | |
40 | } | |
41 | await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel) | |
42 | const channelRes = await getVideoChannelsList(servers[0].url, 0, 1) | |
43 | videoChannelId = channelRes.body.data[0].id | |
44 | ||
9a27cdc2 C |
45 | // Server 1 and server 2 follow each other |
46 | await doubleFollow(servers[0], servers[1]) | |
47 | // Server 1 and server 3 follow each other | |
48 | await doubleFollow(servers[0], servers[2]) | |
49 | // Server 2 and server 3 follow each other | |
50 | await doubleFollow(servers[1], servers[2]) | |
0e1dc3e7 C |
51 | }) |
52 | ||
9a27cdc2 | 53 | it('Should not have videos for all servers', async function () { |
0e1dc3e7 C |
54 | for (const server of servers) { |
55 | const res = await getVideosList(server.url) | |
56 | const videos = res.body.data | |
57 | expect(videos).to.be.an('array') | |
58 | expect(videos.length).to.equal(0) | |
59 | } | |
60 | }) | |
61 | ||
9a27cdc2 C |
62 | describe('Should upload the video and propagate on each server', function () { |
63 | it('Should upload the video on server 1 and propagate on each server', async function () { | |
652b3056 | 64 | this.timeout(25000) |
0e1dc3e7 C |
65 | |
66 | const videoAttributes = { | |
9a27cdc2 | 67 | name: 'my super name for server 1', |
0e1dc3e7 C |
68 | category: 5, |
69 | licence: 4, | |
70 | language: 9, | |
71 | nsfw: true, | |
9a27cdc2 | 72 | description: 'my super description for server 1', |
0e1dc3e7 | 73 | tags: [ 'tag1p1', 'tag2p1' ], |
5f04dd2f | 74 | channelId: videoChannelId, |
0e1dc3e7 C |
75 | fixture: 'video_short1.webm' |
76 | } | |
77 | await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) | |
78 | ||
652b3056 | 79 | await wait(10000) |
0e1dc3e7 | 80 | |
9a27cdc2 | 81 | // All servers should have this video |
0e1dc3e7 | 82 | for (const server of servers) { |
b1f5b93e C |
83 | const isLocal = server.url === 'http://localhost:9001' |
84 | const checkAttributes = { | |
85 | name: 'my super name for server 1', | |
86 | category: 5, | |
87 | licence: 4, | |
88 | language: 9, | |
89 | nsfw: true, | |
90 | description: 'my super description for server 1', | |
91 | host: 'localhost:9001', | |
92 | account: 'root', | |
93 | isLocal, | |
94 | duration: 10, | |
95 | tags: [ 'tag1p1', 'tag2p1' ], | |
96 | privacy: VideoPrivacy.PUBLIC, | |
47564bbe | 97 | commentsEnabled: true, |
b1f5b93e C |
98 | channel: { |
99 | name: 'my channel', | |
100 | description: 'super channel', | |
101 | isLocal | |
102 | }, | |
8b0d42ee | 103 | fixture: 'video_short1.webm', |
b1f5b93e C |
104 | files: [ |
105 | { | |
106 | resolution: 720, | |
107 | size: 572456 | |
108 | } | |
109 | ] | |
110 | } | |
0e1dc3e7 C |
111 | |
112 | const res = await getVideosList(server.url) | |
0e1dc3e7 C |
113 | const videos = res.body.data |
114 | expect(videos).to.be.an('array') | |
115 | expect(videos.length).to.equal(1) | |
116 | const video = videos[0] | |
0e1dc3e7 | 117 | |
b1f5b93e | 118 | await completeVideoCheck(server.url, video, checkAttributes) |
0e1dc3e7 C |
119 | } |
120 | }) | |
121 | ||
9a27cdc2 | 122 | it('Should upload the video on server 2 and propagate on each server', async function () { |
572f8d3d | 123 | this.timeout(50000) |
0e1dc3e7 | 124 | |
5f04dd2f C |
125 | const user = { |
126 | username: 'user1', | |
127 | password: 'super_password' | |
128 | } | |
129 | await createUser(servers[1].url, servers[1].accessToken, user.username, user.password) | |
eec63bbc | 130 | const userAccessToken = await userLogin(servers[1], user) |
5f04dd2f | 131 | |
0e1dc3e7 | 132 | const videoAttributes = { |
9a27cdc2 | 133 | name: 'my super name for server 2', |
0e1dc3e7 C |
134 | category: 4, |
135 | licence: 3, | |
136 | language: 11, | |
137 | nsfw: true, | |
9a27cdc2 | 138 | description: 'my super description for server 2', |
0e1dc3e7 C |
139 | tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ], |
140 | fixture: 'video_short2.webm' | |
141 | } | |
5f04dd2f | 142 | await uploadVideo(servers[1].url, userAccessToken, videoAttributes) |
0e1dc3e7 | 143 | |
572f8d3d | 144 | // Transcoding |
62c852b2 | 145 | await wait(30000) |
0e1dc3e7 | 146 | |
9a27cdc2 | 147 | // All servers should have this video |
0e1dc3e7 | 148 | for (const server of servers) { |
b1f5b93e C |
149 | const isLocal = server.url === 'http://localhost:9002' |
150 | const checkAttributes = { | |
151 | name: 'my super name for server 2', | |
152 | category: 4, | |
153 | licence: 3, | |
154 | language: 11, | |
155 | nsfw: true, | |
156 | description: 'my super description for server 2', | |
157 | host: 'localhost:9002', | |
158 | account: 'user1', | |
159 | isLocal, | |
47564bbe | 160 | commentsEnabled: true, |
b1f5b93e C |
161 | duration: 5, |
162 | tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ], | |
163 | privacy: VideoPrivacy.PUBLIC, | |
164 | channel: { | |
165 | name: 'Default user1 channel', | |
166 | description: 'super channel', | |
167 | isLocal | |
168 | }, | |
169 | fixture: 'video_short2.webm', | |
170 | files: [ | |
171 | { | |
172 | resolution: 240, | |
173 | size: 190000 | |
174 | }, | |
175 | { | |
176 | resolution: 360, | |
177 | size: 280000 | |
178 | }, | |
179 | { | |
180 | resolution: 480, | |
181 | size: 390000 | |
182 | }, | |
183 | { | |
184 | resolution: 720, | |
185 | size: 710000 | |
186 | } | |
187 | ] | |
188 | } | |
0e1dc3e7 C |
189 | |
190 | const res = await getVideosList(server.url) | |
0e1dc3e7 C |
191 | const videos = res.body.data |
192 | expect(videos).to.be.an('array') | |
193 | expect(videos.length).to.equal(2) | |
194 | const video = videos[1] | |
0e1dc3e7 | 195 | |
b1f5b93e | 196 | await completeVideoCheck(server.url, video, checkAttributes) |
0e1dc3e7 C |
197 | } |
198 | }) | |
199 | ||
9a27cdc2 | 200 | it('Should upload two videos on server 3 and propagate on each server', async function () { |
0e1dc3e7 C |
201 | this.timeout(45000) |
202 | ||
203 | const videoAttributes1 = { | |
9a27cdc2 | 204 | name: 'my super name for server 3', |
0e1dc3e7 C |
205 | category: 6, |
206 | licence: 5, | |
207 | language: 11, | |
208 | nsfw: true, | |
9a27cdc2 | 209 | description: 'my super description for server 3', |
0e1dc3e7 C |
210 | tags: [ 'tag1p3' ], |
211 | fixture: 'video_short3.webm' | |
212 | } | |
213 | await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes1) | |
214 | ||
215 | const videoAttributes2 = { | |
9a27cdc2 | 216 | name: 'my super name for server 3-2', |
0e1dc3e7 C |
217 | category: 7, |
218 | licence: 6, | |
219 | language: 12, | |
220 | nsfw: false, | |
9a27cdc2 | 221 | description: 'my super description for server 3-2', |
0e1dc3e7 C |
222 | tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ], |
223 | fixture: 'video_short.webm' | |
224 | } | |
225 | await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes2) | |
226 | ||
572f8d3d | 227 | await wait(10000) |
0e1dc3e7 | 228 | |
9a27cdc2 | 229 | // All servers should have this video |
0e1dc3e7 | 230 | for (const server of servers) { |
b1f5b93e | 231 | const isLocal = server.url === 'http://localhost:9003' |
0e1dc3e7 C |
232 | const res = await getVideosList(server.url) |
233 | ||
234 | const videos = res.body.data | |
235 | expect(videos).to.be.an('array') | |
236 | expect(videos.length).to.equal(4) | |
237 | ||
238 | // We not sure about the order of the two last uploads | |
239 | let video1 = null | |
240 | let video2 = null | |
9a27cdc2 | 241 | if (videos[2].name === 'my super name for server 3') { |
0e1dc3e7 C |
242 | video1 = videos[2] |
243 | video2 = videos[3] | |
244 | } else { | |
245 | video1 = videos[3] | |
246 | video2 = videos[2] | |
247 | } | |
248 | ||
b1f5b93e C |
249 | const checkAttributesVideo1 = { |
250 | name: 'my super name for server 3', | |
251 | category: 6, | |
252 | licence: 5, | |
253 | language: 11, | |
254 | nsfw: true, | |
255 | description: 'my super description for server 3', | |
256 | host: 'localhost:9003', | |
257 | account: 'root', | |
258 | isLocal, | |
259 | duration: 5, | |
47564bbe | 260 | commentsEnabled: true, |
b1f5b93e C |
261 | tags: [ 'tag1p3' ], |
262 | privacy: VideoPrivacy.PUBLIC, | |
263 | channel: { | |
264 | name: 'Default root channel', | |
265 | description: '', | |
266 | isLocal | |
267 | }, | |
268 | fixture: 'video_short3.webm', | |
269 | files: [ | |
270 | { | |
271 | resolution: 720, | |
272 | size: 292677 | |
273 | } | |
274 | ] | |
0e1dc3e7 | 275 | } |
b1f5b93e C |
276 | await completeVideoCheck(server.url, video1, checkAttributesVideo1) |
277 | ||
278 | const checkAttributesVideo2 = { | |
279 | name: 'my super name for server 3-2', | |
280 | category: 7, | |
281 | licence: 6, | |
282 | language: 12, | |
283 | nsfw: false, | |
284 | description: 'my super description for server 3-2', | |
285 | host: 'localhost:9003', | |
286 | account: 'root', | |
47564bbe | 287 | commentsEnabled: true, |
b1f5b93e C |
288 | isLocal, |
289 | duration: 5, | |
290 | tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ], | |
291 | privacy: VideoPrivacy.PUBLIC, | |
292 | channel: { | |
293 | name: 'Default root channel', | |
294 | description: '', | |
295 | isLocal | |
296 | }, | |
8b0d42ee | 297 | fixture: 'video_short.webm', |
b1f5b93e C |
298 | files: [ |
299 | { | |
300 | resolution: 720, | |
301 | size: 218910 | |
302 | } | |
303 | ] | |
0e1dc3e7 | 304 | } |
b1f5b93e | 305 | await completeVideoCheck(server.url, video2, checkAttributesVideo2) |
0e1dc3e7 C |
306 | } |
307 | }) | |
308 | }) | |
309 | ||
310 | describe('Should seed the uploaded video', function () { | |
9a27cdc2 | 311 | it('Should add the file 1 by asking server 3', async function () { |
572f8d3d | 312 | this.timeout(10000) |
0e1dc3e7 C |
313 | |
314 | const res = await getVideosList(servers[2].url) | |
315 | ||
316 | const video = res.body.data[0] | |
317 | toRemove.push(res.body.data[2]) | |
318 | toRemove.push(res.body.data[3]) | |
319 | ||
5f04dd2f C |
320 | const res2 = await getVideo(servers[2].url, video.id) |
321 | const videoDetails = res2.body | |
322 | ||
b1f5b93e | 323 | const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) |
0e1dc3e7 C |
324 | expect(torrent.files).to.be.an('array') |
325 | expect(torrent.files.length).to.equal(1) | |
326 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
327 | }) | |
328 | ||
9a27cdc2 | 329 | it('Should add the file 2 by asking server 1', async function () { |
572f8d3d | 330 | this.timeout(10000) |
0e1dc3e7 C |
331 | |
332 | const res = await getVideosList(servers[0].url) | |
333 | ||
334 | const video = res.body.data[1] | |
5f04dd2f C |
335 | const res2 = await getVideo(servers[0].url, video.id) |
336 | const videoDetails = res2.body | |
0e1dc3e7 | 337 | |
b1f5b93e | 338 | const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) |
0e1dc3e7 C |
339 | expect(torrent.files).to.be.an('array') |
340 | expect(torrent.files.length).to.equal(1) | |
341 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
342 | }) | |
343 | ||
9a27cdc2 | 344 | it('Should add the file 3 by asking server 2', async function () { |
572f8d3d | 345 | this.timeout(10000) |
0e1dc3e7 C |
346 | |
347 | const res = await getVideosList(servers[1].url) | |
348 | ||
349 | const video = res.body.data[2] | |
5f04dd2f C |
350 | const res2 = await getVideo(servers[1].url, video.id) |
351 | const videoDetails = res2.body | |
0e1dc3e7 | 352 | |
b1f5b93e | 353 | const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) |
0e1dc3e7 C |
354 | expect(torrent.files).to.be.an('array') |
355 | expect(torrent.files.length).to.equal(1) | |
356 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
357 | }) | |
358 | ||
9a27cdc2 | 359 | it('Should add the file 3-2 by asking server 1', async function () { |
572f8d3d | 360 | this.timeout(10000) |
0e1dc3e7 C |
361 | |
362 | const res = await getVideosList(servers[0].url) | |
363 | ||
364 | const video = res.body.data[3] | |
5f04dd2f C |
365 | const res2 = await getVideo(servers[0].url, video.id) |
366 | const videoDetails = res2.body | |
0e1dc3e7 | 367 | |
5f04dd2f | 368 | const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri) |
0e1dc3e7 C |
369 | expect(torrent.files).to.be.an('array') |
370 | expect(torrent.files.length).to.equal(1) | |
371 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
372 | }) | |
14d3270f | 373 | |
9a27cdc2 | 374 | it('Should add the file 2 in 360p by asking server 1', async function () { |
572f8d3d | 375 | this.timeout(10000) |
14d3270f C |
376 | |
377 | const res = await getVideosList(servers[0].url) | |
378 | ||
9a27cdc2 | 379 | const video = res.body.data.find(v => v.name === 'my super name for server 2') |
5f04dd2f C |
380 | const res2 = await getVideo(servers[0].url, video.id) |
381 | const videoDetails = res2.body | |
382 | ||
383 | const file = videoDetails.files.find(f => f.resolution === 360) | |
14d3270f C |
384 | expect(file).not.to.be.undefined |
385 | ||
386 | const torrent = await webtorrentAdd(file.magnetUri) | |
387 | expect(torrent.files).to.be.an('array') | |
388 | expect(torrent.files.length).to.equal(1) | |
389 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
390 | }) | |
0e1dc3e7 C |
391 | }) |
392 | ||
393 | describe('Should update video views, likes and dislikes', function () { | |
9a27cdc2 C |
394 | let localVideosServer3 = [] |
395 | let remoteVideosServer1 = [] | |
396 | let remoteVideosServer2 = [] | |
397 | let remoteVideosServer3 = [] | |
0e1dc3e7 C |
398 | |
399 | before(async function () { | |
400 | const res1 = await getVideosList(servers[0].url) | |
9a27cdc2 | 401 | remoteVideosServer1 = res1.body.data.filter(video => video.isLocal === false).map(video => video.uuid) |
0e1dc3e7 C |
402 | |
403 | const res2 = await getVideosList(servers[1].url) | |
9a27cdc2 | 404 | remoteVideosServer2 = res2.body.data.filter(video => video.isLocal === false).map(video => video.uuid) |
0e1dc3e7 C |
405 | |
406 | const res3 = await getVideosList(servers[2].url) | |
9a27cdc2 C |
407 | localVideosServer3 = res3.body.data.filter(video => video.isLocal === true).map(video => video.uuid) |
408 | remoteVideosServer3 = res3.body.data.filter(video => video.isLocal === false).map(video => video.uuid) | |
0e1dc3e7 C |
409 | }) |
410 | ||
411 | it('Should view multiple videos on owned servers', async function () { | |
572f8d3d | 412 | this.timeout(10000) |
0e1dc3e7 C |
413 | |
414 | const tasks: Promise<any>[] = [] | |
1f3e9fec C |
415 | tasks.push(viewVideo(servers[2].url, localVideosServer3[0])) |
416 | tasks.push(viewVideo(servers[2].url, localVideosServer3[0])) | |
417 | tasks.push(viewVideo(servers[2].url, localVideosServer3[0])) | |
418 | tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) | |
0e1dc3e7 C |
419 | |
420 | await Promise.all(tasks) | |
421 | ||
572f8d3d | 422 | await wait(5000) |
0e1dc3e7 C |
423 | |
424 | for (const server of servers) { | |
425 | const res = await getVideosList(server.url) | |
426 | ||
427 | const videos = res.body.data | |
9a27cdc2 C |
428 | const video0 = videos.find(v => v.uuid === localVideosServer3[0]) |
429 | const video1 = videos.find(v => v.uuid === localVideosServer3[1]) | |
5f04dd2f | 430 | |
1f3e9fec C |
431 | expect(video0.views).to.equal(3) |
432 | expect(video1.views).to.equal(1) | |
0e1dc3e7 C |
433 | } |
434 | }) | |
435 | ||
436 | it('Should view multiple videos on each servers', async function () { | |
572f8d3d | 437 | this.timeout(15000) |
0e1dc3e7 C |
438 | |
439 | const tasks: Promise<any>[] = [] | |
1f3e9fec C |
440 | tasks.push(viewVideo(servers[0].url, remoteVideosServer1[0])) |
441 | tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0])) | |
442 | tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0])) | |
443 | tasks.push(viewVideo(servers[2].url, remoteVideosServer3[0])) | |
444 | tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) | |
445 | tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) | |
446 | tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) | |
447 | tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) | |
448 | tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) | |
449 | tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) | |
0e1dc3e7 C |
450 | |
451 | await Promise.all(tasks) | |
452 | ||
572f8d3d | 453 | await wait(10000) |
0e1dc3e7 C |
454 | |
455 | let baseVideos = null | |
456 | ||
457 | for (const server of servers) { | |
458 | const res = await getVideosList(server.url) | |
459 | ||
460 | const videos = res.body.data | |
461 | ||
462 | // Initialize base videos for future comparisons | |
463 | if (baseVideos === null) { | |
464 | baseVideos = videos | |
35a097b8 | 465 | continue |
0e1dc3e7 C |
466 | } |
467 | ||
468 | for (const baseVideo of baseVideos) { | |
469 | const sameVideo = videos.find(video => video.name === baseVideo.name) | |
470 | expect(baseVideo.views).to.equal(sameVideo.views) | |
471 | } | |
472 | } | |
473 | }) | |
474 | ||
475 | it('Should like and dislikes videos on different services', async function () { | |
572f8d3d | 476 | this.timeout(20000) |
0e1dc3e7 C |
477 | |
478 | const tasks: Promise<any>[] = [] | |
9a27cdc2 C |
479 | tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like')) |
480 | tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'dislike')) | |
481 | tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like')) | |
482 | tasks.push(rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'like')) | |
483 | tasks.push(rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'dislike')) | |
484 | tasks.push(rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[1], 'dislike')) | |
485 | tasks.push(rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[0], 'like')) | |
0e1dc3e7 C |
486 | |
487 | await Promise.all(tasks) | |
488 | ||
572f8d3d | 489 | await wait(10000) |
0e1dc3e7 C |
490 | |
491 | let baseVideos = null | |
492 | for (const server of servers) { | |
493 | const res = await getVideosList(server.url) | |
494 | ||
495 | const videos = res.body.data | |
496 | ||
497 | // Initialize base videos for future comparisons | |
498 | if (baseVideos === null) { | |
499 | baseVideos = videos | |
35a097b8 | 500 | continue |
0e1dc3e7 C |
501 | } |
502 | ||
35a097b8 | 503 | for (const baseVideo of baseVideos) { |
0e1dc3e7 C |
504 | const sameVideo = videos.find(video => video.name === baseVideo.name) |
505 | expect(baseVideo.likes).to.equal(sameVideo.likes) | |
506 | expect(baseVideo.dislikes).to.equal(sameVideo.dislikes) | |
35a097b8 | 507 | } |
0e1dc3e7 C |
508 | } |
509 | }) | |
510 | }) | |
511 | ||
512 | describe('Should manipulate these videos', function () { | |
9a27cdc2 | 513 | it('Should update the video 3 by asking server 3', async function () { |
572f8d3d | 514 | this.timeout(10000) |
0e1dc3e7 C |
515 | |
516 | const attributes = { | |
517 | name: 'my super video updated', | |
518 | category: 10, | |
519 | licence: 7, | |
520 | language: 13, | |
521 | nsfw: true, | |
522 | description: 'my super description updated', | |
523 | tags: [ 'tag_up_1', 'tag_up_2' ] | |
524 | } | |
525 | ||
526 | await updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes) | |
527 | ||
572f8d3d | 528 | await wait(5000) |
0e1dc3e7 C |
529 | }) |
530 | ||
9a27cdc2 | 531 | it('Should have the video 3 updated on each server', async function () { |
572f8d3d | 532 | this.timeout(10000) |
0e1dc3e7 C |
533 | |
534 | for (const server of servers) { | |
535 | const res = await getVideosList(server.url) | |
536 | ||
537 | const videos = res.body.data | |
538 | const videoUpdated = videos.find(video => video.name === 'my super video updated') | |
0e1dc3e7 | 539 | expect(!!videoUpdated).to.be.true |
0e1dc3e7 | 540 | |
b1f5b93e C |
541 | const isLocal = server.url === 'http://localhost:9003' |
542 | const checkAttributes = { | |
543 | name: 'my super video updated', | |
544 | category: 10, | |
545 | licence: 7, | |
546 | language: 13, | |
547 | nsfw: true, | |
548 | description: 'my super description updated', | |
549 | host: 'localhost:9003', | |
550 | account: 'root', | |
551 | isLocal, | |
552 | duration: 5, | |
47564bbe | 553 | commentsEnabled: true, |
b1f5b93e C |
554 | tags: [ 'tag_up_1', 'tag_up_2' ], |
555 | privacy: VideoPrivacy.PUBLIC, | |
556 | channel: { | |
557 | name: 'Default root channel', | |
558 | description: '', | |
559 | isLocal | |
560 | }, | |
561 | fixture: 'video_short3.webm', | |
562 | files: [ | |
563 | { | |
564 | resolution: 720, | |
565 | size: 292677 | |
566 | } | |
567 | ] | |
568 | } | |
569 | await completeVideoCheck(server.url, videoUpdated, checkAttributes) | |
0e1dc3e7 C |
570 | } |
571 | }) | |
572 | ||
9a27cdc2 | 573 | it('Should remove the videos 3 and 3-2 by asking server 3', async function () { |
572f8d3d | 574 | this.timeout(10000) |
0e1dc3e7 C |
575 | |
576 | await removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id) | |
577 | await removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id) | |
578 | ||
572f8d3d | 579 | await wait(5000) |
0e1dc3e7 C |
580 | }) |
581 | ||
f05a1c30 C |
582 | it('Should not have files of videos 3 and 3-2 on each server', async function () { |
583 | for (const server of servers) { | |
584 | await checkVideoFilesWereRemoved(toRemove[0].uuid, server.serverNumber) | |
585 | await checkVideoFilesWereRemoved(toRemove[1].uuid, server.serverNumber) | |
586 | } | |
587 | }) | |
588 | ||
9a27cdc2 | 589 | it('Should have videos 1 and 3 on each server', async function () { |
0e1dc3e7 C |
590 | for (const server of servers) { |
591 | const res = await getVideosList(server.url) | |
592 | ||
593 | const videos = res.body.data | |
594 | expect(videos).to.be.an('array') | |
595 | expect(videos.length).to.equal(2) | |
596 | expect(videos[0].name).not.to.equal(videos[1].name) | |
597 | expect(videos[0].name).not.to.equal(toRemove[0].name) | |
598 | expect(videos[1].name).not.to.equal(toRemove[0].name) | |
599 | expect(videos[0].name).not.to.equal(toRemove[1].name) | |
600 | expect(videos[1].name).not.to.equal(toRemove[1].name) | |
601 | ||
9a27cdc2 | 602 | videoUUID = videos.find(video => video.name === 'my super name for server 1').uuid |
0e1dc3e7 C |
603 | } |
604 | }) | |
605 | ||
9a27cdc2 | 606 | it('Should get the same video by UUID on each server', async function () { |
0e1dc3e7 C |
607 | let baseVideo = null |
608 | for (const server of servers) { | |
609 | const res = await getVideo(server.url, videoUUID) | |
610 | ||
611 | const video = res.body | |
612 | ||
613 | if (baseVideo === null) { | |
614 | baseVideo = video | |
35a097b8 | 615 | continue |
0e1dc3e7 C |
616 | } |
617 | ||
618 | expect(baseVideo.name).to.equal(video.name) | |
619 | expect(baseVideo.uuid).to.equal(video.uuid) | |
620 | expect(baseVideo.category).to.equal(video.category) | |
621 | expect(baseVideo.language).to.equal(video.language) | |
622 | expect(baseVideo.licence).to.equal(video.licence) | |
623 | expect(baseVideo.category).to.equal(video.category) | |
624 | expect(baseVideo.nsfw).to.equal(video.nsfw) | |
b1fa3eba | 625 | expect(baseVideo.accountName).to.equal(video.accountName) |
0e1dc3e7 C |
626 | expect(baseVideo.tags).to.deep.equal(video.tags) |
627 | } | |
628 | }) | |
629 | ||
9a27cdc2 | 630 | it('Should get the preview from each server', async function () { |
0e1dc3e7 C |
631 | for (const server of servers) { |
632 | const res = await getVideo(server.url, videoUUID) | |
633 | const video = res.body | |
634 | ||
f05a1c30 | 635 | const test = await testImage(server.url, 'video_short1-preview.webm', video.previewPath) |
0e1dc3e7 C |
636 | expect(test).to.equal(true) |
637 | } | |
638 | }) | |
639 | }) | |
640 | ||
d50acfab C |
641 | describe('Should comment these videos', function () { |
642 | it('Should add comment (threads and replies)', async function () { | |
643 | this.timeout(25000) | |
644 | ||
645 | { | |
646 | const text = 'my super first comment' | |
647 | await addVideoCommentThread(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID, text) | |
648 | } | |
649 | ||
650 | { | |
651 | const text = 'my super second comment' | |
652 | await addVideoCommentThread(servers[ 2 ].url, servers[ 2 ].accessToken, videoUUID, text) | |
653 | } | |
654 | ||
655 | await wait(5000) | |
656 | ||
657 | { | |
658 | const res = await getVideoCommentThreads(servers[1].url, videoUUID, 0, 5) | |
659 | const threadId = res.body.data.find(c => c.text === 'my super first comment').id | |
660 | ||
661 | const text = 'my super answer to thread 1' | |
662 | await addVideoCommentReply(servers[ 1 ].url, servers[ 1 ].accessToken, videoUUID, threadId, text) | |
663 | } | |
664 | ||
665 | await wait(5000) | |
666 | ||
667 | { | |
668 | const res1 = await getVideoCommentThreads(servers[2].url, videoUUID, 0, 5) | |
669 | const threadId = res1.body.data.find(c => c.text === 'my super first comment').id | |
670 | ||
671 | const res2 = await getVideoThreadComments(servers[2].url, videoUUID, threadId) | |
672 | const childCommentId = res2.body.children[0].comment.id | |
673 | ||
674 | const text3 = 'my second answer to thread 1' | |
675 | await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, videoUUID, threadId, text3) | |
676 | ||
677 | const text2 = 'my super answer to answer of thread 1' | |
678 | await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, videoUUID, childCommentId, text2) | |
679 | } | |
680 | ||
681 | await wait(5000) | |
682 | }) | |
683 | ||
684 | it('Should have these threads', async function () { | |
685 | for (const server of servers) { | |
686 | const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) | |
687 | ||
688 | expect(res.body.total).to.equal(2) | |
689 | expect(res.body.data).to.be.an('array') | |
690 | expect(res.body.data).to.have.lengthOf(2) | |
691 | ||
692 | { | |
693 | const comment: VideoComment = res.body.data.find(c => c.text === 'my super first comment') | |
694 | expect(comment).to.not.be.undefined | |
695 | expect(comment.inReplyToCommentId).to.be.null | |
696 | expect(comment.account.name).to.equal('root') | |
697 | expect(comment.account.host).to.equal('localhost:9001') | |
698 | expect(comment.totalReplies).to.equal(3) | |
699 | expect(dateIsValid(comment.createdAt as string)).to.be.true | |
700 | expect(dateIsValid(comment.updatedAt as string)).to.be.true | |
701 | } | |
702 | ||
703 | { | |
704 | const comment: VideoComment = res.body.data.find(c => c.text === 'my super second comment') | |
705 | expect(comment).to.not.be.undefined | |
706 | expect(comment.inReplyToCommentId).to.be.null | |
707 | expect(comment.account.name).to.equal('root') | |
708 | expect(comment.account.host).to.equal('localhost:9003') | |
709 | expect(comment.totalReplies).to.equal(0) | |
710 | expect(dateIsValid(comment.createdAt as string)).to.be.true | |
711 | expect(dateIsValid(comment.updatedAt as string)).to.be.true | |
712 | } | |
713 | } | |
714 | }) | |
715 | ||
716 | it('Should have these comments', async function () { | |
717 | for (const server of servers) { | |
718 | const res1 = await getVideoCommentThreads(server.url, videoUUID, 0, 5) | |
719 | const threadId = res1.body.data.find(c => c.text === 'my super first comment').id | |
720 | ||
721 | const res2 = await getVideoThreadComments(server.url, videoUUID, threadId) | |
722 | ||
723 | const tree: VideoCommentThreadTree = res2.body | |
724 | expect(tree.comment.text).equal('my super first comment') | |
725 | expect(tree.comment.account.name).equal('root') | |
726 | expect(tree.comment.account.host).equal('localhost:9001') | |
727 | expect(tree.children).to.have.lengthOf(2) | |
728 | ||
729 | const firstChild = tree.children[0] | |
730 | expect(firstChild.comment.text).to.equal('my super answer to thread 1') | |
731 | expect(firstChild.comment.account.name).equal('root') | |
732 | expect(firstChild.comment.account.host).equal('localhost:9002') | |
733 | expect(firstChild.children).to.have.lengthOf(1) | |
734 | ||
735 | const childOfFirstChild = firstChild.children[0] | |
736 | expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1') | |
737 | expect(childOfFirstChild.comment.account.name).equal('root') | |
738 | expect(childOfFirstChild.comment.account.host).equal('localhost:9003') | |
739 | expect(childOfFirstChild.children).to.have.lengthOf(0) | |
740 | ||
741 | const secondChild = tree.children[1] | |
742 | expect(secondChild.comment.text).to.equal('my second answer to thread 1') | |
743 | expect(secondChild.comment.account.name).equal('root') | |
744 | expect(secondChild.comment.account.host).equal('localhost:9003') | |
745 | expect(secondChild.children).to.have.lengthOf(0) | |
746 | } | |
747 | }) | |
47564bbe | 748 | |
4cb6d457 C |
749 | it('Should delete the thread comments', async function () { |
750 | this.timeout(10000) | |
751 | ||
752 | const res1 = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 5) | |
753 | const threadId = res1.body.data.find(c => c.text === 'my super first comment').id | |
754 | await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId) | |
755 | ||
756 | await wait(5000) | |
757 | }) | |
758 | ||
759 | it('Should have the thread comments deleted on other servers too', async function () { | |
760 | for (const server of servers) { | |
761 | const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) | |
762 | ||
763 | expect(res.body.total).to.equal(1) | |
764 | expect(res.body.data).to.be.an('array') | |
765 | expect(res.body.data).to.have.lengthOf(1) | |
766 | ||
767 | { | |
768 | const comment: VideoComment = res.body.data[0] | |
769 | expect(comment).to.not.be.undefined | |
770 | expect(comment.inReplyToCommentId).to.be.null | |
771 | expect(comment.account.name).to.equal('root') | |
772 | expect(comment.account.host).to.equal('localhost:9003') | |
773 | expect(comment.totalReplies).to.equal(0) | |
774 | expect(dateIsValid(comment.createdAt as string)).to.be.true | |
775 | expect(dateIsValid(comment.updatedAt as string)).to.be.true | |
776 | } | |
777 | } | |
778 | }) | |
779 | ||
47564bbe C |
780 | it('Should disable comments', async function () { |
781 | this.timeout(20000) | |
782 | ||
783 | const attributes = { | |
784 | commentsEnabled: false | |
785 | } | |
786 | ||
787 | await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, attributes) | |
788 | ||
789 | await wait(5000) | |
790 | ||
791 | for (const server of servers) { | |
792 | const res = await getVideo(server.url, videoUUID) | |
793 | expect(res.body.commentsEnabled).to.be.false | |
794 | ||
795 | const text = 'my super forbidden comment' | |
796 | await addVideoCommentThread(server.url, server.accessToken, videoUUID, text, 409) | |
797 | } | |
798 | }) | |
d50acfab C |
799 | }) |
800 | ||
f595d394 C |
801 | describe('With minimum parameters', function () { |
802 | it('Should upload and propagate the video', async function () { | |
803 | this.timeout(50000) | |
804 | ||
805 | const path = '/api/v1/videos/upload' | |
806 | ||
807 | const req = request(servers[1].url) | |
808 | .post(path) | |
809 | .set('Accept', 'application/json') | |
810 | .set('Authorization', 'Bearer ' + servers[1].accessToken) | |
811 | .field('name', 'minimum parameters') | |
812 | .field('privacy', '1') | |
813 | .field('nsfw', 'false') | |
814 | .field('channelId', '1') | |
47564bbe | 815 | .field('commentsEnabled', 'true') |
f595d394 | 816 | |
59651eee | 817 | const filePath = join(__dirname, '..', '..', 'api', 'fixtures', 'video_short.webm') |
f595d394 C |
818 | |
819 | await req.attach('videofile', filePath) | |
820 | .expect(200) | |
821 | ||
822 | await wait(25000) | |
823 | ||
824 | for (const server of servers) { | |
825 | const res = await getVideosList(server.url) | |
826 | const video = res.body.data.find(v => v.name === 'minimum parameters') | |
827 | ||
b1f5b93e C |
828 | const isLocal = server.url === 'http://localhost:9002' |
829 | const checkAttributes = { | |
830 | name: 'minimum parameters', | |
831 | category: null, | |
832 | licence: null, | |
833 | language: null, | |
834 | nsfw: false, | |
835 | description: null, | |
836 | host: 'localhost:9002', | |
837 | account: 'root', | |
838 | isLocal, | |
839 | duration: 5, | |
47564bbe | 840 | commentsEnabled: true, |
b1f5b93e C |
841 | tags: [ ], |
842 | privacy: VideoPrivacy.PUBLIC, | |
843 | channel: { | |
844 | name: 'Default root channel', | |
845 | description: '', | |
846 | isLocal | |
847 | }, | |
848 | fixture: 'video_short.webm', | |
849 | files: [ | |
850 | { | |
851 | resolution: 720, | |
852 | size: 40315 | |
853 | }, | |
854 | { | |
855 | resolution: 480, | |
856 | size: 22808 | |
857 | }, | |
858 | { | |
859 | resolution: 360, | |
860 | size: 18617 | |
861 | }, | |
862 | { | |
863 | resolution: 240, | |
864 | size: 15217 | |
865 | } | |
866 | ] | |
867 | } | |
868 | await completeVideoCheck(server.url, video, checkAttributes) | |
f595d394 C |
869 | } |
870 | }) | |
871 | }) | |
872 | ||
0e1dc3e7 C |
873 | after(async function () { |
874 | killallServers(servers) | |
875 | ||
876 | // Keep the logs if the test failed | |
877 | if (this['ok']) { | |
878 | await flushTests() | |
879 | } | |
880 | }) | |
881 | }) |