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