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