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