]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/multiple-servers.ts
Soft delete video comments instead of detroy
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / multiple-servers.ts
CommitLineData
0e1dc3e7
C
1/* tslint:disable:no-unused-expression */
2
0e1dc3e7 3import * as chai from 'chai'
d50acfab 4import 'mocha'
b1a134ee 5import { join } from 'path'
f595d394 6import * as request from 'supertest'
b1f5b93e 7import { VideoPrivacy } from '../../../../shared/models/videos'
c5d31dba 8import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
0e1dc3e7 9import {
b64c950a 10 addVideoChannel,
89231874 11 checkTmpIsEmpty,
7243f84d
C
12 checkVideoFilesWereRemoved,
13 cleanupTests,
b64c950a
C
14 completeVideoCheck,
15 createUser,
16 dateIsValid,
17 doubleFollow,
18 flushAndRunMultipleServers,
3cd0734f 19 getLocalVideos,
b64c950a
C
20 getVideo,
21 getVideoChannelsList,
22 getVideosList,
b64c950a
C
23 rateVideo,
24 removeVideo,
25 ServerInfo,
26 setAccessTokensToServers,
27 testImage,
28 updateVideo,
29 uploadVideo,
30 userLogin,
31 viewVideo,
32 wait,
33 webtorrentAdd
94565d52 34} from '../../../../shared/extra-utils'
c5d31dba 35import {
b64c950a
C
36 addVideoCommentReply,
37 addVideoCommentThread,
38 deleteVideoComment,
39 getVideoCommentThreads,
c5d31dba 40 getVideoThreadComments
94565d52
C
41} from '../../../../shared/extra-utils/videos/video-comments'
42import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
0e1dc3e7
C
43
44const expect = chai.expect
45
9a27cdc2 46describe('Test multiple servers', function () {
0e1dc3e7
C
47 let servers: ServerInfo[] = []
48 const toRemove = []
49 let videoUUID = ''
5f04dd2f 50 let videoChannelId: number
0e1dc3e7
C
51
52 before(async function () {
53 this.timeout(120000)
54
55 servers = await flushAndRunMultipleServers(3)
56
57 // Get the access tokens
58 await setAccessTokensToServers(servers)
59
48dce1c9
C
60 {
61 const videoChannel = {
8a19bee1 62 name: 'super_channel_name',
08c1efbe 63 displayName: 'my channel',
48dce1c9
C
64 description: 'super channel'
65 }
170726f5 66 await addVideoChannel(servers[ 0 ].url, servers[ 0 ].accessToken, videoChannel)
48dce1c9
C
67 const channelRes = await getVideoChannelsList(servers[ 0 ].url, 0, 1)
68 videoChannelId = channelRes.body.data[ 0 ].id
5f04dd2f 69 }
5f04dd2f 70
9a27cdc2
C
71 // Server 1 and server 2 follow each other
72 await doubleFollow(servers[0], servers[1])
73 // Server 1 and server 3 follow each other
74 await doubleFollow(servers[0], servers[2])
75 // Server 2 and server 3 follow each other
76 await doubleFollow(servers[1], servers[2])
0e1dc3e7
C
77 })
78
9a27cdc2 79 it('Should not have videos for all servers', async function () {
0e1dc3e7
C
80 for (const server of servers) {
81 const res = await getVideosList(server.url)
82 const videos = res.body.data
83 expect(videos).to.be.an('array')
84 expect(videos.length).to.equal(0)
85 }
86 })
87
9a27cdc2
C
88 describe('Should upload the video and propagate on each server', function () {
89 it('Should upload the video on server 1 and propagate on each server', async function () {
652b3056 90 this.timeout(25000)
0e1dc3e7
C
91
92 const videoAttributes = {
9a27cdc2 93 name: 'my super name for server 1',
0e1dc3e7
C
94 category: 5,
95 licence: 4,
9d3ef9fe 96 language: 'ja',
0e1dc3e7 97 nsfw: true,
9a27cdc2 98 description: 'my super description for server 1',
2422c46b 99 support: 'my super support text for server 1',
7519127b 100 originallyPublishedAt: '2019-02-10T13:38:14.449Z',
0e1dc3e7 101 tags: [ 'tag1p1', 'tag2p1' ],
5f04dd2f 102 channelId: videoChannelId,
0e1dc3e7
C
103 fixture: 'video_short1.webm'
104 }
105 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
106
3cd0734f 107 await waitJobs(servers)
0e1dc3e7 108
9a27cdc2 109 // All servers should have this video
53a61317 110 let publishedAt: string = null
0e1dc3e7 111 for (const server of servers) {
48f07b4a 112 const isLocal = server.port === servers[0].port
b1f5b93e
C
113 const checkAttributes = {
114 name: 'my super name for server 1',
115 category: 5,
116 licence: 4,
9d3ef9fe 117 language: 'ja',
b1f5b93e
C
118 nsfw: true,
119 description: 'my super description for server 1',
2422c46b 120 support: 'my super support text for server 1',
7519127b 121 originallyPublishedAt: '2019-02-10T13:38:14.449Z',
b64c950a
C
122 account: {
123 name: 'root',
7243f84d 124 host: 'localhost:' + servers[0].port
b64c950a 125 },
b1f5b93e 126 isLocal,
53a61317 127 publishedAt,
b1f5b93e
C
128 duration: 10,
129 tags: [ 'tag1p1', 'tag2p1' ],
130 privacy: VideoPrivacy.PUBLIC,
47564bbe 131 commentsEnabled: true,
7f2cfe3a 132 downloadEnabled: true,
b1f5b93e 133 channel: {
f6eebcb3
C
134 displayName: 'my channel',
135 name: 'super_channel_name',
b1f5b93e
C
136 description: 'super channel',
137 isLocal
138 },
8b0d42ee 139 fixture: 'video_short1.webm',
b1f5b93e
C
140 files: [
141 {
142 resolution: 720,
143 size: 572456
144 }
145 ]
146 }
0e1dc3e7
C
147
148 const res = await getVideosList(server.url)
0e1dc3e7
C
149 const videos = res.body.data
150 expect(videos).to.be.an('array')
151 expect(videos.length).to.equal(1)
152 const video = videos[0]
0e1dc3e7 153
b1f5b93e 154 await completeVideoCheck(server.url, video, checkAttributes)
53a61317 155 publishedAt = video.publishedAt
0e1dc3e7
C
156 }
157 })
158
9a27cdc2 159 it('Should upload the video on server 2 and propagate on each server', async function () {
572f8d3d 160 this.timeout(50000)
0e1dc3e7 161
5f04dd2f
C
162 const user = {
163 username: 'user1',
164 password: 'super_password'
165 }
1eddc9a7 166 await createUser({ url: servers[ 1 ].url, accessToken: servers[ 1 ].accessToken, username: user.username, password: user.password })
eec63bbc 167 const userAccessToken = await userLogin(servers[1], user)
5f04dd2f 168
0e1dc3e7 169 const videoAttributes = {
9a27cdc2 170 name: 'my super name for server 2',
0e1dc3e7
C
171 category: 4,
172 licence: 3,
9d3ef9fe 173 language: 'de',
0e1dc3e7 174 nsfw: true,
9a27cdc2 175 description: 'my super description for server 2',
2422c46b 176 support: 'my super support text for server 2',
0e1dc3e7 177 tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ],
ac81d1a0
C
178 fixture: 'video_short2.webm',
179 thumbnailfile: 'thumbnail.jpg',
180 previewfile: 'preview.jpg'
0e1dc3e7 181 }
5f04dd2f 182 await uploadVideo(servers[1].url, userAccessToken, videoAttributes)
0e1dc3e7 183
572f8d3d 184 // Transcoding
3cd0734f 185 await waitJobs(servers)
0e1dc3e7 186
9a27cdc2 187 // All servers should have this video
0e1dc3e7 188 for (const server of servers) {
7243f84d 189 const isLocal = server.url === 'http://localhost:' + servers[1].port
b1f5b93e
C
190 const checkAttributes = {
191 name: 'my super name for server 2',
192 category: 4,
193 licence: 3,
9d3ef9fe 194 language: 'de',
b1f5b93e
C
195 nsfw: true,
196 description: 'my super description for server 2',
2422c46b 197 support: 'my super support text for server 2',
b64c950a
C
198 account: {
199 name: 'user1',
7243f84d 200 host: 'localhost:' + servers[1].port
b64c950a 201 },
b1f5b93e 202 isLocal,
47564bbe 203 commentsEnabled: true,
7f2cfe3a 204 downloadEnabled: true,
b1f5b93e
C
205 duration: 5,
206 tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ],
207 privacy: VideoPrivacy.PUBLIC,
208 channel: {
f6eebcb3
C
209 displayName: 'Main user1 channel',
210 name: 'user1_channel',
b1f5b93e
C
211 description: 'super channel',
212 isLocal
213 },
214 fixture: 'video_short2.webm',
215 files: [
216 {
217 resolution: 240,
80b8ad2a 218 size: 189000
b1f5b93e
C
219 },
220 {
221 resolution: 360,
eed24d26 222 size: 278000
b1f5b93e
C
223 },
224 {
225 resolution: 480,
80b8ad2a 226 size: 384000
b1f5b93e
C
227 },
228 {
229 resolution: 720,
eed24d26 230 size: 706000
b1f5b93e 231 }
ac81d1a0
C
232 ],
233 thumbnailfile: 'thumbnail',
234 previewfile: 'preview'
b1f5b93e 235 }
0e1dc3e7
C
236
237 const res = await getVideosList(server.url)
0e1dc3e7
C
238 const videos = res.body.data
239 expect(videos).to.be.an('array')
240 expect(videos.length).to.equal(2)
241 const video = videos[1]
0e1dc3e7 242
b1f5b93e 243 await completeVideoCheck(server.url, video, checkAttributes)
0e1dc3e7
C
244 }
245 })
246
9a27cdc2 247 it('Should upload two videos on server 3 and propagate on each server', async function () {
0e1dc3e7
C
248 this.timeout(45000)
249
250 const videoAttributes1 = {
9a27cdc2 251 name: 'my super name for server 3',
0e1dc3e7
C
252 category: 6,
253 licence: 5,
9d3ef9fe 254 language: 'de',
0e1dc3e7 255 nsfw: true,
9a27cdc2 256 description: 'my super description for server 3',
2422c46b 257 support: 'my super support text for server 3',
0e1dc3e7
C
258 tags: [ 'tag1p3' ],
259 fixture: 'video_short3.webm'
260 }
261 await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes1)
262
263 const videoAttributes2 = {
9a27cdc2 264 name: 'my super name for server 3-2',
0e1dc3e7
C
265 category: 7,
266 licence: 6,
9d3ef9fe 267 language: 'ko',
0e1dc3e7 268 nsfw: false,
9a27cdc2 269 description: 'my super description for server 3-2',
2422c46b 270 support: 'my super support text for server 3-2',
0e1dc3e7
C
271 tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ],
272 fixture: 'video_short.webm'
273 }
274 await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes2)
275
3cd0734f 276 await waitJobs(servers)
0e1dc3e7 277
9a27cdc2 278 // All servers should have this video
0e1dc3e7 279 for (const server of servers) {
7243f84d 280 const isLocal = server.url === 'http://localhost:' + servers[2].port
0e1dc3e7
C
281 const res = await getVideosList(server.url)
282
283 const videos = res.body.data
284 expect(videos).to.be.an('array')
285 expect(videos.length).to.equal(4)
286
287 // We not sure about the order of the two last uploads
288 let video1 = null
289 let video2 = null
9a27cdc2 290 if (videos[2].name === 'my super name for server 3') {
0e1dc3e7
C
291 video1 = videos[2]
292 video2 = videos[3]
293 } else {
294 video1 = videos[3]
295 video2 = videos[2]
296 }
297
b1f5b93e
C
298 const checkAttributesVideo1 = {
299 name: 'my super name for server 3',
300 category: 6,
301 licence: 5,
9d3ef9fe 302 language: 'de',
b1f5b93e
C
303 nsfw: true,
304 description: 'my super description for server 3',
2422c46b 305 support: 'my super support text for server 3',
b64c950a
C
306 account: {
307 name: 'root',
7243f84d 308 host: 'localhost:' + servers[2].port
b64c950a 309 },
b1f5b93e
C
310 isLocal,
311 duration: 5,
47564bbe 312 commentsEnabled: true,
7f2cfe3a 313 downloadEnabled: true,
b1f5b93e
C
314 tags: [ 'tag1p3' ],
315 privacy: VideoPrivacy.PUBLIC,
316 channel: {
f6eebcb3
C
317 displayName: 'Main root channel',
318 name: 'root_channel',
b1f5b93e
C
319 description: '',
320 isLocal
321 },
322 fixture: 'video_short3.webm',
323 files: [
324 {
325 resolution: 720,
326 size: 292677
327 }
328 ]
0e1dc3e7 329 }
b1f5b93e
C
330 await completeVideoCheck(server.url, video1, checkAttributesVideo1)
331
332 const checkAttributesVideo2 = {
333 name: 'my super name for server 3-2',
334 category: 7,
335 licence: 6,
9d3ef9fe 336 language: 'ko',
b1f5b93e
C
337 nsfw: false,
338 description: 'my super description for server 3-2',
2422c46b 339 support: 'my super support text for server 3-2',
b64c950a
C
340 account: {
341 name: 'root',
7243f84d 342 host: 'localhost:' + servers[2].port
b64c950a 343 },
47564bbe 344 commentsEnabled: true,
7f2cfe3a 345 downloadEnabled: true,
b1f5b93e
C
346 isLocal,
347 duration: 5,
348 tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ],
349 privacy: VideoPrivacy.PUBLIC,
350 channel: {
f6eebcb3
C
351 displayName: 'Main root channel',
352 name: 'root_channel',
b1f5b93e
C
353 description: '',
354 isLocal
355 },
8b0d42ee 356 fixture: 'video_short.webm',
b1f5b93e
C
357 files: [
358 {
359 resolution: 720,
360 size: 218910
361 }
362 ]
0e1dc3e7 363 }
b1f5b93e 364 await completeVideoCheck(server.url, video2, checkAttributesVideo2)
0e1dc3e7
C
365 }
366 })
367 })
368
066e94c5
C
369 describe('It should list local videos', function () {
370 it('Should list only local videos on server 1', async function () {
371 const { body } = await getLocalVideos(servers[0].url)
372
373 expect(body.total).to.equal(1)
374 expect(body.data).to.be.an('array')
375 expect(body.data.length).to.equal(1)
376 expect(body.data[0].name).to.equal('my super name for server 1')
377 })
378
379 it('Should list only local videos on server 2', async function () {
380 const { body } = await getLocalVideos(servers[1].url)
381
382 expect(body.total).to.equal(1)
383 expect(body.data).to.be.an('array')
384 expect(body.data.length).to.equal(1)
385 expect(body.data[0].name).to.equal('my super name for server 2')
386 })
387
388 it('Should list only local videos on server 3', async function () {
389 const { body } = await getLocalVideos(servers[2].url)
390
391 expect(body.total).to.equal(2)
392 expect(body.data).to.be.an('array')
393 expect(body.data.length).to.equal(2)
394 expect(body.data[0].name).to.equal('my super name for server 3')
395 expect(body.data[1].name).to.equal('my super name for server 3-2')
396 })
397 })
398
0e1dc3e7 399 describe('Should seed the uploaded video', function () {
9a27cdc2 400 it('Should add the file 1 by asking server 3', async function () {
572f8d3d 401 this.timeout(10000)
0e1dc3e7
C
402
403 const res = await getVideosList(servers[2].url)
404
405 const video = res.body.data[0]
406 toRemove.push(res.body.data[2])
407 toRemove.push(res.body.data[3])
408
5f04dd2f
C
409 const res2 = await getVideo(servers[2].url, video.id)
410 const videoDetails = res2.body
411
b1f5b93e 412 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true)
0e1dc3e7
C
413 expect(torrent.files).to.be.an('array')
414 expect(torrent.files.length).to.equal(1)
415 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
416 })
417
9a27cdc2 418 it('Should add the file 2 by asking server 1', async function () {
572f8d3d 419 this.timeout(10000)
0e1dc3e7
C
420
421 const res = await getVideosList(servers[0].url)
422
423 const video = res.body.data[1]
5f04dd2f
C
424 const res2 = await getVideo(servers[0].url, video.id)
425 const videoDetails = res2.body
0e1dc3e7 426
b1f5b93e 427 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true)
0e1dc3e7
C
428 expect(torrent.files).to.be.an('array')
429 expect(torrent.files.length).to.equal(1)
430 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
431 })
432
9a27cdc2 433 it('Should add the file 3 by asking server 2', async function () {
572f8d3d 434 this.timeout(10000)
0e1dc3e7
C
435
436 const res = await getVideosList(servers[1].url)
437
438 const video = res.body.data[2]
5f04dd2f
C
439 const res2 = await getVideo(servers[1].url, video.id)
440 const videoDetails = res2.body
0e1dc3e7 441
b1f5b93e 442 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true)
0e1dc3e7
C
443 expect(torrent.files).to.be.an('array')
444 expect(torrent.files.length).to.equal(1)
445 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
446 })
447
9a27cdc2 448 it('Should add the file 3-2 by asking server 1', async function () {
572f8d3d 449 this.timeout(10000)
0e1dc3e7
C
450
451 const res = await getVideosList(servers[0].url)
452
453 const video = res.body.data[3]
5f04dd2f
C
454 const res2 = await getVideo(servers[0].url, video.id)
455 const videoDetails = res2.body
0e1dc3e7 456
5f04dd2f 457 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)
0e1dc3e7
C
458 expect(torrent.files).to.be.an('array')
459 expect(torrent.files.length).to.equal(1)
460 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
461 })
14d3270f 462
9a27cdc2 463 it('Should add the file 2 in 360p by asking server 1', async function () {
572f8d3d 464 this.timeout(10000)
14d3270f
C
465
466 const res = await getVideosList(servers[0].url)
467
9a27cdc2 468 const video = res.body.data.find(v => v.name === 'my super name for server 2')
5f04dd2f
C
469 const res2 = await getVideo(servers[0].url, video.id)
470 const videoDetails = res2.body
471
5d00a3d7 472 const file = videoDetails.files.find(f => f.resolution.id === 360)
14d3270f
C
473 expect(file).not.to.be.undefined
474
475 const torrent = await webtorrentAdd(file.magnetUri)
476 expect(torrent.files).to.be.an('array')
477 expect(torrent.files.length).to.equal(1)
478 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
479 })
0e1dc3e7
C
480 })
481
482 describe('Should update video views, likes and dislikes', function () {
9a27cdc2
C
483 let localVideosServer3 = []
484 let remoteVideosServer1 = []
485 let remoteVideosServer2 = []
486 let remoteVideosServer3 = []
0e1dc3e7
C
487
488 before(async function () {
489 const res1 = await getVideosList(servers[0].url)
9a27cdc2 490 remoteVideosServer1 = res1.body.data.filter(video => video.isLocal === false).map(video => video.uuid)
0e1dc3e7
C
491
492 const res2 = await getVideosList(servers[1].url)
9a27cdc2 493 remoteVideosServer2 = res2.body.data.filter(video => video.isLocal === false).map(video => video.uuid)
0e1dc3e7
C
494
495 const res3 = await getVideosList(servers[2].url)
9a27cdc2
C
496 localVideosServer3 = res3.body.data.filter(video => video.isLocal === true).map(video => video.uuid)
497 remoteVideosServer3 = res3.body.data.filter(video => video.isLocal === false).map(video => video.uuid)
0e1dc3e7
C
498 })
499
500 it('Should view multiple videos on owned servers', async function () {
6b616860 501 this.timeout(30000)
0e1dc3e7 502
b5c0e955 503 await viewVideo(servers[2].url, localVideosServer3[0])
511765c9 504 await wait(1000)
b5c0e955
C
505
506 await viewVideo(servers[2].url, localVideosServer3[0])
511765c9 507 await viewVideo(servers[2].url, localVideosServer3[1])
b5c0e955 508
511765c9 509 await wait(1000)
b5c0e955 510
0b353d1d
C
511 await viewVideo(servers[2].url, localVideosServer3[0])
512 await viewVideo(servers[2].url, localVideosServer3[0])
0e1dc3e7 513
3cd0734f 514 await waitJobs(servers)
0e1dc3e7 515
6b616860
C
516 // Wait the repeatable job
517 await wait(6000)
518
0e1dc3e7
C
519 for (const server of servers) {
520 const res = await getVideosList(server.url)
521
522 const videos = res.body.data
9a27cdc2
C
523 const video0 = videos.find(v => v.uuid === localVideosServer3[0])
524 const video1 = videos.find(v => v.uuid === localVideosServer3[1])
5f04dd2f 525
1f3e9fec
C
526 expect(video0.views).to.equal(3)
527 expect(video1.views).to.equal(1)
0e1dc3e7
C
528 }
529 })
530
531 it('Should view multiple videos on each servers', async function () {
24163420 532 this.timeout(45000)
0e1dc3e7
C
533
534 const tasks: Promise<any>[] = []
1f3e9fec
C
535 tasks.push(viewVideo(servers[0].url, remoteVideosServer1[0]))
536 tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0]))
537 tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0]))
538 tasks.push(viewVideo(servers[2].url, remoteVideosServer3[0]))
539 tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1]))
540 tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1]))
541 tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1]))
542 tasks.push(viewVideo(servers[2].url, localVideosServer3[1]))
543 tasks.push(viewVideo(servers[2].url, localVideosServer3[1]))
544 tasks.push(viewVideo(servers[2].url, localVideosServer3[1]))
0e1dc3e7
C
545
546 await Promise.all(tasks)
547
3cd0734f 548 await waitJobs(servers)
0e1dc3e7 549
6b616860 550 // Wait the repeatable job
24163420 551 await wait(16000)
6b616860 552
0e1dc3e7
C
553 let baseVideos = null
554
555 for (const server of servers) {
556 const res = await getVideosList(server.url)
557
558 const videos = res.body.data
559
560 // Initialize base videos for future comparisons
561 if (baseVideos === null) {
562 baseVideos = videos
35a097b8 563 continue
0e1dc3e7
C
564 }
565
566 for (const baseVideo of baseVideos) {
567 const sameVideo = videos.find(video => video.name === baseVideo.name)
568 expect(baseVideo.views).to.equal(sameVideo.views)
569 }
570 }
571 })
572
573 it('Should like and dislikes videos on different services', async function () {
572f8d3d 574 this.timeout(20000)
0e1dc3e7 575
94a5ff8a 576 await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like')
2ba92871 577 await wait(500)
94a5ff8a 578 await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'dislike')
2ba92871 579 await wait(500)
94a5ff8a
C
580 await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like')
581 await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'like')
2ba92871 582 await wait(500)
94a5ff8a
C
583 await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'dislike')
584 await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[1], 'dislike')
2ba92871 585 await wait(500)
94a5ff8a 586 await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[0], 'like')
0e1dc3e7 587
3cd0734f 588 await waitJobs(servers)
0e1dc3e7
C
589
590 let baseVideos = null
591 for (const server of servers) {
592 const res = await getVideosList(server.url)
593
594 const videos = res.body.data
595
596 // Initialize base videos for future comparisons
597 if (baseVideos === null) {
598 baseVideos = videos
35a097b8 599 continue
0e1dc3e7
C
600 }
601
35a097b8 602 for (const baseVideo of baseVideos) {
0e1dc3e7
C
603 const sameVideo = videos.find(video => video.name === baseVideo.name)
604 expect(baseVideo.likes).to.equal(sameVideo.likes)
605 expect(baseVideo.dislikes).to.equal(sameVideo.dislikes)
35a097b8 606 }
0e1dc3e7
C
607 }
608 })
609 })
610
611 describe('Should manipulate these videos', function () {
9a27cdc2 612 it('Should update the video 3 by asking server 3', async function () {
572f8d3d 613 this.timeout(10000)
0e1dc3e7
C
614
615 const attributes = {
616 name: 'my super video updated',
617 category: 10,
618 licence: 7,
9d3ef9fe 619 language: 'fr',
0e1dc3e7
C
620 nsfw: true,
621 description: 'my super description updated',
2422c46b 622 support: 'my super support text updated',
ac81d1a0
C
623 tags: [ 'tag_up_1', 'tag_up_2' ],
624 thumbnailfile: 'thumbnail.jpg',
7519127b 625 originallyPublishedAt: '2019-02-11T13:38:14.449Z',
ac81d1a0 626 previewfile: 'preview.jpg'
0e1dc3e7
C
627 }
628
629 await updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes)
630
3cd0734f 631 await waitJobs(servers)
0e1dc3e7
C
632 })
633
9a27cdc2 634 it('Should have the video 3 updated on each server', async function () {
572f8d3d 635 this.timeout(10000)
0e1dc3e7
C
636
637 for (const server of servers) {
638 const res = await getVideosList(server.url)
639
640 const videos = res.body.data
641 const videoUpdated = videos.find(video => video.name === 'my super video updated')
0e1dc3e7 642 expect(!!videoUpdated).to.be.true
0e1dc3e7 643
7243f84d 644 const isLocal = server.url === 'http://localhost:' + servers[2].port
b1f5b93e
C
645 const checkAttributes = {
646 name: 'my super video updated',
647 category: 10,
648 licence: 7,
9d3ef9fe 649 language: 'fr',
b1f5b93e
C
650 nsfw: true,
651 description: 'my super description updated',
2422c46b 652 support: 'my super support text updated',
7519127b 653 originallyPublishedAt: '2019-02-11T13:38:14.449Z',
b64c950a
C
654 account: {
655 name: 'root',
7243f84d 656 host: 'localhost:' + servers[2].port
b64c950a 657 },
b1f5b93e
C
658 isLocal,
659 duration: 5,
47564bbe 660 commentsEnabled: true,
7f2cfe3a 661 downloadEnabled: true,
b1f5b93e
C
662 tags: [ 'tag_up_1', 'tag_up_2' ],
663 privacy: VideoPrivacy.PUBLIC,
664 channel: {
f6eebcb3
C
665 displayName: 'Main root channel',
666 name: 'root_channel',
b1f5b93e
C
667 description: '',
668 isLocal
669 },
670 fixture: 'video_short3.webm',
671 files: [
672 {
673 resolution: 720,
674 size: 292677
675 }
ac81d1a0
C
676 ],
677 thumbnailfile: 'thumbnail',
678 previewfile: 'preview'
b1f5b93e
C
679 }
680 await completeVideoCheck(server.url, videoUpdated, checkAttributes)
0e1dc3e7
C
681 }
682 })
683
9a27cdc2 684 it('Should remove the videos 3 and 3-2 by asking server 3', async function () {
572f8d3d 685 this.timeout(10000)
0e1dc3e7
C
686
687 await removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id)
688 await removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id)
689
3cd0734f 690 await waitJobs(servers)
0e1dc3e7
C
691 })
692
f05a1c30
C
693 it('Should not have files of videos 3 and 3-2 on each server', async function () {
694 for (const server of servers) {
695 await checkVideoFilesWereRemoved(toRemove[0].uuid, server.serverNumber)
696 await checkVideoFilesWereRemoved(toRemove[1].uuid, server.serverNumber)
697 }
698 })
699
9a27cdc2 700 it('Should have videos 1 and 3 on each server', async function () {
0e1dc3e7
C
701 for (const server of servers) {
702 const res = await getVideosList(server.url)
703
704 const videos = res.body.data
705 expect(videos).to.be.an('array')
706 expect(videos.length).to.equal(2)
707 expect(videos[0].name).not.to.equal(videos[1].name)
708 expect(videos[0].name).not.to.equal(toRemove[0].name)
709 expect(videos[1].name).not.to.equal(toRemove[0].name)
710 expect(videos[0].name).not.to.equal(toRemove[1].name)
711 expect(videos[1].name).not.to.equal(toRemove[1].name)
712
9a27cdc2 713 videoUUID = videos.find(video => video.name === 'my super name for server 1').uuid
0e1dc3e7
C
714 }
715 })
716
9a27cdc2 717 it('Should get the same video by UUID on each server', async function () {
0e1dc3e7
C
718 let baseVideo = null
719 for (const server of servers) {
720 const res = await getVideo(server.url, videoUUID)
721
722 const video = res.body
723
724 if (baseVideo === null) {
725 baseVideo = video
35a097b8 726 continue
0e1dc3e7
C
727 }
728
729 expect(baseVideo.name).to.equal(video.name)
730 expect(baseVideo.uuid).to.equal(video.uuid)
5d00a3d7
C
731 expect(baseVideo.category.id).to.equal(video.category.id)
732 expect(baseVideo.language.id).to.equal(video.language.id)
733 expect(baseVideo.licence.id).to.equal(video.licence.id)
0e1dc3e7 734 expect(baseVideo.nsfw).to.equal(video.nsfw)
b64c950a
C
735 expect(baseVideo.account.name).to.equal(video.account.name)
736 expect(baseVideo.account.displayName).to.equal(video.account.displayName)
737 expect(baseVideo.account.url).to.equal(video.account.url)
738 expect(baseVideo.account.host).to.equal(video.account.host)
0e1dc3e7
C
739 expect(baseVideo.tags).to.deep.equal(video.tags)
740 }
741 })
742
9a27cdc2 743 it('Should get the preview from each server', async function () {
0e1dc3e7
C
744 for (const server of servers) {
745 const res = await getVideo(server.url, videoUUID)
746 const video = res.body
747
7b0956ec 748 await testImage(server.url, 'video_short1-preview.webm', video.previewPath)
0e1dc3e7
C
749 }
750 })
751 })
752
d50acfab 753 describe('Should comment these videos', function () {
73c08093
C
754 let childOfFirstChild: VideoCommentThreadTree
755
d50acfab
C
756 it('Should add comment (threads and replies)', async function () {
757 this.timeout(25000)
758
759 {
760 const text = 'my super first comment'
761 await addVideoCommentThread(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID, text)
762 }
763
764 {
765 const text = 'my super second comment'
766 await addVideoCommentThread(servers[ 2 ].url, servers[ 2 ].accessToken, videoUUID, text)
767 }
768
3cd0734f 769 await waitJobs(servers)
d50acfab
C
770
771 {
772 const res = await getVideoCommentThreads(servers[1].url, videoUUID, 0, 5)
773 const threadId = res.body.data.find(c => c.text === 'my super first comment').id
774
775 const text = 'my super answer to thread 1'
776 await addVideoCommentReply(servers[ 1 ].url, servers[ 1 ].accessToken, videoUUID, threadId, text)
777 }
778
3cd0734f 779 await waitJobs(servers)
d50acfab
C
780
781 {
782 const res1 = await getVideoCommentThreads(servers[2].url, videoUUID, 0, 5)
783 const threadId = res1.body.data.find(c => c.text === 'my super first comment').id
784
785 const res2 = await getVideoThreadComments(servers[2].url, videoUUID, threadId)
786 const childCommentId = res2.body.children[0].comment.id
787
788 const text3 = 'my second answer to thread 1'
789 await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, videoUUID, threadId, text3)
790
791 const text2 = 'my super answer to answer of thread 1'
792 await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, videoUUID, childCommentId, text2)
793 }
794
3cd0734f 795 await waitJobs(servers)
d50acfab
C
796 })
797
798 it('Should have these threads', async function () {
799 for (const server of servers) {
800 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
801
802 expect(res.body.total).to.equal(2)
803 expect(res.body.data).to.be.an('array')
804 expect(res.body.data).to.have.lengthOf(2)
805
806 {
807 const comment: VideoComment = res.body.data.find(c => c.text === 'my super first comment')
808 expect(comment).to.not.be.undefined
809 expect(comment.inReplyToCommentId).to.be.null
810 expect(comment.account.name).to.equal('root')
7243f84d 811 expect(comment.account.host).to.equal('localhost:' + servers[0].port)
d50acfab
C
812 expect(comment.totalReplies).to.equal(3)
813 expect(dateIsValid(comment.createdAt as string)).to.be.true
814 expect(dateIsValid(comment.updatedAt as string)).to.be.true
815 }
816
817 {
818 const comment: VideoComment = res.body.data.find(c => c.text === 'my super second comment')
819 expect(comment).to.not.be.undefined
820 expect(comment.inReplyToCommentId).to.be.null
821 expect(comment.account.name).to.equal('root')
7243f84d 822 expect(comment.account.host).to.equal('localhost:' + servers[2].port)
d50acfab
C
823 expect(comment.totalReplies).to.equal(0)
824 expect(dateIsValid(comment.createdAt as string)).to.be.true
825 expect(dateIsValid(comment.updatedAt as string)).to.be.true
826 }
827 }
828 })
829
830 it('Should have these comments', async function () {
831 for (const server of servers) {
832 const res1 = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
833 const threadId = res1.body.data.find(c => c.text === 'my super first comment').id
834
835 const res2 = await getVideoThreadComments(server.url, videoUUID, threadId)
836
837 const tree: VideoCommentThreadTree = res2.body
838 expect(tree.comment.text).equal('my super first comment')
839 expect(tree.comment.account.name).equal('root')
7243f84d 840 expect(tree.comment.account.host).equal('localhost:' + servers[0].port)
d50acfab
C
841 expect(tree.children).to.have.lengthOf(2)
842
843 const firstChild = tree.children[0]
844 expect(firstChild.comment.text).to.equal('my super answer to thread 1')
845 expect(firstChild.comment.account.name).equal('root')
7243f84d 846 expect(firstChild.comment.account.host).equal('localhost:' + servers[1].port)
d50acfab
C
847 expect(firstChild.children).to.have.lengthOf(1)
848
73c08093 849 childOfFirstChild = firstChild.children[0]
d50acfab
C
850 expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1')
851 expect(childOfFirstChild.comment.account.name).equal('root')
7243f84d 852 expect(childOfFirstChild.comment.account.host).equal('localhost:' + servers[2].port)
d50acfab
C
853 expect(childOfFirstChild.children).to.have.lengthOf(0)
854
855 const secondChild = tree.children[1]
856 expect(secondChild.comment.text).to.equal('my second answer to thread 1')
857 expect(secondChild.comment.account.name).equal('root')
7243f84d 858 expect(secondChild.comment.account.host).equal('localhost:' + servers[2].port)
d50acfab
C
859 expect(secondChild.children).to.have.lengthOf(0)
860 }
861 })
47564bbe 862
73c08093
C
863 it('Should delete a reply', async function () {
864 this.timeout(10000)
865
866 await deleteVideoComment(servers[2].url, servers[2].accessToken, videoUUID, childOfFirstChild.comment.id)
867
3cd0734f 868 await waitJobs(servers)
73c08093
C
869 })
870
69222afa 871 it('Should have this comment marked as deleted', async function () {
73c08093
C
872 for (const server of servers) {
873 const res1 = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
874 const threadId = res1.body.data.find(c => c.text === 'my super first comment').id
875
876 const res2 = await getVideoThreadComments(server.url, videoUUID, threadId)
877
878 const tree: VideoCommentThreadTree = res2.body
879 expect(tree.comment.text).equal('my super first comment')
880
881 const firstChild = tree.children[0]
882 expect(firstChild.comment.text).to.equal('my super answer to thread 1')
69222afa
JM
883 expect(firstChild.children).to.have.lengthOf(1)
884
885 const deletedComment = firstChild.children[0].comment
886 expect(deletedComment.isDeleted).to.be.true
887 expect(deletedComment.deletedAt).to.not.be.null
888 expect(deletedComment.account).to.be.null
889 expect(deletedComment.text).to.equal('')
73c08093
C
890
891 const secondChild = tree.children[1]
892 expect(secondChild.comment.text).to.equal('my second answer to thread 1')
893 }
894 })
895
4cb6d457
C
896 it('Should delete the thread comments', async function () {
897 this.timeout(10000)
898
511765c9
C
899 const res = await getVideoCommentThreads(servers[ 0 ].url, videoUUID, 0, 5)
900 const threadId = res.body.data.find(c => c.text === 'my super first comment').id
901 await deleteVideoComment(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID, threadId)
4cb6d457 902
3cd0734f 903 await waitJobs(servers)
4cb6d457
C
904 })
905
69222afa 906 it('Should have the threads marked as deleted on other servers too', async function () {
4cb6d457
C
907 for (const server of servers) {
908 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
909
69222afa 910 expect(res.body.total).to.equal(2)
4cb6d457 911 expect(res.body.data).to.be.an('array')
69222afa 912 expect(res.body.data).to.have.lengthOf(2)
4cb6d457
C
913
914 {
915 const comment: VideoComment = res.body.data[0]
916 expect(comment).to.not.be.undefined
917 expect(comment.inReplyToCommentId).to.be.null
918 expect(comment.account.name).to.equal('root')
7243f84d 919 expect(comment.account.host).to.equal('localhost:' + servers[2].port)
4cb6d457
C
920 expect(comment.totalReplies).to.equal(0)
921 expect(dateIsValid(comment.createdAt as string)).to.be.true
922 expect(dateIsValid(comment.updatedAt as string)).to.be.true
923 }
69222afa
JM
924
925 {
926 const deletedComment: VideoComment = res.body.data[1]
927 expect(deletedComment).to.not.be.undefined
928 expect(deletedComment.isDeleted).to.be.true
929 expect(deletedComment.deletedAt).to.not.be.null
930 expect(deletedComment.text).to.equal('')
931 expect(deletedComment.inReplyToCommentId).to.be.null
932 expect(deletedComment.account).to.be.null
933 expect(deletedComment.totalReplies).to.equal(3)
934 expect(dateIsValid(deletedComment.createdAt as string)).to.be.true
935 expect(dateIsValid(deletedComment.updatedAt as string)).to.be.true
936 expect(dateIsValid(deletedComment.deletedAt as string)).to.be.true
937 }
4cb6d457
C
938 }
939 })
940
511765c9
C
941 it('Should delete a remote thread by the origin server', async function () {
942 const res = await getVideoCommentThreads(servers[ 0 ].url, videoUUID, 0, 5)
943 const threadId = res.body.data.find(c => c.text === 'my super second comment').id
944 await deleteVideoComment(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID, threadId)
945
946 await waitJobs(servers)
947 })
948
69222afa 949 it('Should have the threads marked as deleted on other servers too', async function () {
511765c9
C
950 for (const server of servers) {
951 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
952
69222afa
JM
953 expect(res.body.total).to.equal(2)
954 expect(res.body.data).to.have.lengthOf(2)
955
956 {
957 const comment: VideoComment = res.body.data[0]
958 expect(comment.text).to.equal('')
959 expect(comment.isDeleted).to.be.true
960 expect(comment.createdAt).to.not.be.null
961 expect(comment.deletedAt).to.not.be.null
962 expect(comment.account).to.be.null
963 expect(comment.totalReplies).to.equal(0)
964 }
965
966 {
967 const comment: VideoComment = res.body.data[1]
968 expect(comment.text).to.equal('')
969 expect(comment.isDeleted).to.be.true
970 expect(comment.createdAt).to.not.be.null
971 expect(comment.deletedAt).to.not.be.null
972 expect(comment.account).to.be.null
973 expect(comment.totalReplies).to.equal(3)
974 }
511765c9
C
975 }
976 })
977
53a94c7c 978 it('Should disable comments and download', async function () {
47564bbe
C
979 this.timeout(20000)
980
981 const attributes = {
53a94c7c
C
982 commentsEnabled: false,
983 downloadEnabled: false
47564bbe
C
984 }
985
986 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, attributes)
987
3cd0734f 988 await waitJobs(servers)
47564bbe
C
989
990 for (const server of servers) {
991 const res = await getVideo(server.url, videoUUID)
992 expect(res.body.commentsEnabled).to.be.false
53a94c7c 993 expect(res.body.downloadEnabled).to.be.false
47564bbe
C
994
995 const text = 'my super forbidden comment'
996 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text, 409)
997 }
998 })
d50acfab
C
999 })
1000
f595d394
C
1001 describe('With minimum parameters', function () {
1002 it('Should upload and propagate the video', async function () {
2186386c 1003 this.timeout(60000)
f595d394
C
1004
1005 const path = '/api/v1/videos/upload'
1006
1007 const req = request(servers[1].url)
1008 .post(path)
1009 .set('Accept', 'application/json')
1010 .set('Authorization', 'Bearer ' + servers[1].accessToken)
1011 .field('name', 'minimum parameters')
1012 .field('privacy', '1')
f595d394
C
1013 .field('channelId', '1')
1014
99d10301 1015 const filePath = join(__dirname, '..', '..', 'fixtures', 'video_short.webm')
f595d394
C
1016
1017 await req.attach('videofile', filePath)
1018 .expect(200)
1019
3cd0734f 1020 await waitJobs(servers)
f595d394
C
1021
1022 for (const server of servers) {
1023 const res = await getVideosList(server.url)
1024 const video = res.body.data.find(v => v.name === 'minimum parameters')
1025
7243f84d 1026 const isLocal = server.url === 'http://localhost:' + servers[1].port
b1f5b93e
C
1027 const checkAttributes = {
1028 name: 'minimum parameters',
1029 category: null,
1030 licence: null,
1031 language: null,
1032 nsfw: false,
1033 description: null,
2422c46b 1034 support: null,
b64c950a
C
1035 account: {
1036 name: 'root',
7243f84d 1037 host: 'localhost:' + servers[1].port
b64c950a 1038 },
b1f5b93e
C
1039 isLocal,
1040 duration: 5,
210709a9 1041 commentsEnabled: true,
7519127b 1042 downloadEnabled: true,
b1f5b93e
C
1043 tags: [ ],
1044 privacy: VideoPrivacy.PUBLIC,
1045 channel: {
f6eebcb3
C
1046 displayName: 'Main root channel',
1047 name: 'root_channel',
b1f5b93e
C
1048 description: '',
1049 isLocal
1050 },
1051 fixture: 'video_short.webm',
1052 files: [
1053 {
1054 resolution: 720,
cdf4cb9e 1055 size: 72000
b1f5b93e
C
1056 },
1057 {
1058 resolution: 480,
cdf4cb9e 1059 size: 45000
b1f5b93e
C
1060 },
1061 {
1062 resolution: 360,
cdf4cb9e 1063 size: 34600
b1f5b93e
C
1064 },
1065 {
1066 resolution: 240,
cdf4cb9e 1067 size: 24770
b1f5b93e
C
1068 }
1069 ]
1070 }
1071 await completeVideoCheck(server.url, video, checkAttributes)
f595d394
C
1072 }
1073 })
1074 })
1075
89231874
C
1076 describe('TMP directory', function () {
1077 it('Should have an empty tmp directory', async function () {
1078 for (const server of servers) {
1079 await checkTmpIsEmpty(server)
1080 }
1081 })
1082 })
1083
7c3b7976
C
1084 after(async function () {
1085 await cleanupTests(servers)
0e1dc3e7
C
1086 })
1087})