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