diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-28 13:59:22 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-28 13:59:22 +0100 |
commit | c5d31dba56d669c0df0209761c43c5a6ac7cec4a (patch) | |
tree | fe72b56a1c0e7beb6e092c393a00ddfe93a5d71f /server/tests/api/videos | |
parent | db799da3d2b2ea465165df78ff71effa653b6309 (diff) | |
download | PeerTube-c5d31dba56d669c0df0209761c43c5a6ac7cec4a.tar.gz PeerTube-c5d31dba56d669c0df0209761c43c5a6ac7cec4a.tar.zst PeerTube-c5d31dba56d669c0df0209761c43c5a6ac7cec4a.zip |
Tests directories refractor
Diffstat (limited to 'server/tests/api/videos')
-rw-r--r-- | server/tests/api/videos/multiple-servers.ts | 861 | ||||
-rw-r--r-- | server/tests/api/videos/services.ts | 85 | ||||
-rw-r--r-- | server/tests/api/videos/single-server.ts | 701 | ||||
-rw-r--r-- | server/tests/api/videos/video-abuse.ts | 145 | ||||
-rw-r--r-- | server/tests/api/videos/video-blacklist-management.ts | 162 | ||||
-rw-r--r-- | server/tests/api/videos/video-blacklist.ts | 98 | ||||
-rw-r--r-- | server/tests/api/videos/video-channels.ts | 139 | ||||
-rw-r--r-- | server/tests/api/videos/video-comments.ts | 154 | ||||
-rw-r--r-- | server/tests/api/videos/video-description.ts | 111 | ||||
-rw-r--r-- | server/tests/api/videos/video-privacy.ts | 159 | ||||
-rw-r--r-- | server/tests/api/videos/video-transcoder.ts | 97 |
11 files changed, 2712 insertions, 0 deletions
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts new file mode 100644 index 000000000..84f730a8e --- /dev/null +++ b/server/tests/api/videos/multiple-servers.ts | |||
@@ -0,0 +1,861 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | ||
5 | import { join } from 'path' | ||
6 | import * as request from 'supertest' | ||
7 | import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' | ||
8 | |||
9 | import { | ||
10 | addVideoChannel, dateIsValid, doubleFollow, flushAndRunMultipleServers, flushTests, getUserAccessToken, getVideo, | ||
11 | getVideoChannelsList, getVideosList, killallServers, rateVideo, removeVideo, ServerInfo, setAccessTokensToServers, testVideoImage, | ||
12 | updateVideo, uploadVideo, wait, webtorrentAdd | ||
13 | } from '../../utils/index' | ||
14 | import { createUser } from '../../utils/users/users' | ||
15 | import { | ||
16 | addVideoCommentReply, addVideoCommentThread, getVideoCommentThreads, | ||
17 | getVideoThreadComments | ||
18 | } from '../../utils/videos/video-comments' | ||
19 | import { viewVideo } from '../../utils/videos/videos' | ||
20 | |||
21 | const expect = chai.expect | ||
22 | |||
23 | describe('Test multiple servers', function () { | ||
24 | let servers: ServerInfo[] = [] | ||
25 | const toRemove = [] | ||
26 | let videoUUID = '' | ||
27 | let videoChannelId: number | ||
28 | |||
29 | before(async function () { | ||
30 | this.timeout(120000) | ||
31 | |||
32 | servers = await flushAndRunMultipleServers(3) | ||
33 | |||
34 | // Get the access tokens | ||
35 | await setAccessTokensToServers(servers) | ||
36 | |||
37 | const videoChannel = { | ||
38 | name: 'my channel', | ||
39 | description: 'super channel' | ||
40 | } | ||
41 | await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel) | ||
42 | const channelRes = await getVideoChannelsList(servers[0].url, 0, 1) | ||
43 | videoChannelId = channelRes.body.data[0].id | ||
44 | |||
45 | // Server 1 and server 2 follow each other | ||
46 | await doubleFollow(servers[0], servers[1]) | ||
47 | // Server 1 and server 3 follow each other | ||
48 | await doubleFollow(servers[0], servers[2]) | ||
49 | // Server 2 and server 3 follow each other | ||
50 | await doubleFollow(servers[1], servers[2]) | ||
51 | }) | ||
52 | |||
53 | it('Should not have videos for all servers', async function () { | ||
54 | for (const server of servers) { | ||
55 | const res = await getVideosList(server.url) | ||
56 | const videos = res.body.data | ||
57 | expect(videos).to.be.an('array') | ||
58 | expect(videos.length).to.equal(0) | ||
59 | } | ||
60 | }) | ||
61 | |||
62 | describe('Should upload the video and propagate on each server', function () { | ||
63 | it('Should upload the video on server 1 and propagate on each server', async function () { | ||
64 | this.timeout(25000) | ||
65 | |||
66 | const videoAttributes = { | ||
67 | name: 'my super name for server 1', | ||
68 | category: 5, | ||
69 | licence: 4, | ||
70 | language: 9, | ||
71 | nsfw: true, | ||
72 | description: 'my super description for server 1', | ||
73 | tags: [ 'tag1p1', 'tag2p1' ], | ||
74 | channelId: videoChannelId, | ||
75 | fixture: 'video_short1.webm' | ||
76 | } | ||
77 | await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) | ||
78 | |||
79 | await wait(10000) | ||
80 | |||
81 | // All servers should have this video | ||
82 | for (const server of servers) { | ||
83 | let baseMagnet = null | ||
84 | |||
85 | const res = await getVideosList(server.url) | ||
86 | |||
87 | const videos = res.body.data | ||
88 | expect(videos).to.be.an('array') | ||
89 | expect(videos.length).to.equal(1) | ||
90 | const video = videos[0] | ||
91 | expect(video.name).to.equal('my super name for server 1') | ||
92 | expect(video.category).to.equal(5) | ||
93 | expect(video.categoryLabel).to.equal('Sports') | ||
94 | expect(video.licence).to.equal(4) | ||
95 | expect(video.licenceLabel).to.equal('Attribution - Non Commercial') | ||
96 | expect(video.language).to.equal(9) | ||
97 | expect(video.languageLabel).to.equal('Japanese') | ||
98 | expect(video.nsfw).to.be.ok | ||
99 | expect(video.description).to.equal('my super description for server 1') | ||
100 | expect(video.serverHost).to.equal('localhost:9001') | ||
101 | expect(video.duration).to.equal(10) | ||
102 | expect(dateIsValid(video.createdAt)).to.be.true | ||
103 | expect(dateIsValid(video.updatedAt)).to.be.true | ||
104 | expect(video.accountName).to.equal('root') | ||
105 | |||
106 | const res2 = await getVideo(server.url, video.uuid) | ||
107 | const videoDetails = res2.body | ||
108 | |||
109 | expect(videoDetails.channel.name).to.equal('my channel') | ||
110 | expect(videoDetails.channel.description).to.equal('super channel') | ||
111 | expect(videoDetails.account.name).to.equal('root') | ||
112 | expect(dateIsValid(videoDetails.channel.createdAt)).to.be.true | ||
113 | expect(dateIsValid(videoDetails.channel.updatedAt)).to.be.true | ||
114 | expect(videoDetails.files).to.have.lengthOf(1) | ||
115 | expect(videoDetails.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ]) | ||
116 | |||
117 | const file = videoDetails.files[0] | ||
118 | const magnetUri = file.magnetUri | ||
119 | expect(file.magnetUri).to.have.lengthOf.above(2) | ||
120 | expect(file.torrentUrl).to | ||
121 | .equal(`http://${videoDetails.serverHost}/static/torrents/${videoDetails.uuid}-${file.resolution}.torrent`) | ||
122 | expect(file.fileUrl).to.equal(`http://${videoDetails.serverHost}/static/webseed/${videoDetails.uuid}-${file.resolution}.webm`) | ||
123 | expect(file.resolution).to.equal(720) | ||
124 | expect(file.resolutionLabel).to.equal('720p') | ||
125 | expect(file.size).to.equal(572456) | ||
126 | |||
127 | if (server.url !== 'http://localhost:9001') { | ||
128 | expect(video.isLocal).to.be.false | ||
129 | expect(videoDetails.channel.isLocal).to.be.false | ||
130 | } else { | ||
131 | expect(video.isLocal).to.be.true | ||
132 | expect(videoDetails.channel.isLocal).to.be.true | ||
133 | } | ||
134 | |||
135 | // All servers should have the same magnet Uri | ||
136 | if (baseMagnet === null) { | ||
137 | baseMagnet = magnetUri | ||
138 | } else { | ||
139 | expect(baseMagnet).to.equal(magnetUri) | ||
140 | } | ||
141 | |||
142 | const test = await testVideoImage(server.url, 'video_short1.webm', video.thumbnailPath) | ||
143 | expect(test).to.equal(true) | ||
144 | } | ||
145 | }) | ||
146 | |||
147 | it('Should upload the video on server 2 and propagate on each server', async function () { | ||
148 | this.timeout(50000) | ||
149 | |||
150 | const user = { | ||
151 | username: 'user1', | ||
152 | password: 'super_password' | ||
153 | } | ||
154 | await createUser(servers[1].url, servers[1].accessToken, user.username, user.password) | ||
155 | const userAccessToken = await getUserAccessToken(servers[1], user) | ||
156 | |||
157 | const videoAttributes = { | ||
158 | name: 'my super name for server 2', | ||
159 | category: 4, | ||
160 | licence: 3, | ||
161 | language: 11, | ||
162 | nsfw: true, | ||
163 | description: 'my super description for server 2', | ||
164 | tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ], | ||
165 | fixture: 'video_short2.webm' | ||
166 | } | ||
167 | await uploadVideo(servers[1].url, userAccessToken, videoAttributes) | ||
168 | |||
169 | // Transcoding | ||
170 | await wait(30000) | ||
171 | |||
172 | // All servers should have this video | ||
173 | for (const server of servers) { | ||
174 | let baseMagnet = {} | ||
175 | |||
176 | const res = await getVideosList(server.url) | ||
177 | |||
178 | const videos = res.body.data | ||
179 | expect(videos).to.be.an('array') | ||
180 | expect(videos.length).to.equal(2) | ||
181 | const video = videos[1] | ||
182 | expect(video.name).to.equal('my super name for server 2') | ||
183 | expect(video.category).to.equal(4) | ||
184 | expect(video.categoryLabel).to.equal('Art') | ||
185 | expect(video.licence).to.equal(3) | ||
186 | expect(video.licenceLabel).to.equal('Attribution - No Derivatives') | ||
187 | expect(video.language).to.equal(11) | ||
188 | expect(video.languageLabel).to.equal('German') | ||
189 | expect(video.nsfw).to.be.true | ||
190 | expect(video.description).to.equal('my super description for server 2') | ||
191 | expect(video.serverHost).to.equal('localhost:9002') | ||
192 | expect(video.duration).to.equal(5) | ||
193 | expect(dateIsValid(video.createdAt)).to.be.true | ||
194 | expect(dateIsValid(video.updatedAt)).to.be.true | ||
195 | expect(video.accountName).to.equal('user1') | ||
196 | |||
197 | if (server.url !== 'http://localhost:9002') { | ||
198 | expect(video.isLocal).to.be.false | ||
199 | } else { | ||
200 | expect(video.isLocal).to.be.true | ||
201 | } | ||
202 | |||
203 | const res2 = await getVideo(server.url, video.uuid) | ||
204 | const videoDetails = res2.body | ||
205 | |||
206 | expect(videoDetails.channel.name).to.equal('Default user1 channel') | ||
207 | expect(dateIsValid(videoDetails.channel.createdAt)).to.be.true | ||
208 | expect(dateIsValid(videoDetails.channel.updatedAt)).to.be.true | ||
209 | expect(videoDetails.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ]) | ||
210 | |||
211 | expect(videoDetails.files).to.have.lengthOf(4) | ||
212 | |||
213 | // Check common attributes | ||
214 | for (const file of videoDetails.files) { | ||
215 | expect(file.magnetUri).to.have.lengthOf.above(2) | ||
216 | |||
217 | // All servers should have the same magnet Uri | ||
218 | if (baseMagnet[file.resolution] === undefined) { | ||
219 | baseMagnet[file.resolution] = file.magnet | ||
220 | } else { | ||
221 | expect(baseMagnet[file.resolution]).to.equal(file.magnet) | ||
222 | } | ||
223 | } | ||
224 | |||
225 | const file240p = videoDetails.files.find(f => f.resolution === 240) | ||
226 | expect(file240p).not.to.be.undefined | ||
227 | expect(file240p.resolutionLabel).to.equal('240p') | ||
228 | expect(file240p.size).to.be.above(180000).and.below(200000) | ||
229 | |||
230 | const file360p = videoDetails.files.find(f => f.resolution === 360) | ||
231 | expect(file360p).not.to.be.undefined | ||
232 | expect(file360p.resolutionLabel).to.equal('360p') | ||
233 | expect(file360p.size).to.be.above(270000).and.below(290000) | ||
234 | |||
235 | const file480p = videoDetails.files.find(f => f.resolution === 480) | ||
236 | expect(file480p).not.to.be.undefined | ||
237 | expect(file480p.resolutionLabel).to.equal('480p') | ||
238 | expect(file480p.size).to.be.above(380000).and.below(400000) | ||
239 | |||
240 | const file720p = videoDetails.files.find(f => f.resolution === 720) | ||
241 | expect(file720p).not.to.be.undefined | ||
242 | expect(file720p.resolutionLabel).to.equal('720p') | ||
243 | expect(file720p.size).to.be.above(700000).and.below(7200000) | ||
244 | |||
245 | const test = await testVideoImage(server.url, 'video_short2.webm', videoDetails.thumbnailPath) | ||
246 | expect(test).to.equal(true) | ||
247 | } | ||
248 | }) | ||
249 | |||
250 | it('Should upload two videos on server 3 and propagate on each server', async function () { | ||
251 | this.timeout(45000) | ||
252 | |||
253 | const videoAttributes1 = { | ||
254 | name: 'my super name for server 3', | ||
255 | category: 6, | ||
256 | licence: 5, | ||
257 | language: 11, | ||
258 | nsfw: true, | ||
259 | description: 'my super description for server 3', | ||
260 | tags: [ 'tag1p3' ], | ||
261 | fixture: 'video_short3.webm' | ||
262 | } | ||
263 | await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes1) | ||
264 | |||
265 | const videoAttributes2 = { | ||
266 | name: 'my super name for server 3-2', | ||
267 | category: 7, | ||
268 | licence: 6, | ||
269 | language: 12, | ||
270 | nsfw: false, | ||
271 | description: 'my super description for server 3-2', | ||
272 | tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ], | ||
273 | fixture: 'video_short.webm' | ||
274 | } | ||
275 | await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes2) | ||
276 | |||
277 | await wait(10000) | ||
278 | |||
279 | let baseMagnet = null | ||
280 | // All servers should have this video | ||
281 | for (const server of servers) { | ||
282 | const res = await getVideosList(server.url) | ||
283 | |||
284 | const videos = res.body.data | ||
285 | expect(videos).to.be.an('array') | ||
286 | expect(videos.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 (videos[2].name === 'my super name for server 3') { | ||
292 | video1 = videos[2] | ||
293 | video2 = videos[3] | ||
294 | } else { | ||
295 | video1 = videos[3] | ||
296 | video2 = videos[2] | ||
297 | } | ||
298 | |||
299 | expect(video1.name).to.equal('my super name for server 3') | ||
300 | expect(video1.category).to.equal(6) | ||
301 | expect(video1.categoryLabel).to.equal('Travels') | ||
302 | expect(video1.licence).to.equal(5) | ||
303 | expect(video1.licenceLabel).to.equal('Attribution - Non Commercial - Share Alike') | ||
304 | expect(video1.language).to.equal(11) | ||
305 | expect(video1.languageLabel).to.equal('German') | ||
306 | expect(video1.nsfw).to.be.ok | ||
307 | expect(video1.description).to.equal('my super description for server 3') | ||
308 | expect(video1.serverHost).to.equal('localhost:9003') | ||
309 | expect(video1.duration).to.equal(5) | ||
310 | expect(video1.accountName).to.equal('root') | ||
311 | expect(dateIsValid(video1.createdAt)).to.be.true | ||
312 | expect(dateIsValid(video1.updatedAt)).to.be.true | ||
313 | |||
314 | const res2 = await getVideo(server.url, video1.id) | ||
315 | const video1Details = res2.body | ||
316 | expect(video1Details.files).to.have.lengthOf(1) | ||
317 | expect(video1Details.tags).to.deep.equal([ 'tag1p3' ]) | ||
318 | |||
319 | const file1 = video1Details.files[0] | ||
320 | expect(file1.magnetUri).to.have.lengthOf.above(2) | ||
321 | expect(file1.resolution).to.equal(720) | ||
322 | expect(file1.resolutionLabel).to.equal('720p') | ||
323 | expect(file1.size).to.equal(292677) | ||
324 | |||
325 | expect(video2.name).to.equal('my super name for server 3-2') | ||
326 | expect(video2.category).to.equal(7) | ||
327 | expect(video2.categoryLabel).to.equal('Gaming') | ||
328 | expect(video2.licence).to.equal(6) | ||
329 | expect(video2.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | ||
330 | expect(video2.language).to.equal(12) | ||
331 | expect(video2.languageLabel).to.equal('Korean') | ||
332 | expect(video2.nsfw).to.be.false | ||
333 | expect(video2.description).to.equal('my super description for server 3-2') | ||
334 | expect(video2.serverHost).to.equal('localhost:9003') | ||
335 | expect(video2.duration).to.equal(5) | ||
336 | expect(video2.accountName).to.equal('root') | ||
337 | expect(dateIsValid(video2.createdAt)).to.be.true | ||
338 | expect(dateIsValid(video2.updatedAt)).to.be.true | ||
339 | |||
340 | const res3 = await getVideo(server.url, video2.id) | ||
341 | const video2Details = res3.body | ||
342 | expect(video2Details.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ]) | ||
343 | |||
344 | expect(video2Details.files).to.have.lengthOf(1) | ||
345 | |||
346 | const file2 = video2Details.files[0] | ||
347 | const magnetUri2 = file2.magnetUri | ||
348 | expect(file2.magnetUri).to.have.lengthOf.above(2) | ||
349 | expect(file2.resolution).to.equal(720) | ||
350 | expect(file2.resolutionLabel).to.equal('720p') | ||
351 | expect(file2.size).to.equal(218910) | ||
352 | |||
353 | if (server.url !== 'http://localhost:9003') { | ||
354 | expect(video1.isLocal).to.be.false | ||
355 | expect(video2.isLocal).to.be.false | ||
356 | } else { | ||
357 | expect(video1.isLocal).to.be.true | ||
358 | expect(video2.isLocal).to.be.true | ||
359 | } | ||
360 | |||
361 | // All servers should have the same magnet Uri | ||
362 | if (baseMagnet === null) { | ||
363 | baseMagnet = magnetUri2 | ||
364 | } else { | ||
365 | expect(baseMagnet).to.equal(magnetUri2) | ||
366 | } | ||
367 | |||
368 | const test1 = await testVideoImage(server.url, 'video_short3.webm', video1.thumbnailPath) | ||
369 | expect(test1).to.equal(true) | ||
370 | |||
371 | const test2 = await testVideoImage(server.url, 'video_short.webm', video2.thumbnailPath) | ||
372 | expect(test2).to.equal(true) | ||
373 | } | ||
374 | }) | ||
375 | }) | ||
376 | |||
377 | describe('Should seed the uploaded video', function () { | ||
378 | it('Should add the file 1 by asking server 3', async function () { | ||
379 | this.timeout(10000) | ||
380 | |||
381 | const res = await getVideosList(servers[2].url) | ||
382 | |||
383 | const video = res.body.data[0] | ||
384 | toRemove.push(res.body.data[2]) | ||
385 | toRemove.push(res.body.data[3]) | ||
386 | |||
387 | const res2 = await getVideo(servers[2].url, video.id) | ||
388 | const videoDetails = res2.body | ||
389 | |||
390 | const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri) | ||
391 | expect(torrent.files).to.be.an('array') | ||
392 | expect(torrent.files.length).to.equal(1) | ||
393 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
394 | }) | ||
395 | |||
396 | it('Should add the file 2 by asking server 1', async function () { | ||
397 | this.timeout(10000) | ||
398 | |||
399 | const res = await getVideosList(servers[0].url) | ||
400 | |||
401 | const video = res.body.data[1] | ||
402 | const res2 = await getVideo(servers[0].url, video.id) | ||
403 | const videoDetails = res2.body | ||
404 | |||
405 | const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri) | ||
406 | expect(torrent.files).to.be.an('array') | ||
407 | expect(torrent.files.length).to.equal(1) | ||
408 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
409 | }) | ||
410 | |||
411 | it('Should add the file 3 by asking server 2', async function () { | ||
412 | this.timeout(10000) | ||
413 | |||
414 | const res = await getVideosList(servers[1].url) | ||
415 | |||
416 | const video = res.body.data[2] | ||
417 | const res2 = await getVideo(servers[1].url, video.id) | ||
418 | const videoDetails = res2.body | ||
419 | |||
420 | const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri) | ||
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(10000) | ||
428 | |||
429 | const res = await getVideosList(servers[0].url) | ||
430 | |||
431 | const video = res.body.data[3] | ||
432 | const res2 = await getVideo(servers[0].url, video.id) | ||
433 | const videoDetails = res2.body | ||
434 | |||
435 | const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri) | ||
436 | expect(torrent.files).to.be.an('array') | ||
437 | expect(torrent.files.length).to.equal(1) | ||
438 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
439 | }) | ||
440 | |||
441 | it('Should add the file 2 in 360p by asking server 1', async function () { | ||
442 | this.timeout(10000) | ||
443 | |||
444 | const res = await getVideosList(servers[0].url) | ||
445 | |||
446 | const video = res.body.data.find(v => v.name === 'my super name for server 2') | ||
447 | const res2 = await getVideo(servers[0].url, video.id) | ||
448 | const videoDetails = res2.body | ||
449 | |||
450 | const file = videoDetails.files.find(f => f.resolution === 360) | ||
451 | expect(file).not.to.be.undefined | ||
452 | |||
453 | const torrent = await webtorrentAdd(file.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 | |||
460 | describe('Should update video views, likes and dislikes', function () { | ||
461 | let localVideosServer3 = [] | ||
462 | let remoteVideosServer1 = [] | ||
463 | let remoteVideosServer2 = [] | ||
464 | let remoteVideosServer3 = [] | ||
465 | |||
466 | before(async function () { | ||
467 | const res1 = await getVideosList(servers[0].url) | ||
468 | remoteVideosServer1 = res1.body.data.filter(video => video.isLocal === false).map(video => video.uuid) | ||
469 | |||
470 | const res2 = await getVideosList(servers[1].url) | ||
471 | remoteVideosServer2 = res2.body.data.filter(video => video.isLocal === false).map(video => video.uuid) | ||
472 | |||
473 | const res3 = await getVideosList(servers[2].url) | ||
474 | localVideosServer3 = res3.body.data.filter(video => video.isLocal === true).map(video => video.uuid) | ||
475 | remoteVideosServer3 = res3.body.data.filter(video => video.isLocal === false).map(video => video.uuid) | ||
476 | }) | ||
477 | |||
478 | it('Should view multiple videos on owned servers', async function () { | ||
479 | this.timeout(10000) | ||
480 | |||
481 | const tasks: Promise<any>[] = [] | ||
482 | tasks.push(viewVideo(servers[2].url, localVideosServer3[0])) | ||
483 | tasks.push(viewVideo(servers[2].url, localVideosServer3[0])) | ||
484 | tasks.push(viewVideo(servers[2].url, localVideosServer3[0])) | ||
485 | tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) | ||
486 | |||
487 | await Promise.all(tasks) | ||
488 | |||
489 | await wait(5000) | ||
490 | |||
491 | for (const server of servers) { | ||
492 | const res = await getVideosList(server.url) | ||
493 | |||
494 | const videos = res.body.data | ||
495 | const video0 = videos.find(v => v.uuid === localVideosServer3[0]) | ||
496 | const video1 = videos.find(v => v.uuid === localVideosServer3[1]) | ||
497 | |||
498 | expect(video0.views).to.equal(3) | ||
499 | expect(video1.views).to.equal(1) | ||
500 | } | ||
501 | }) | ||
502 | |||
503 | it('Should view multiple videos on each servers', async function () { | ||
504 | this.timeout(15000) | ||
505 | |||
506 | const tasks: Promise<any>[] = [] | ||
507 | tasks.push(viewVideo(servers[0].url, remoteVideosServer1[0])) | ||
508 | tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0])) | ||
509 | tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0])) | ||
510 | tasks.push(viewVideo(servers[2].url, remoteVideosServer3[0])) | ||
511 | tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) | ||
512 | tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) | ||
513 | tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) | ||
514 | tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) | ||
515 | tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) | ||
516 | tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) | ||
517 | |||
518 | await Promise.all(tasks) | ||
519 | |||
520 | await wait(10000) | ||
521 | |||
522 | let baseVideos = null | ||
523 | |||
524 | for (const server of servers) { | ||
525 | const res = await getVideosList(server.url) | ||
526 | |||
527 | const videos = res.body.data | ||
528 | |||
529 | // Initialize base videos for future comparisons | ||
530 | if (baseVideos === null) { | ||
531 | baseVideos = videos | ||
532 | continue | ||
533 | } | ||
534 | |||
535 | for (const baseVideo of baseVideos) { | ||
536 | const sameVideo = videos.find(video => video.name === baseVideo.name) | ||
537 | expect(baseVideo.views).to.equal(sameVideo.views) | ||
538 | } | ||
539 | } | ||
540 | }) | ||
541 | |||
542 | it('Should like and dislikes videos on different services', async function () { | ||
543 | this.timeout(20000) | ||
544 | |||
545 | const tasks: Promise<any>[] = [] | ||
546 | tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like')) | ||
547 | tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'dislike')) | ||
548 | tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like')) | ||
549 | tasks.push(rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'like')) | ||
550 | tasks.push(rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'dislike')) | ||
551 | tasks.push(rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[1], 'dislike')) | ||
552 | tasks.push(rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[0], 'like')) | ||
553 | |||
554 | await Promise.all(tasks) | ||
555 | |||
556 | await wait(10000) | ||
557 | |||
558 | let baseVideos = null | ||
559 | for (const server of servers) { | ||
560 | const res = await getVideosList(server.url) | ||
561 | |||
562 | const videos = res.body.data | ||
563 | |||
564 | // Initialize base videos for future comparisons | ||
565 | if (baseVideos === null) { | ||
566 | baseVideos = videos | ||
567 | continue | ||
568 | } | ||
569 | |||
570 | for (const baseVideo of baseVideos) { | ||
571 | const sameVideo = videos.find(video => video.name === baseVideo.name) | ||
572 | expect(baseVideo.likes).to.equal(sameVideo.likes) | ||
573 | expect(baseVideo.dislikes).to.equal(sameVideo.dislikes) | ||
574 | } | ||
575 | } | ||
576 | }) | ||
577 | }) | ||
578 | |||
579 | describe('Should manipulate these videos', function () { | ||
580 | it('Should update the video 3 by asking server 3', async function () { | ||
581 | this.timeout(10000) | ||
582 | |||
583 | const attributes = { | ||
584 | name: 'my super video updated', | ||
585 | category: 10, | ||
586 | licence: 7, | ||
587 | language: 13, | ||
588 | nsfw: true, | ||
589 | description: 'my super description updated', | ||
590 | tags: [ 'tag_up_1', 'tag_up_2' ] | ||
591 | } | ||
592 | |||
593 | await updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes) | ||
594 | |||
595 | await wait(5000) | ||
596 | }) | ||
597 | |||
598 | it('Should have the video 3 updated on each server', async function () { | ||
599 | this.timeout(10000) | ||
600 | |||
601 | for (const server of servers) { | ||
602 | const res = await getVideosList(server.url) | ||
603 | |||
604 | const videos = res.body.data | ||
605 | const videoUpdated = videos.find(video => video.name === 'my super video updated') | ||
606 | |||
607 | expect(!!videoUpdated).to.be.true | ||
608 | expect(videoUpdated.category).to.equal(10) | ||
609 | expect(videoUpdated.categoryLabel).to.equal('Entertainment') | ||
610 | expect(videoUpdated.licence).to.equal(7) | ||
611 | expect(videoUpdated.licenceLabel).to.equal('Public Domain Dedication') | ||
612 | expect(videoUpdated.language).to.equal(13) | ||
613 | expect(videoUpdated.languageLabel).to.equal('French') | ||
614 | expect(videoUpdated.nsfw).to.be.ok | ||
615 | expect(videoUpdated.description).to.equal('my super description updated') | ||
616 | expect(dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true | ||
617 | |||
618 | const res2 = await getVideo(server.url, videoUpdated.uuid) | ||
619 | const videoUpdatedDetails = res2.body | ||
620 | expect(videoUpdatedDetails.tags).to.deep.equal([ 'tag_up_1', 'tag_up_2' ]) | ||
621 | |||
622 | const file = videoUpdatedDetails.files[0] | ||
623 | expect(file.magnetUri).to.have.lengthOf.above(2) | ||
624 | expect(file.resolution).to.equal(720) | ||
625 | expect(file.resolutionLabel).to.equal('720p') | ||
626 | expect(file.size).to.equal(292677) | ||
627 | |||
628 | const test = await testVideoImage(server.url, 'video_short3.webm', videoUpdated.thumbnailPath) | ||
629 | expect(test).to.equal(true) | ||
630 | |||
631 | // Avoid "duplicate torrent" errors | ||
632 | const refreshWebTorrent = true | ||
633 | const torrent = await webtorrentAdd(videoUpdatedDetails .files[0].magnetUri, refreshWebTorrent) | ||
634 | expect(torrent.files).to.be.an('array') | ||
635 | expect(torrent.files.length).to.equal(1) | ||
636 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
637 | } | ||
638 | }) | ||
639 | |||
640 | it('Should remove the videos 3 and 3-2 by asking server 3', async function () { | ||
641 | this.timeout(10000) | ||
642 | |||
643 | await removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id) | ||
644 | await removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id) | ||
645 | |||
646 | await wait(5000) | ||
647 | }) | ||
648 | |||
649 | it('Should have videos 1 and 3 on each server', async function () { | ||
650 | for (const server of servers) { | ||
651 | const res = await getVideosList(server.url) | ||
652 | |||
653 | const videos = res.body.data | ||
654 | expect(videos).to.be.an('array') | ||
655 | expect(videos.length).to.equal(2) | ||
656 | expect(videos[0].name).not.to.equal(videos[1].name) | ||
657 | expect(videos[0].name).not.to.equal(toRemove[0].name) | ||
658 | expect(videos[1].name).not.to.equal(toRemove[0].name) | ||
659 | expect(videos[0].name).not.to.equal(toRemove[1].name) | ||
660 | expect(videos[1].name).not.to.equal(toRemove[1].name) | ||
661 | |||
662 | videoUUID = videos.find(video => video.name === 'my super name for server 1').uuid | ||
663 | } | ||
664 | }) | ||
665 | |||
666 | it('Should get the same video by UUID on each server', async function () { | ||
667 | let baseVideo = null | ||
668 | for (const server of servers) { | ||
669 | const res = await getVideo(server.url, videoUUID) | ||
670 | |||
671 | const video = res.body | ||
672 | |||
673 | if (baseVideo === null) { | ||
674 | baseVideo = video | ||
675 | continue | ||
676 | } | ||
677 | |||
678 | expect(baseVideo.name).to.equal(video.name) | ||
679 | expect(baseVideo.uuid).to.equal(video.uuid) | ||
680 | expect(baseVideo.category).to.equal(video.category) | ||
681 | expect(baseVideo.language).to.equal(video.language) | ||
682 | expect(baseVideo.licence).to.equal(video.licence) | ||
683 | expect(baseVideo.category).to.equal(video.category) | ||
684 | expect(baseVideo.nsfw).to.equal(video.nsfw) | ||
685 | expect(baseVideo.accountName).to.equal(video.accountName) | ||
686 | expect(baseVideo.tags).to.deep.equal(video.tags) | ||
687 | } | ||
688 | }) | ||
689 | |||
690 | it('Should get the preview from each server', async function () { | ||
691 | for (const server of servers) { | ||
692 | const res = await getVideo(server.url, videoUUID) | ||
693 | const video = res.body | ||
694 | |||
695 | const test = await testVideoImage(server.url, 'video_short1-preview.webm', video.previewPath) | ||
696 | expect(test).to.equal(true) | ||
697 | } | ||
698 | }) | ||
699 | }) | ||
700 | |||
701 | describe('Should comment these videos', function () { | ||
702 | it('Should add comment (threads and replies)', async function () { | ||
703 | this.timeout(25000) | ||
704 | |||
705 | { | ||
706 | const text = 'my super first comment' | ||
707 | await addVideoCommentThread(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID, text) | ||
708 | } | ||
709 | |||
710 | { | ||
711 | const text = 'my super second comment' | ||
712 | await addVideoCommentThread(servers[ 2 ].url, servers[ 2 ].accessToken, videoUUID, text) | ||
713 | } | ||
714 | |||
715 | await wait(5000) | ||
716 | |||
717 | { | ||
718 | const res = await getVideoCommentThreads(servers[1].url, videoUUID, 0, 5) | ||
719 | const threadId = res.body.data.find(c => c.text === 'my super first comment').id | ||
720 | |||
721 | const text = 'my super answer to thread 1' | ||
722 | await addVideoCommentReply(servers[ 1 ].url, servers[ 1 ].accessToken, videoUUID, threadId, text) | ||
723 | } | ||
724 | |||
725 | await wait(5000) | ||
726 | |||
727 | { | ||
728 | const res1 = await getVideoCommentThreads(servers[2].url, videoUUID, 0, 5) | ||
729 | const threadId = res1.body.data.find(c => c.text === 'my super first comment').id | ||
730 | |||
731 | const res2 = await getVideoThreadComments(servers[2].url, videoUUID, threadId) | ||
732 | const childCommentId = res2.body.children[0].comment.id | ||
733 | |||
734 | const text3 = 'my second answer to thread 1' | ||
735 | await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, videoUUID, threadId, text3) | ||
736 | |||
737 | const text2 = 'my super answer to answer of thread 1' | ||
738 | await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, videoUUID, childCommentId, text2) | ||
739 | } | ||
740 | |||
741 | await wait(5000) | ||
742 | }) | ||
743 | |||
744 | it('Should have these threads', async function () { | ||
745 | for (const server of servers) { | ||
746 | const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) | ||
747 | |||
748 | expect(res.body.total).to.equal(2) | ||
749 | expect(res.body.data).to.be.an('array') | ||
750 | expect(res.body.data).to.have.lengthOf(2) | ||
751 | |||
752 | { | ||
753 | const comment: VideoComment = res.body.data.find(c => c.text === 'my super first comment') | ||
754 | expect(comment).to.not.be.undefined | ||
755 | expect(comment.inReplyToCommentId).to.be.null | ||
756 | expect(comment.account.name).to.equal('root') | ||
757 | expect(comment.account.host).to.equal('localhost:9001') | ||
758 | expect(comment.totalReplies).to.equal(3) | ||
759 | expect(dateIsValid(comment.createdAt as string)).to.be.true | ||
760 | expect(dateIsValid(comment.updatedAt as string)).to.be.true | ||
761 | } | ||
762 | |||
763 | { | ||
764 | const comment: VideoComment = res.body.data.find(c => c.text === 'my super second comment') | ||
765 | expect(comment).to.not.be.undefined | ||
766 | expect(comment.inReplyToCommentId).to.be.null | ||
767 | expect(comment.account.name).to.equal('root') | ||
768 | expect(comment.account.host).to.equal('localhost:9003') | ||
769 | expect(comment.totalReplies).to.equal(0) | ||
770 | expect(dateIsValid(comment.createdAt as string)).to.be.true | ||
771 | expect(dateIsValid(comment.updatedAt as string)).to.be.true | ||
772 | } | ||
773 | } | ||
774 | }) | ||
775 | |||
776 | it('Should have these comments', async function () { | ||
777 | for (const server of servers) { | ||
778 | const res1 = await getVideoCommentThreads(server.url, videoUUID, 0, 5) | ||
779 | const threadId = res1.body.data.find(c => c.text === 'my super first comment').id | ||
780 | |||
781 | const res2 = await getVideoThreadComments(server.url, videoUUID, threadId) | ||
782 | |||
783 | const tree: VideoCommentThreadTree = res2.body | ||
784 | expect(tree.comment.text).equal('my super first comment') | ||
785 | expect(tree.comment.account.name).equal('root') | ||
786 | expect(tree.comment.account.host).equal('localhost:9001') | ||
787 | expect(tree.children).to.have.lengthOf(2) | ||
788 | |||
789 | const firstChild = tree.children[0] | ||
790 | expect(firstChild.comment.text).to.equal('my super answer to thread 1') | ||
791 | expect(firstChild.comment.account.name).equal('root') | ||
792 | expect(firstChild.comment.account.host).equal('localhost:9002') | ||
793 | expect(firstChild.children).to.have.lengthOf(1) | ||
794 | |||
795 | const childOfFirstChild = firstChild.children[0] | ||
796 | expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1') | ||
797 | expect(childOfFirstChild.comment.account.name).equal('root') | ||
798 | expect(childOfFirstChild.comment.account.host).equal('localhost:9003') | ||
799 | expect(childOfFirstChild.children).to.have.lengthOf(0) | ||
800 | |||
801 | const secondChild = tree.children[1] | ||
802 | expect(secondChild.comment.text).to.equal('my second answer to thread 1') | ||
803 | expect(secondChild.comment.account.name).equal('root') | ||
804 | expect(secondChild.comment.account.host).equal('localhost:9003') | ||
805 | expect(secondChild.children).to.have.lengthOf(0) | ||
806 | } | ||
807 | }) | ||
808 | }) | ||
809 | |||
810 | describe('With minimum parameters', function () { | ||
811 | it('Should upload and propagate the video', async function () { | ||
812 | this.timeout(50000) | ||
813 | |||
814 | const path = '/api/v1/videos/upload' | ||
815 | |||
816 | const req = request(servers[1].url) | ||
817 | .post(path) | ||
818 | .set('Accept', 'application/json') | ||
819 | .set('Authorization', 'Bearer ' + servers[1].accessToken) | ||
820 | .field('name', 'minimum parameters') | ||
821 | .field('privacy', '1') | ||
822 | .field('nsfw', 'false') | ||
823 | .field('channelId', '1') | ||
824 | |||
825 | const filePath = join(__dirname, '..', 'api', 'fixtures', 'video_short.webm') | ||
826 | |||
827 | await req.attach('videofile', filePath) | ||
828 | .expect(200) | ||
829 | |||
830 | await wait(25000) | ||
831 | |||
832 | for (const server of servers) { | ||
833 | const res = await getVideosList(server.url) | ||
834 | const video = res.body.data.find(v => v.name === 'minimum parameters') | ||
835 | |||
836 | expect(video.name).to.equal('minimum parameters') | ||
837 | expect(video.category).to.equal(null) | ||
838 | expect(video.categoryLabel).to.equal('Misc') | ||
839 | expect(video.licence).to.equal(null) | ||
840 | expect(video.licenceLabel).to.equal('Unknown') | ||
841 | expect(video.language).to.equal(null) | ||
842 | expect(video.languageLabel).to.equal('Unknown') | ||
843 | expect(video.nsfw).to.not.be.ok | ||
844 | expect(video.description).to.equal(null) | ||
845 | expect(video.serverHost).to.equal('localhost:9002') | ||
846 | expect(video.accountName).to.equal('root') | ||
847 | expect(dateIsValid(video.createdAt)).to.be.true | ||
848 | expect(dateIsValid(video.updatedAt)).to.be.true | ||
849 | } | ||
850 | }) | ||
851 | }) | ||
852 | |||
853 | after(async function () { | ||
854 | killallServers(servers) | ||
855 | |||
856 | // Keep the logs if the test failed | ||
857 | if (this['ok']) { | ||
858 | await flushTests() | ||
859 | } | ||
860 | }) | ||
861 | }) | ||
diff --git a/server/tests/api/videos/services.ts b/server/tests/api/videos/services.ts new file mode 100644 index 000000000..1cda464d9 --- /dev/null +++ b/server/tests/api/videos/services.ts | |||
@@ -0,0 +1,85 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import * as chai from 'chai' | ||
5 | const expect = chai.expect | ||
6 | |||
7 | import { | ||
8 | ServerInfo, | ||
9 | flushTests, | ||
10 | uploadVideo, | ||
11 | getVideosList, | ||
12 | setAccessTokensToServers, | ||
13 | killallServers, | ||
14 | getOEmbed | ||
15 | } from '../../utils/index' | ||
16 | import { runServer } from '../../utils/server/servers' | ||
17 | |||
18 | describe('Test services', function () { | ||
19 | let server: ServerInfo = null | ||
20 | |||
21 | before(async function () { | ||
22 | this.timeout(10000) | ||
23 | |||
24 | await flushTests() | ||
25 | |||
26 | server = await runServer(1) | ||
27 | |||
28 | await setAccessTokensToServers([ server ]) | ||
29 | |||
30 | const videoAttributes = { | ||
31 | name: 'my super name' | ||
32 | } | ||
33 | await uploadVideo(server.url, server.accessToken, videoAttributes) | ||
34 | |||
35 | const res = await getVideosList(server.url) | ||
36 | server.video = res.body.data[0] | ||
37 | }) | ||
38 | |||
39 | it('Should have a valid oEmbed response', async function () { | ||
40 | const oembedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid | ||
41 | |||
42 | const res = await getOEmbed(server.url, oembedUrl) | ||
43 | const expectedHtml = `<iframe width="560" height="315" src="http://localhost:9001/videos/embed/${server.video.uuid}" ` + | ||
44 | 'frameborder="0" allowfullscreen></iframe>' | ||
45 | const expectedThumbnailUrl = 'http://localhost:9001/static/previews/' + server.video.uuid + '.jpg' | ||
46 | |||
47 | expect(res.body.html).to.equal(expectedHtml) | ||
48 | expect(res.body.title).to.equal(server.video.name) | ||
49 | expect(res.body.author_name).to.equal(server.video.accountName) | ||
50 | expect(res.body.width).to.equal(560) | ||
51 | expect(res.body.height).to.equal(315) | ||
52 | expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl) | ||
53 | expect(res.body.thumbnail_width).to.equal(560) | ||
54 | expect(res.body.thumbnail_height).to.equal(315) | ||
55 | }) | ||
56 | |||
57 | it('Should have a valid oEmbed response with small max height query', async function () { | ||
58 | const oembedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid | ||
59 | const format = 'json' | ||
60 | const maxHeight = 50 | ||
61 | const maxWidth = 50 | ||
62 | |||
63 | const res = await getOEmbed(server.url, oembedUrl, format, maxHeight, maxWidth) | ||
64 | const expectedHtml = `<iframe width="50" height="50" src="http://localhost:9001/videos/embed/${server.video.uuid}" ` + | ||
65 | 'frameborder="0" allowfullscreen></iframe>' | ||
66 | |||
67 | expect(res.body.html).to.equal(expectedHtml) | ||
68 | expect(res.body.title).to.equal(server.video.name) | ||
69 | expect(res.body.author_name).to.equal(server.video.accountName) | ||
70 | expect(res.body.height).to.equal(50) | ||
71 | expect(res.body.width).to.equal(50) | ||
72 | expect(res.body).to.not.have.property('thumbnail_url') | ||
73 | expect(res.body).to.not.have.property('thumbnail_width') | ||
74 | expect(res.body).to.not.have.property('thumbnail_height') | ||
75 | }) | ||
76 | |||
77 | after(async function () { | ||
78 | killallServers([ server ]) | ||
79 | |||
80 | // Keep the logs if the test failed | ||
81 | if (this['ok']) { | ||
82 | await flushTests() | ||
83 | } | ||
84 | }) | ||
85 | }) | ||
diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts new file mode 100644 index 000000000..02723654d --- /dev/null +++ b/server/tests/api/videos/single-server.ts | |||
@@ -0,0 +1,701 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import * as chai from 'chai' | ||
4 | import { keyBy } from 'lodash' | ||
5 | import 'mocha' | ||
6 | import { join } from 'path' | ||
7 | import { | ||
8 | dateIsValid, | ||
9 | flushTests, | ||
10 | getVideo, | ||
11 | getVideoCategories, | ||
12 | getVideoLanguages, | ||
13 | getVideoLicences, | ||
14 | getVideoPrivacies, | ||
15 | getVideosList, | ||
16 | getVideosListPagination, | ||
17 | getVideosListSort, | ||
18 | killallServers, | ||
19 | rateVideo, | ||
20 | readdirPromise, | ||
21 | removeVideo, | ||
22 | runServer, | ||
23 | searchVideo, | ||
24 | searchVideoWithPagination, | ||
25 | searchVideoWithSort, | ||
26 | ServerInfo, | ||
27 | setAccessTokensToServers, | ||
28 | testVideoImage, | ||
29 | updateVideo, | ||
30 | uploadVideo, | ||
31 | wait, | ||
32 | webtorrentAdd | ||
33 | } from '../../utils/index' | ||
34 | import { viewVideo } from '../../utils/videos/videos' | ||
35 | |||
36 | const expect = chai.expect | ||
37 | |||
38 | describe('Test a single server', function () { | ||
39 | let server: ServerInfo = null | ||
40 | let videoId = -1 | ||
41 | let videoUUID = '' | ||
42 | let videosListBase: any[] = null | ||
43 | |||
44 | before(async function () { | ||
45 | this.timeout(10000) | ||
46 | |||
47 | await flushTests() | ||
48 | |||
49 | server = await runServer(1) | ||
50 | |||
51 | await setAccessTokensToServers([ server ]) | ||
52 | }) | ||
53 | |||
54 | it('Should list video categories', async function () { | ||
55 | const res = await getVideoCategories(server.url) | ||
56 | |||
57 | const categories = res.body | ||
58 | expect(Object.keys(categories)).to.have.length.above(10) | ||
59 | |||
60 | expect(categories[11]).to.equal('News') | ||
61 | }) | ||
62 | |||
63 | it('Should list video licences', async function () { | ||
64 | const res = await getVideoLicences(server.url) | ||
65 | |||
66 | const licences = res.body | ||
67 | expect(Object.keys(licences)).to.have.length.above(5) | ||
68 | |||
69 | expect(licences[3]).to.equal('Attribution - No Derivatives') | ||
70 | }) | ||
71 | |||
72 | it('Should list video languages', async function () { | ||
73 | const res = await getVideoLanguages(server.url) | ||
74 | |||
75 | const languages = res.body | ||
76 | expect(Object.keys(languages)).to.have.length.above(5) | ||
77 | |||
78 | expect(languages[3]).to.equal('Mandarin') | ||
79 | }) | ||
80 | |||
81 | it('Should list video privacies', async function () { | ||
82 | const res = await getVideoPrivacies(server.url) | ||
83 | |||
84 | const privacies = res.body | ||
85 | expect(Object.keys(privacies)).to.have.length.at.least(3) | ||
86 | |||
87 | expect(privacies[3]).to.equal('Private') | ||
88 | }) | ||
89 | |||
90 | it('Should not have videos', async function () { | ||
91 | const res = await getVideosList(server.url) | ||
92 | |||
93 | expect(res.body.total).to.equal(0) | ||
94 | expect(res.body.data).to.be.an('array') | ||
95 | expect(res.body.data.length).to.equal(0) | ||
96 | }) | ||
97 | |||
98 | it('Should upload the video', async function () { | ||
99 | const videoAttributes = { | ||
100 | name: 'my super name', | ||
101 | category: 2, | ||
102 | nsfw: true, | ||
103 | licence: 6, | ||
104 | tags: [ 'tag1', 'tag2', 'tag3' ] | ||
105 | } | ||
106 | const res = await uploadVideo(server.url, server.accessToken, videoAttributes) | ||
107 | expect(res.body.video).to.not.be.undefined | ||
108 | expect(res.body.video.id).to.equal(1) | ||
109 | expect(res.body.video.uuid).to.have.length.above(5) | ||
110 | }) | ||
111 | |||
112 | it('Should seed the uploaded video', async function () { | ||
113 | // Yes, this could be long | ||
114 | this.timeout(60000) | ||
115 | |||
116 | const res = await getVideosList(server.url) | ||
117 | |||
118 | expect(res.body.total).to.equal(1) | ||
119 | expect(res.body.data).to.be.an('array') | ||
120 | expect(res.body.data.length).to.equal(1) | ||
121 | |||
122 | const video = res.body.data[0] | ||
123 | expect(video.name).to.equal('my super name') | ||
124 | expect(video.category).to.equal(2) | ||
125 | expect(video.categoryLabel).to.equal('Films') | ||
126 | expect(video.licence).to.equal(6) | ||
127 | expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | ||
128 | expect(video.language).to.equal(3) | ||
129 | expect(video.languageLabel).to.equal('Mandarin') | ||
130 | expect(video.nsfw).to.be.ok | ||
131 | expect(video.description).to.equal('my super description') | ||
132 | expect(video.serverHost).to.equal('localhost:9001') | ||
133 | expect(video.accountName).to.equal('root') | ||
134 | expect(video.isLocal).to.be.true | ||
135 | expect(dateIsValid(video.createdAt)).to.be.true | ||
136 | expect(dateIsValid(video.updatedAt)).to.be.true | ||
137 | |||
138 | const res2 = await getVideo(server.url, res.body.data[0].id) | ||
139 | const videoDetails = res2.body | ||
140 | |||
141 | expect(videoDetails.files).to.have.lengthOf(1) | ||
142 | |||
143 | const file = videoDetails.files[0] | ||
144 | const magnetUri = file.magnetUri | ||
145 | expect(file.magnetUri).to.have.lengthOf.above(2) | ||
146 | expect(file.torrentUrl).to.equal(`${server.url}/static/torrents/${videoDetails.uuid}-${file.resolution}.torrent`) | ||
147 | expect(file.fileUrl).to.equal(`${server.url}/static/webseed/${videoDetails.uuid}-${file.resolution}.webm`) | ||
148 | expect(file.resolution).to.equal(720) | ||
149 | expect(file.resolutionLabel).to.equal('720p') | ||
150 | expect(file.size).to.equal(218910) | ||
151 | |||
152 | const test = await testVideoImage(server.url, 'video_short.webm', videoDetails.thumbnailPath) | ||
153 | expect(test).to.equal(true) | ||
154 | |||
155 | videoId = videoDetails.id | ||
156 | videoUUID = videoDetails.uuid | ||
157 | |||
158 | const torrent = await webtorrentAdd(magnetUri) | ||
159 | expect(torrent.files).to.be.an('array') | ||
160 | expect(torrent.files.length).to.equal(1) | ||
161 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
162 | }) | ||
163 | |||
164 | it('Should get the video', async function () { | ||
165 | // Yes, this could be long | ||
166 | this.timeout(60000) | ||
167 | |||
168 | const res = await getVideo(server.url, videoId) | ||
169 | |||
170 | const video = res.body | ||
171 | expect(video.name).to.equal('my super name') | ||
172 | expect(video.category).to.equal(2) | ||
173 | expect(video.categoryLabel).to.equal('Films') | ||
174 | expect(video.licence).to.equal(6) | ||
175 | expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | ||
176 | expect(video.language).to.equal(3) | ||
177 | expect(video.languageLabel).to.equal('Mandarin') | ||
178 | expect(video.nsfw).to.be.ok | ||
179 | expect(video.description).to.equal('my super description') | ||
180 | expect(video.serverHost).to.equal('localhost:9001') | ||
181 | expect(video.accountName).to.equal('root') | ||
182 | expect(video.isLocal).to.be.true | ||
183 | expect(dateIsValid(video.createdAt)).to.be.true | ||
184 | expect(dateIsValid(video.updatedAt)).to.be.true | ||
185 | expect(video.channel.name).to.equal('Default root channel') | ||
186 | expect(video.channel.isLocal).to.be.true | ||
187 | expect(dateIsValid(video.channel.createdAt)).to.be.true | ||
188 | expect(dateIsValid(video.channel.updatedAt)).to.be.true | ||
189 | |||
190 | expect(video.files).to.have.lengthOf(1) | ||
191 | |||
192 | const file = video.files[0] | ||
193 | expect(file.magnetUri).to.have.lengthOf.above(2) | ||
194 | expect(file.resolution).to.equal(720) | ||
195 | expect(file.resolutionLabel).to.equal('720p') | ||
196 | expect(file.size).to.equal(218910) | ||
197 | |||
198 | const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath) | ||
199 | expect(test).to.equal(true) | ||
200 | |||
201 | // Wait the async views increment | ||
202 | await wait(500) | ||
203 | }) | ||
204 | |||
205 | it('Should get the video by UUID', async function () { | ||
206 | // Yes, this could be long | ||
207 | this.timeout(60000) | ||
208 | |||
209 | const res = await getVideo(server.url, videoUUID) | ||
210 | |||
211 | const video = res.body | ||
212 | expect(video.name).to.equal('my super name') | ||
213 | |||
214 | // Wait the async views increment | ||
215 | await wait(500) | ||
216 | }) | ||
217 | |||
218 | it('Should have the views updated', async function () { | ||
219 | await viewVideo(server.url, videoId) | ||
220 | await viewVideo(server.url, videoId) | ||
221 | await viewVideo(server.url, videoId) | ||
222 | |||
223 | const res = await getVideo(server.url, videoId) | ||
224 | |||
225 | const video = res.body | ||
226 | expect(video.views).to.equal(3) | ||
227 | }) | ||
228 | |||
229 | it('Should search the video by name', async function () { | ||
230 | const res = await searchVideo(server.url, 'my') | ||
231 | |||
232 | expect(res.body.total).to.equal(1) | ||
233 | expect(res.body.data).to.be.an('array') | ||
234 | expect(res.body.data.length).to.equal(1) | ||
235 | |||
236 | const video = res.body.data[0] | ||
237 | expect(video.name).to.equal('my super name') | ||
238 | expect(video.category).to.equal(2) | ||
239 | expect(video.categoryLabel).to.equal('Films') | ||
240 | expect(video.licence).to.equal(6) | ||
241 | expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | ||
242 | expect(video.language).to.equal(3) | ||
243 | expect(video.languageLabel).to.equal('Mandarin') | ||
244 | expect(video.nsfw).to.be.ok | ||
245 | expect(video.description).to.equal('my super description') | ||
246 | expect(video.serverHost).to.equal('localhost:9001') | ||
247 | expect(video.accountName).to.equal('root') | ||
248 | expect(video.isLocal).to.be.true | ||
249 | expect(dateIsValid(video.createdAt)).to.be.true | ||
250 | expect(dateIsValid(video.updatedAt)).to.be.true | ||
251 | |||
252 | const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath) | ||
253 | expect(test).to.equal(true) | ||
254 | }) | ||
255 | |||
256 | // Not implemented yet | ||
257 | // it('Should search the video by serverHost', async function () { | ||
258 | // const res = await videosUtils.searchVideo(server.url, '9001', 'host') | ||
259 | |||
260 | // expect(res.body.total).to.equal(1) | ||
261 | // expect(res.body.data).to.be.an('array') | ||
262 | // expect(res.body.data.length).to.equal(1) | ||
263 | |||
264 | // const video = res.body.data[0] | ||
265 | // expect(video.name).to.equal('my super name') | ||
266 | // expect(video.description).to.equal('my super description') | ||
267 | // expect(video.serverHost).to.equal('localhost:9001') | ||
268 | // expect(video.author).to.equal('root') | ||
269 | // expect(video.isLocal).to.be.true | ||
270 | // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | ||
271 | // expect(dateIsValid(video.createdAt)).to.be.true | ||
272 | // expect(dateIsValid(video.updatedAt)).to.be.true | ||
273 | |||
274 | // const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath) | ||
275 | // expect(test).to.equal(true) | ||
276 | |||
277 | // done() | ||
278 | // }) | ||
279 | // }) | ||
280 | // }) | ||
281 | |||
282 | // Not implemented yet | ||
283 | // it('Should search the video by tag', async function () { | ||
284 | // const res = await searchVideo(server.url, 'tag1') | ||
285 | // | ||
286 | // expect(res.body.total).to.equal(1) | ||
287 | // expect(res.body.data).to.be.an('array') | ||
288 | // expect(res.body.data.length).to.equal(1) | ||
289 | // | ||
290 | // const video = res.body.data[0] | ||
291 | // expect(video.name).to.equal('my super name') | ||
292 | // expect(video.category).to.equal(2) | ||
293 | // expect(video.categoryLabel).to.equal('Films') | ||
294 | // expect(video.licence).to.equal(6) | ||
295 | // expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | ||
296 | // expect(video.language).to.equal(3) | ||
297 | // expect(video.languageLabel).to.equal('Mandarin') | ||
298 | // expect(video.nsfw).to.be.ok | ||
299 | // expect(video.description).to.equal('my super description') | ||
300 | // expect(video.serverHost).to.equal('localhost:9001') | ||
301 | // expect(video.accountName).to.equal('root') | ||
302 | // expect(video.isLocal).to.be.true | ||
303 | // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | ||
304 | // expect(dateIsValid(video.createdAt)).to.be.true | ||
305 | // expect(dateIsValid(video.updatedAt)).to.be.true | ||
306 | // | ||
307 | // const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath) | ||
308 | // expect(test).to.equal(true) | ||
309 | // }) | ||
310 | |||
311 | it('Should not find a search by name', async function () { | ||
312 | const res = await searchVideo(server.url, 'hello') | ||
313 | |||
314 | expect(res.body.total).to.equal(0) | ||
315 | expect(res.body.data).to.be.an('array') | ||
316 | expect(res.body.data.length).to.equal(0) | ||
317 | }) | ||
318 | |||
319 | // Not implemented yet | ||
320 | // it('Should not find a search by author', async function () { | ||
321 | // const res = await searchVideo(server.url, 'hello') | ||
322 | // | ||
323 | // expect(res.body.total).to.equal(0) | ||
324 | // expect(res.body.data).to.be.an('array') | ||
325 | // expect(res.body.data.length).to.equal(0) | ||
326 | // }) | ||
327 | // | ||
328 | // Not implemented yet | ||
329 | // it('Should not find a search by tag', async function () { | ||
330 | // const res = await searchVideo(server.url, 'hello') | ||
331 | // | ||
332 | // expect(res.body.total).to.equal(0) | ||
333 | // expect(res.body.data).to.be.an('array') | ||
334 | // expect(res.body.data.length).to.equal(0) | ||
335 | // }) | ||
336 | |||
337 | it('Should remove the video', async function () { | ||
338 | await removeVideo(server.url, server.accessToken, videoId) | ||
339 | |||
340 | const files1 = await readdirPromise(join(__dirname, '..', '..', '..', 'test1/videos/')) | ||
341 | expect(files1).to.have.lengthOf(0) | ||
342 | |||
343 | const files2 = await readdirPromise(join(__dirname, '..', '..', '..', 'test1/thumbnails/')) | ||
344 | expect(files2).to.have.lengthOf(0) | ||
345 | }) | ||
346 | |||
347 | it('Should not have videos', async function () { | ||
348 | const res = await getVideosList(server.url) | ||
349 | |||
350 | expect(res.body.total).to.equal(0) | ||
351 | expect(res.body.data).to.be.an('array') | ||
352 | expect(res.body.data).to.have.lengthOf(0) | ||
353 | }) | ||
354 | |||
355 | it('Should upload 6 videos', async function () { | ||
356 | this.timeout(25000) | ||
357 | |||
358 | const videos = [ | ||
359 | 'video_short.mp4', 'video_short.ogv', 'video_short.webm', | ||
360 | 'video_short1.webm', 'video_short2.webm', 'video_short3.webm' | ||
361 | ] | ||
362 | |||
363 | const tasks: Promise<any>[] = [] | ||
364 | for (const video of videos) { | ||
365 | const videoAttributes = { | ||
366 | name: video + ' name', | ||
367 | description: video + ' description', | ||
368 | category: 2, | ||
369 | licence: 1, | ||
370 | language: 1, | ||
371 | nsfw: true, | ||
372 | tags: [ 'tag1', 'tag2', 'tag3' ], | ||
373 | fixture: video | ||
374 | } | ||
375 | |||
376 | const p = uploadVideo(server.url, server.accessToken, videoAttributes) | ||
377 | tasks.push(p) | ||
378 | } | ||
379 | |||
380 | await Promise.all(tasks) | ||
381 | }) | ||
382 | |||
383 | it('Should have the correct durations', async function () { | ||
384 | const res = await getVideosList(server.url) | ||
385 | |||
386 | expect(res.body.total).to.equal(6) | ||
387 | const videos = res.body.data | ||
388 | expect(videos).to.be.an('array') | ||
389 | expect(videos).to.have.lengthOf(6) | ||
390 | |||
391 | const videosByName = keyBy<{ duration: number }>(videos, 'name') | ||
392 | expect(videosByName['video_short.mp4 name'].duration).to.equal(5) | ||
393 | expect(videosByName['video_short.ogv name'].duration).to.equal(5) | ||
394 | expect(videosByName['video_short.webm name'].duration).to.equal(5) | ||
395 | expect(videosByName['video_short1.webm name'].duration).to.equal(10) | ||
396 | expect(videosByName['video_short2.webm name'].duration).to.equal(5) | ||
397 | expect(videosByName['video_short3.webm name'].duration).to.equal(5) | ||
398 | }) | ||
399 | |||
400 | it('Should have the correct thumbnails', async function () { | ||
401 | const res = await getVideosList(server.url) | ||
402 | |||
403 | const videos = res.body.data | ||
404 | // For the next test | ||
405 | videosListBase = videos | ||
406 | |||
407 | for (const video of videos) { | ||
408 | const videoName = video.name.replace(' name', '') | ||
409 | const test = await testVideoImage(server.url, videoName, video.thumbnailPath) | ||
410 | |||
411 | expect(test).to.equal(true) | ||
412 | } | ||
413 | }) | ||
414 | |||
415 | it('Should list only the two first videos', async function () { | ||
416 | const res = await getVideosListPagination(server.url, 0, 2, 'name') | ||
417 | |||
418 | const videos = res.body.data | ||
419 | expect(res.body.total).to.equal(6) | ||
420 | expect(videos.length).to.equal(2) | ||
421 | expect(videos[0].name).to.equal(videosListBase[0].name) | ||
422 | expect(videos[1].name).to.equal(videosListBase[1].name) | ||
423 | }) | ||
424 | |||
425 | it('Should list only the next three videos', async function () { | ||
426 | const res = await getVideosListPagination(server.url, 2, 3, 'name') | ||
427 | |||
428 | const videos = res.body.data | ||
429 | expect(res.body.total).to.equal(6) | ||
430 | expect(videos.length).to.equal(3) | ||
431 | expect(videos[0].name).to.equal(videosListBase[2].name) | ||
432 | expect(videos[1].name).to.equal(videosListBase[3].name) | ||
433 | expect(videos[2].name).to.equal(videosListBase[4].name) | ||
434 | }) | ||
435 | |||
436 | it('Should list the last video', async function () { | ||
437 | const res = await getVideosListPagination(server.url, 5, 6, 'name') | ||
438 | |||
439 | const videos = res.body.data | ||
440 | expect(res.body.total).to.equal(6) | ||
441 | expect(videos.length).to.equal(1) | ||
442 | expect(videos[0].name).to.equal(videosListBase[5].name) | ||
443 | }) | ||
444 | |||
445 | it('Should search the first video', async function () { | ||
446 | const res = await searchVideoWithPagination(server.url, 'webm', 0, 1, 'name') | ||
447 | |||
448 | const videos = res.body.data | ||
449 | expect(res.body.total).to.equal(4) | ||
450 | expect(videos.length).to.equal(1) | ||
451 | expect(videos[0].name).to.equal('video_short1.webm name') | ||
452 | }) | ||
453 | |||
454 | it('Should search the last two videos', async function () { | ||
455 | const res = await searchVideoWithPagination(server.url, 'webm', 2, 2, 'name') | ||
456 | |||
457 | const videos = res.body.data | ||
458 | expect(res.body.total).to.equal(4) | ||
459 | expect(videos.length).to.equal(2) | ||
460 | expect(videos[0].name).to.equal('video_short3.webm name') | ||
461 | expect(videos[1].name).to.equal('video_short.webm name') | ||
462 | }) | ||
463 | |||
464 | it('Should search all the webm videos', async function () { | ||
465 | const res = await searchVideoWithPagination(server.url, 'webm', 0, 15) | ||
466 | |||
467 | const videos = res.body.data | ||
468 | expect(res.body.total).to.equal(4) | ||
469 | expect(videos.length).to.equal(4) | ||
470 | }) | ||
471 | |||
472 | // Not implemented yet | ||
473 | // it('Should search all the root author videos', async function () { | ||
474 | // const res = await searchVideoWithPagination(server.url, 'root', 0, 15) | ||
475 | // | ||
476 | // const videos = res.body.data | ||
477 | // expect(res.body.total).to.equal(6) | ||
478 | // expect(videos.length).to.equal(6) | ||
479 | // }) | ||
480 | |||
481 | // Not implemented yet | ||
482 | // it('Should search all the 9001 port videos', async function () { | ||
483 | // const res = await videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15) | ||
484 | |||
485 | // const videos = res.body.data | ||
486 | // expect(res.body.total).to.equal(6) | ||
487 | // expect(videos.length).to.equal(6) | ||
488 | |||
489 | // done() | ||
490 | // }) | ||
491 | // }) | ||
492 | |||
493 | // it('Should search all the localhost videos', async function () { | ||
494 | // const res = await videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15) | ||
495 | |||
496 | // const videos = res.body.data | ||
497 | // expect(res.body.total).to.equal(6) | ||
498 | // expect(videos.length).to.equal(6) | ||
499 | |||
500 | // done() | ||
501 | // }) | ||
502 | // }) | ||
503 | |||
504 | it('Should list and sort by name in descending order', async function () { | ||
505 | const res = await getVideosListSort(server.url, '-name') | ||
506 | |||
507 | const videos = res.body.data | ||
508 | expect(res.body.total).to.equal(6) | ||
509 | expect(videos.length).to.equal(6) | ||
510 | expect(videos[0].name).to.equal('video_short.webm name') | ||
511 | expect(videos[1].name).to.equal('video_short.ogv name') | ||
512 | expect(videos[2].name).to.equal('video_short.mp4 name') | ||
513 | expect(videos[3].name).to.equal('video_short3.webm name') | ||
514 | expect(videos[4].name).to.equal('video_short2.webm name') | ||
515 | expect(videos[5].name).to.equal('video_short1.webm name') | ||
516 | }) | ||
517 | |||
518 | it('Should search and sort by name in ascending order', async function () { | ||
519 | const res = await searchVideoWithSort(server.url, 'webm', 'name') | ||
520 | |||
521 | const videos = res.body.data | ||
522 | expect(res.body.total).to.equal(4) | ||
523 | expect(videos.length).to.equal(4) | ||
524 | |||
525 | expect(videos[0].name).to.equal('video_short1.webm name') | ||
526 | expect(videos[1].name).to.equal('video_short2.webm name') | ||
527 | expect(videos[2].name).to.equal('video_short3.webm name') | ||
528 | expect(videos[3].name).to.equal('video_short.webm name') | ||
529 | |||
530 | videoId = videos[2].id | ||
531 | }) | ||
532 | |||
533 | it('Should update a video', async function () { | ||
534 | const attributes = { | ||
535 | name: 'my super video updated', | ||
536 | category: 4, | ||
537 | licence: 2, | ||
538 | language: 5, | ||
539 | nsfw: false, | ||
540 | description: 'my super description updated', | ||
541 | tags: [ 'tagup1', 'tagup2' ] | ||
542 | } | ||
543 | await updateVideo(server.url, server.accessToken, videoId, attributes) | ||
544 | }) | ||
545 | |||
546 | it('Should have the video updated', async function () { | ||
547 | this.timeout(60000) | ||
548 | |||
549 | const res = await getVideo(server.url, videoId) | ||
550 | |||
551 | const video = res.body | ||
552 | |||
553 | expect(video.name).to.equal('my super video updated') | ||
554 | expect(video.category).to.equal(4) | ||
555 | expect(video.categoryLabel).to.equal('Art') | ||
556 | expect(video.licence).to.equal(2) | ||
557 | expect(video.licenceLabel).to.equal('Attribution - Share Alike') | ||
558 | expect(video.language).to.equal(5) | ||
559 | expect(video.languageLabel).to.equal('Arabic') | ||
560 | expect(video.nsfw).to.be.ok | ||
561 | expect(video.description).to.equal('my super description updated') | ||
562 | expect(video.serverHost).to.equal('localhost:9001') | ||
563 | expect(video.accountName).to.equal('root') | ||
564 | expect(video.account.name).to.equal('root') | ||
565 | expect(video.isLocal).to.be.true | ||
566 | expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ]) | ||
567 | expect(dateIsValid(video.createdAt)).to.be.true | ||
568 | expect(dateIsValid(video.updatedAt)).to.be.true | ||
569 | |||
570 | expect(video.channel.name).to.equal('Default root channel') | ||
571 | expect(video.channel.isLocal).to.be.true | ||
572 | expect(dateIsValid(video.channel.createdAt)).to.be.true | ||
573 | expect(dateIsValid(video.channel.updatedAt)).to.be.true | ||
574 | |||
575 | expect(video.files).to.have.lengthOf(1) | ||
576 | |||
577 | const file = video.files[0] | ||
578 | const magnetUri = file.magnetUri | ||
579 | expect(file.magnetUri).to.have.lengthOf.above(2) | ||
580 | expect(file.resolution).to.equal(720) | ||
581 | expect(file.resolutionLabel).to.equal('720p') | ||
582 | expect(file.size).to.equal(292677) | ||
583 | |||
584 | const test = await testVideoImage(server.url, 'video_short3.webm', video.thumbnailPath) | ||
585 | expect(test).to.equal(true) | ||
586 | |||
587 | const torrent = await webtorrentAdd(magnetUri) | ||
588 | expect(torrent.files).to.be.an('array') | ||
589 | expect(torrent.files.length).to.equal(1) | ||
590 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
591 | }) | ||
592 | |||
593 | it('Should update only the tags of a video', async function () { | ||
594 | const attributes = { | ||
595 | tags: [ 'tag1', 'tag2', 'supertag' ] | ||
596 | } | ||
597 | |||
598 | await updateVideo(server.url, server.accessToken, videoId, attributes) | ||
599 | |||
600 | const res = await getVideo(server.url, videoId) | ||
601 | const video = res.body | ||
602 | |||
603 | expect(video.name).to.equal('my super video updated') | ||
604 | expect(video.category).to.equal(4) | ||
605 | expect(video.categoryLabel).to.equal('Art') | ||
606 | expect(video.licence).to.equal(2) | ||
607 | expect(video.licenceLabel).to.equal('Attribution - Share Alike') | ||
608 | expect(video.language).to.equal(5) | ||
609 | expect(video.languageLabel).to.equal('Arabic') | ||
610 | expect(video.nsfw).to.be.ok | ||
611 | expect(video.description).to.equal('my super description updated') | ||
612 | expect(video.serverHost).to.equal('localhost:9001') | ||
613 | expect(video.accountName).to.equal('root') | ||
614 | expect(video.isLocal).to.be.true | ||
615 | expect(video.tags).to.deep.equal([ 'supertag', 'tag1', 'tag2' ]) | ||
616 | expect(dateIsValid(video.createdAt)).to.be.true | ||
617 | expect(dateIsValid(video.updatedAt)).to.be.true | ||
618 | |||
619 | expect(video.channel.name).to.equal('Default root channel') | ||
620 | expect(video.channel.isLocal).to.be.true | ||
621 | expect(dateIsValid(video.channel.createdAt)).to.be.true | ||
622 | expect(dateIsValid(video.channel.updatedAt)).to.be.true | ||
623 | |||
624 | expect(video.files).to.have.lengthOf(1) | ||
625 | |||
626 | const file = video.files[0] | ||
627 | expect(file.magnetUri).to.have.lengthOf.above(2) | ||
628 | expect(file.resolution).to.equal(720) | ||
629 | expect(file.resolutionLabel).to.equal('720p') | ||
630 | expect(file.size).to.equal(292677) | ||
631 | }) | ||
632 | |||
633 | it('Should update only the description of a video', async function () { | ||
634 | const attributes = { | ||
635 | description: 'hello everybody' | ||
636 | } | ||
637 | |||
638 | await updateVideo(server.url, server.accessToken, videoId, attributes) | ||
639 | |||
640 | const res = await getVideo(server.url, videoId) | ||
641 | const video = res.body | ||
642 | |||
643 | expect(video.name).to.equal('my super video updated') | ||
644 | expect(video.category).to.equal(4) | ||
645 | expect(video.categoryLabel).to.equal('Art') | ||
646 | expect(video.licence).to.equal(2) | ||
647 | expect(video.licenceLabel).to.equal('Attribution - Share Alike') | ||
648 | expect(video.language).to.equal(5) | ||
649 | expect(video.languageLabel).to.equal('Arabic') | ||
650 | expect(video.nsfw).to.be.ok | ||
651 | expect(video.description).to.equal('hello everybody') | ||
652 | expect(video.serverHost).to.equal('localhost:9001') | ||
653 | expect(video.accountName).to.equal('root') | ||
654 | expect(video.isLocal).to.be.true | ||
655 | expect(video.tags).to.deep.equal([ 'supertag', 'tag1', 'tag2' ]) | ||
656 | expect(dateIsValid(video.createdAt)).to.be.true | ||
657 | expect(dateIsValid(video.updatedAt)).to.be.true | ||
658 | |||
659 | expect(video.channel.name).to.equal('Default root channel') | ||
660 | expect(video.channel.isLocal).to.be.true | ||
661 | expect(dateIsValid(video.channel.createdAt)).to.be.true | ||
662 | expect(dateIsValid(video.channel.updatedAt)).to.be.true | ||
663 | |||
664 | expect(video.files).to.have.lengthOf(1) | ||
665 | |||
666 | const file = video.files[0] | ||
667 | expect(file.magnetUri).to.have.lengthOf.above(2) | ||
668 | expect(file.resolution).to.equal(720) | ||
669 | expect(file.resolutionLabel).to.equal('720p') | ||
670 | expect(file.size).to.equal(292677) | ||
671 | }) | ||
672 | |||
673 | it('Should like a video', async function () { | ||
674 | await rateVideo(server.url, server.accessToken, videoId, 'like') | ||
675 | |||
676 | const res = await getVideo(server.url, videoId) | ||
677 | const video = res.body | ||
678 | |||
679 | expect(video.likes).to.equal(1) | ||
680 | expect(video.dislikes).to.equal(0) | ||
681 | }) | ||
682 | |||
683 | it('Should dislike the same video', async function () { | ||
684 | await rateVideo(server.url, server.accessToken, videoId, 'dislike') | ||
685 | |||
686 | const res = await getVideo(server.url, videoId) | ||
687 | const video = res.body | ||
688 | |||
689 | expect(video.likes).to.equal(0) | ||
690 | expect(video.dislikes).to.equal(1) | ||
691 | }) | ||
692 | |||
693 | after(async function () { | ||
694 | killallServers([ server ]) | ||
695 | |||
696 | // Keep the logs if the test failed | ||
697 | if (this['ok']) { | ||
698 | await flushTests() | ||
699 | } | ||
700 | }) | ||
701 | }) | ||
diff --git a/server/tests/api/videos/video-abuse.ts b/server/tests/api/videos/video-abuse.ts new file mode 100644 index 000000000..3fcf5d8c7 --- /dev/null +++ b/server/tests/api/videos/video-abuse.ts | |||
@@ -0,0 +1,145 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | ||
5 | import { | ||
6 | flushAndRunMultipleServers, | ||
7 | flushTests, | ||
8 | getVideoAbusesList, | ||
9 | getVideosList, | ||
10 | killallServers, | ||
11 | reportVideoAbuse, | ||
12 | ServerInfo, | ||
13 | setAccessTokensToServers, | ||
14 | uploadVideo, | ||
15 | wait | ||
16 | } from '../../utils/index' | ||
17 | import { doubleFollow } from '../../utils/server/follows' | ||
18 | |||
19 | const expect = chai.expect | ||
20 | |||
21 | describe('Test video abuses', function () { | ||
22 | let servers: ServerInfo[] = [] | ||
23 | |||
24 | before(async function () { | ||
25 | this.timeout(50000) | ||
26 | |||
27 | // Run servers | ||
28 | servers = await flushAndRunMultipleServers(2) | ||
29 | |||
30 | // Get the access tokens | ||
31 | await setAccessTokensToServers(servers) | ||
32 | |||
33 | // Server 1 and server 2 follow each other | ||
34 | await doubleFollow(servers[0], servers[1]) | ||
35 | |||
36 | // Upload some videos on each servers | ||
37 | const video1Attributes = { | ||
38 | name: 'my super name for server 1', | ||
39 | description: 'my super description for server 1' | ||
40 | } | ||
41 | await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes) | ||
42 | |||
43 | const video2Attributes = { | ||
44 | name: 'my super name for server 2', | ||
45 | description: 'my super description for server 2' | ||
46 | } | ||
47 | await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes) | ||
48 | |||
49 | // Wait videos propagation, server 2 has transcoding enabled | ||
50 | await wait(15000) | ||
51 | |||
52 | const res = await getVideosList(servers[0].url) | ||
53 | const videos = res.body.data | ||
54 | |||
55 | expect(videos.length).to.equal(2) | ||
56 | |||
57 | servers[0].video = videos.find(video => video.name === 'my super name for server 1') | ||
58 | servers[1].video = videos.find(video => video.name === 'my super name for server 2') | ||
59 | }) | ||
60 | |||
61 | it('Should not have video abuses', async function () { | ||
62 | const res = await getVideoAbusesList(servers[0].url, servers[0].accessToken) | ||
63 | |||
64 | expect(res.body.total).to.equal(0) | ||
65 | expect(res.body.data).to.be.an('array') | ||
66 | expect(res.body.data.length).to.equal(0) | ||
67 | }) | ||
68 | |||
69 | it('Should report abuse on a local video', async function () { | ||
70 | this.timeout(10000) | ||
71 | |||
72 | const reason = 'my super bad reason' | ||
73 | await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[0].video.id, reason) | ||
74 | |||
75 | // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2 | ||
76 | await wait(5000) | ||
77 | }) | ||
78 | |||
79 | it('Should have 1 video abuses on server 1 and 0 on server 2', async function () { | ||
80 | const res1 = await getVideoAbusesList(servers[0].url, servers[0].accessToken) | ||
81 | |||
82 | expect(res1.body.total).to.equal(1) | ||
83 | expect(res1.body.data).to.be.an('array') | ||
84 | expect(res1.body.data.length).to.equal(1) | ||
85 | |||
86 | const abuse = res1.body.data[0] | ||
87 | expect(abuse.reason).to.equal('my super bad reason') | ||
88 | expect(abuse.reporterUsername).to.equal('root') | ||
89 | expect(abuse.reporterServerHost).to.equal('localhost:9001') | ||
90 | expect(abuse.videoId).to.equal(servers[0].video.id) | ||
91 | |||
92 | const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken) | ||
93 | expect(res2.body.total).to.equal(0) | ||
94 | expect(res2.body.data).to.be.an('array') | ||
95 | expect(res2.body.data.length).to.equal(0) | ||
96 | }) | ||
97 | |||
98 | it('Should report abuse on a remote video', async function () { | ||
99 | this.timeout(10000) | ||
100 | |||
101 | const reason = 'my super bad reason 2' | ||
102 | await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[1].video.id, reason) | ||
103 | |||
104 | // We wait requests propagation | ||
105 | await wait(5000) | ||
106 | }) | ||
107 | |||
108 | it('Should have 2 video abuse on server 1 and 1 on server 2', async function () { | ||
109 | const res1 = await getVideoAbusesList(servers[0].url, servers[0].accessToken) | ||
110 | expect(res1.body.total).to.equal(2) | ||
111 | expect(res1.body.data).to.be.an('array') | ||
112 | expect(res1.body.data.length).to.equal(2) | ||
113 | |||
114 | const abuse1 = res1.body.data[0] | ||
115 | expect(abuse1.reason).to.equal('my super bad reason') | ||
116 | expect(abuse1.reporterUsername).to.equal('root') | ||
117 | expect(abuse1.reporterServerHost).to.equal('localhost:9001') | ||
118 | expect(abuse1.videoId).to.equal(servers[0].video.id) | ||
119 | |||
120 | const abuse2 = res1.body.data[1] | ||
121 | expect(abuse2.reason).to.equal('my super bad reason 2') | ||
122 | expect(abuse2.reporterUsername).to.equal('root') | ||
123 | expect(abuse2.reporterServerHost).to.equal('localhost:9001') | ||
124 | expect(abuse2.videoId).to.equal(servers[1].video.id) | ||
125 | |||
126 | const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken) | ||
127 | expect(res2.body.total).to.equal(1) | ||
128 | expect(res2.body.data).to.be.an('array') | ||
129 | expect(res2.body.data.length).to.equal(1) | ||
130 | |||
131 | const abuse3 = res2.body.data[0] | ||
132 | expect(abuse3.reason).to.equal('my super bad reason 2') | ||
133 | expect(abuse3.reporterUsername).to.equal('root') | ||
134 | expect(abuse3.reporterServerHost).to.equal('localhost:9001') | ||
135 | }) | ||
136 | |||
137 | after(async function () { | ||
138 | killallServers(servers) | ||
139 | |||
140 | // Keep the logs if the test failed | ||
141 | if (this['ok']) { | ||
142 | await flushTests() | ||
143 | } | ||
144 | }) | ||
145 | }) | ||
diff --git a/server/tests/api/videos/video-blacklist-management.ts b/server/tests/api/videos/video-blacklist-management.ts new file mode 100644 index 000000000..db79784c2 --- /dev/null +++ b/server/tests/api/videos/video-blacklist-management.ts | |||
@@ -0,0 +1,162 @@ | |||
1 | /* tslint:disable:no-unused-expressions */ | ||
2 | |||
3 | import * as chai from 'chai' | ||
4 | import * as lodash from 'lodash' | ||
5 | import 'mocha' | ||
6 | import { | ||
7 | addVideoToBlacklist, | ||
8 | flushAndRunMultipleServers, | ||
9 | flushTests, | ||
10 | getBlacklistedVideosList, | ||
11 | getSortedBlacklistedVideosList, | ||
12 | getVideosList, | ||
13 | killallServers, | ||
14 | removeVideoFromBlacklist, | ||
15 | ServerInfo, | ||
16 | setAccessTokensToServers, | ||
17 | uploadVideo, | ||
18 | wait | ||
19 | } from '../../utils/index' | ||
20 | import { doubleFollow } from '../../utils/server/follows' | ||
21 | |||
22 | const expect = chai.expect | ||
23 | const orderBy = lodash.orderBy | ||
24 | |||
25 | describe('Test video blacklist management', function () { | ||
26 | let servers: ServerInfo[] = [] | ||
27 | |||
28 | async function blacklistVideosOnServer (server: ServerInfo) { | ||
29 | const res = await getVideosList(server.url) | ||
30 | |||
31 | const videos = res.body.data | ||
32 | for (let video of videos) { | ||
33 | await addVideoToBlacklist(server.url, server.accessToken, video.id) | ||
34 | } | ||
35 | } | ||
36 | |||
37 | before(async function () { | ||
38 | this.timeout(50000) | ||
39 | |||
40 | // Run servers | ||
41 | servers = await flushAndRunMultipleServers(2) | ||
42 | |||
43 | // Get the access tokens | ||
44 | await setAccessTokensToServers(servers) | ||
45 | |||
46 | // Server 1 and server 2 follow each other | ||
47 | await doubleFollow(servers[0], servers[1]) | ||
48 | |||
49 | // Upload 2 videos on server 2 | ||
50 | await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 1st video', description: 'A video on server 2' }) | ||
51 | await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on server 2' }) | ||
52 | |||
53 | // Wait videos propagation, server 2 has transcoding enabled | ||
54 | await wait(15000) | ||
55 | |||
56 | // Blacklist the two videos on server 1 | ||
57 | await blacklistVideosOnServer(servers[0]) | ||
58 | }) | ||
59 | |||
60 | describe('When listing blacklisted videos', function () { | ||
61 | it('Should display all the blacklisted videos', async function () { | ||
62 | const res = await getBlacklistedVideosList(servers[0].url, servers[0].accessToken) | ||
63 | |||
64 | expect(res.body.total).to.equal(2) | ||
65 | |||
66 | const videos = res.body.data | ||
67 | expect(videos).to.be.an('array') | ||
68 | expect(videos.length).to.equal(2) | ||
69 | }) | ||
70 | |||
71 | it('Should get the correct sort when sorting by descending id', async function () { | ||
72 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-id') | ||
73 | expect(res.body.total).to.equal(2) | ||
74 | |||
75 | const videos = res.body.data | ||
76 | expect(videos).to.be.an('array') | ||
77 | expect(videos.length).to.equal(2) | ||
78 | |||
79 | const result = orderBy(res.body.data, [ 'id' ], [ 'desc' ]) | ||
80 | |||
81 | expect(videos).to.deep.equal(result) | ||
82 | }) | ||
83 | |||
84 | it('Should get the correct sort when sorting by descending video name', async function () { | ||
85 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') | ||
86 | expect(res.body.total).to.equal(2) | ||
87 | |||
88 | const videos = res.body.data | ||
89 | expect(videos).to.be.an('array') | ||
90 | expect(videos.length).to.equal(2) | ||
91 | |||
92 | const result = orderBy(res.body.data, [ 'name' ], [ 'desc' ]) | ||
93 | |||
94 | expect(videos).to.deep.equal(result) | ||
95 | }) | ||
96 | |||
97 | it('Should get the correct sort when sorting by ascending creation date', async function () { | ||
98 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt') | ||
99 | expect(res.body.total).to.equal(2) | ||
100 | |||
101 | const videos = res.body.data | ||
102 | expect(videos).to.be.an('array') | ||
103 | expect(videos.length).to.equal(2) | ||
104 | |||
105 | const result = orderBy(res.body.data, [ 'createdAt' ]) | ||
106 | |||
107 | expect(videos).to.deep.equal(result) | ||
108 | }) | ||
109 | }) | ||
110 | |||
111 | describe('When removing a blacklisted video', function () { | ||
112 | let videoToRemove | ||
113 | let blacklist = [] | ||
114 | |||
115 | it('Should not have any video in videos list on server 1', async function () { | ||
116 | const res = await getVideosList(servers[0].url) | ||
117 | expect(res.body.total).to.equal(0) | ||
118 | expect(res.body.data).to.be.an('array') | ||
119 | expect(res.body.data.length).to.equal(0) | ||
120 | }) | ||
121 | |||
122 | it('Should remove a video from the blacklist on server 1', async function () { | ||
123 | // Get one video in the blacklist | ||
124 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') | ||
125 | videoToRemove = res.body.data[0] | ||
126 | blacklist = res.body.data.slice(1) | ||
127 | |||
128 | // Remove it | ||
129 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoToRemove.videoId) | ||
130 | }) | ||
131 | |||
132 | it('Should have the ex-blacklisted video in videos list on server 1', async function () { | ||
133 | const res = await getVideosList(servers[0].url) | ||
134 | expect(res.body.total).to.equal(1) | ||
135 | |||
136 | const videos = res.body.data | ||
137 | expect(videos).to.be.an('array') | ||
138 | expect(videos.length).to.equal(1) | ||
139 | |||
140 | expect(videos[0].name).to.equal(videoToRemove.name) | ||
141 | expect(videos[0].id).to.equal(videoToRemove.videoId) | ||
142 | }) | ||
143 | |||
144 | it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () { | ||
145 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') | ||
146 | expect(res.body.total).to.equal(1) | ||
147 | |||
148 | const videos = res.body.data | ||
149 | expect(videos).to.be.an('array') | ||
150 | expect(videos.length).to.equal(1) | ||
151 | expect(videos).to.deep.equal(blacklist) | ||
152 | }) | ||
153 | }) | ||
154 | |||
155 | after(async function () { | ||
156 | killallServers(servers) | ||
157 | |||
158 | if (this['ok']) { | ||
159 | await flushTests() | ||
160 | } | ||
161 | }) | ||
162 | }) | ||
diff --git a/server/tests/api/videos/video-blacklist.ts b/server/tests/api/videos/video-blacklist.ts new file mode 100644 index 000000000..d1cefa5d7 --- /dev/null +++ b/server/tests/api/videos/video-blacklist.ts | |||
@@ -0,0 +1,98 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | ||
5 | import { | ||
6 | addVideoToBlacklist, | ||
7 | flushAndRunMultipleServers, | ||
8 | flushTests, | ||
9 | getVideosList, | ||
10 | killallServers, | ||
11 | searchVideo, | ||
12 | ServerInfo, | ||
13 | setAccessTokensToServers, | ||
14 | uploadVideo, | ||
15 | wait | ||
16 | } from '../../utils/index' | ||
17 | import { doubleFollow } from '../../utils/server/follows' | ||
18 | |||
19 | const expect = chai.expect | ||
20 | |||
21 | describe('Test video blacklists', function () { | ||
22 | let servers: ServerInfo[] = [] | ||
23 | |||
24 | before(async function () { | ||
25 | this.timeout(50000) | ||
26 | |||
27 | // Run servers | ||
28 | servers = await flushAndRunMultipleServers(2) | ||
29 | |||
30 | // Get the access tokens | ||
31 | await setAccessTokensToServers(servers) | ||
32 | |||
33 | // Server 1 and server 2 follow each other | ||
34 | await doubleFollow(servers[0], servers[1]) | ||
35 | |||
36 | // Upload a video on server 2 | ||
37 | const videoAttributes = { | ||
38 | name: 'my super name for server 2', | ||
39 | description: 'my super description for server 2' | ||
40 | } | ||
41 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | ||
42 | |||
43 | // Wait videos propagation, server 2 has transcoding enabled | ||
44 | await wait(10000) | ||
45 | |||
46 | const res = await getVideosList(servers[0].url) | ||
47 | const videos = res.body.data | ||
48 | |||
49 | expect(videos.length).to.equal(1) | ||
50 | |||
51 | servers[0].remoteVideo = videos.find(video => video.name === 'my super name for server 2') | ||
52 | }) | ||
53 | |||
54 | it('Should blacklist a remote video on server 1', async function () { | ||
55 | await addVideoToBlacklist(servers[0].url, servers[0].accessToken, servers[0].remoteVideo.id) | ||
56 | }) | ||
57 | |||
58 | it('Should not have the video blacklisted in videos list on server 1', async function () { | ||
59 | const res = await getVideosList(servers[0].url) | ||
60 | |||
61 | expect(res.body.total).to.equal(0) | ||
62 | expect(res.body.data).to.be.an('array') | ||
63 | expect(res.body.data.length).to.equal(0) | ||
64 | }) | ||
65 | |||
66 | it('Should not have the video blacklisted in videos search on server 1', async function () { | ||
67 | const res = await searchVideo(servers[0].url, 'name') | ||
68 | |||
69 | expect(res.body.total).to.equal(0) | ||
70 | expect(res.body.data).to.be.an('array') | ||
71 | expect(res.body.data.length).to.equal(0) | ||
72 | }) | ||
73 | |||
74 | it('Should have the blacklisted video in videos list on server 2', async function () { | ||
75 | const res = await getVideosList(servers[1].url) | ||
76 | |||
77 | expect(res.body.total).to.equal(1) | ||
78 | expect(res.body.data).to.be.an('array') | ||
79 | expect(res.body.data.length).to.equal(1) | ||
80 | }) | ||
81 | |||
82 | it('Should have the video blacklisted in videos search on server 2', async function () { | ||
83 | const res = await searchVideo(servers[1].url, 'name') | ||
84 | |||
85 | expect(res.body.total).to.equal(1) | ||
86 | expect(res.body.data).to.be.an('array') | ||
87 | expect(res.body.data.length).to.equal(1) | ||
88 | }) | ||
89 | |||
90 | after(async function () { | ||
91 | killallServers(servers) | ||
92 | |||
93 | // Keep the logs if the test failed | ||
94 | if (this['ok']) { | ||
95 | await flushTests() | ||
96 | } | ||
97 | }) | ||
98 | }) | ||
diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts new file mode 100644 index 000000000..454a96da6 --- /dev/null +++ b/server/tests/api/videos/video-channels.ts | |||
@@ -0,0 +1,139 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import * as chai from 'chai' | ||
5 | const expect = chai.expect | ||
6 | |||
7 | import { | ||
8 | ServerInfo, | ||
9 | flushTests, | ||
10 | runServer, | ||
11 | setAccessTokensToServers, | ||
12 | killallServers, | ||
13 | getMyUserInformation, | ||
14 | getVideoChannelsList, | ||
15 | addVideoChannel, | ||
16 | getAccountVideoChannelsList, | ||
17 | updateVideoChannel, | ||
18 | deleteVideoChannel, | ||
19 | getVideoChannel | ||
20 | } from '../../utils/index' | ||
21 | import { User } from '../../../../shared/index' | ||
22 | |||
23 | describe('Test a video channels', function () { | ||
24 | let server: ServerInfo | ||
25 | let userInfo: User | ||
26 | let videoChannelId: number | ||
27 | |||
28 | before(async function () { | ||
29 | this.timeout(10000) | ||
30 | |||
31 | await flushTests() | ||
32 | |||
33 | server = await runServer(1) | ||
34 | |||
35 | await setAccessTokensToServers([ server ]) | ||
36 | }) | ||
37 | |||
38 | it('Should have one video channel (created with root)', async () => { | ||
39 | const res = await getVideoChannelsList(server.url, 0, 2) | ||
40 | |||
41 | expect(res.body.total).to.equal(1) | ||
42 | expect(res.body.data).to.be.an('array') | ||
43 | expect(res.body.data).to.have.lengthOf(1) | ||
44 | }) | ||
45 | |||
46 | it('Should create another video channel', async () => { | ||
47 | const videoChannel = { | ||
48 | name: 'second video channel', | ||
49 | description: 'super video channel description' | ||
50 | } | ||
51 | await addVideoChannel(server.url, server.accessToken, videoChannel) | ||
52 | }) | ||
53 | |||
54 | it('Should have two video channels when getting my information', async () => { | ||
55 | const res = await getMyUserInformation(server.url, server.accessToken) | ||
56 | userInfo = res.body | ||
57 | |||
58 | expect(userInfo.videoChannels).to.be.an('array') | ||
59 | expect(userInfo.videoChannels).to.have.lengthOf(2) | ||
60 | |||
61 | const videoChannels = userInfo.videoChannels | ||
62 | expect(videoChannels[0].name).to.equal('Default root channel') | ||
63 | expect(videoChannels[1].name).to.equal('second video channel') | ||
64 | expect(videoChannels[1].description).to.equal('super video channel description') | ||
65 | }) | ||
66 | |||
67 | it('Should have two video channels when getting account channels', async () => { | ||
68 | const res = await getAccountVideoChannelsList(server.url, userInfo.account.uuid) | ||
69 | |||
70 | expect(res.body.total).to.equal(2) | ||
71 | expect(res.body.data).to.be.an('array') | ||
72 | expect(res.body.data).to.have.lengthOf(2) | ||
73 | |||
74 | const videoChannels = res.body.data | ||
75 | expect(videoChannels[0].name).to.equal('Default root channel') | ||
76 | expect(videoChannels[1].name).to.equal('second video channel') | ||
77 | expect(videoChannels[1].description).to.equal('super video channel description') | ||
78 | |||
79 | videoChannelId = videoChannels[1].id | ||
80 | }) | ||
81 | |||
82 | it('Should list video channels', async () => { | ||
83 | const res = await getVideoChannelsList(server.url, 1, 1, '-name') | ||
84 | |||
85 | expect(res.body.total).to.equal(2) | ||
86 | expect(res.body.data).to.be.an('array') | ||
87 | expect(res.body.data).to.have.lengthOf(1) | ||
88 | expect(res.body.data[0].name).to.equal('Default root channel') | ||
89 | }) | ||
90 | |||
91 | it('Should update video channel', async () => { | ||
92 | const videoChannelAttributes = { | ||
93 | name: 'video channel updated', | ||
94 | description: 'video channel description updated' | ||
95 | } | ||
96 | |||
97 | await updateVideoChannel(server.url, server.accessToken, videoChannelId, videoChannelAttributes) | ||
98 | }) | ||
99 | |||
100 | it('Should have video channel updated', async () => { | ||
101 | const res = await getVideoChannelsList(server.url, 0, 1, '-name') | ||
102 | |||
103 | expect(res.body.total).to.equal(2) | ||
104 | expect(res.body.data).to.be.an('array') | ||
105 | expect(res.body.data).to.have.lengthOf(1) | ||
106 | expect(res.body.data[0].name).to.equal('video channel updated') | ||
107 | expect(res.body.data[0].description).to.equal('video channel description updated') | ||
108 | }) | ||
109 | |||
110 | it('Should get video channel', async () => { | ||
111 | const res = await getVideoChannel(server.url, videoChannelId) | ||
112 | |||
113 | const videoChannel = res.body | ||
114 | expect(videoChannel.name).to.equal('video channel updated') | ||
115 | expect(videoChannel.description).to.equal('video channel description updated') | ||
116 | }) | ||
117 | |||
118 | it('Should delete video channel', async () => { | ||
119 | await deleteVideoChannel(server.url, server.accessToken, videoChannelId) | ||
120 | }) | ||
121 | |||
122 | it('Should have video channel deleted', async () => { | ||
123 | const res = await getVideoChannelsList(server.url, 0, 10) | ||
124 | |||
125 | expect(res.body.total).to.equal(1) | ||
126 | expect(res.body.data).to.be.an('array') | ||
127 | expect(res.body.data).to.have.lengthOf(1) | ||
128 | expect(res.body.data[0].name).to.equal('Default root channel') | ||
129 | }) | ||
130 | |||
131 | after(async function () { | ||
132 | killallServers([ server ]) | ||
133 | |||
134 | // Keep the logs if the test failed | ||
135 | if (this['ok']) { | ||
136 | await flushTests() | ||
137 | } | ||
138 | }) | ||
139 | }) | ||
diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts new file mode 100644 index 000000000..3b6578f04 --- /dev/null +++ b/server/tests/api/videos/video-comments.ts | |||
@@ -0,0 +1,154 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | ||
5 | import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' | ||
6 | import { dateIsValid, flushTests, killallServers, runServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../utils/index' | ||
7 | import { | ||
8 | addVideoCommentReply, addVideoCommentThread, getVideoCommentThreads, | ||
9 | getVideoThreadComments | ||
10 | } from '../../utils/videos/video-comments' | ||
11 | |||
12 | const expect = chai.expect | ||
13 | |||
14 | describe('Test video comments', function () { | ||
15 | let server: ServerInfo | ||
16 | let videoId | ||
17 | let videoUUID | ||
18 | let threadId | ||
19 | |||
20 | before(async function () { | ||
21 | this.timeout(10000) | ||
22 | |||
23 | await flushTests() | ||
24 | |||
25 | server = await runServer(1) | ||
26 | |||
27 | await setAccessTokensToServers([ server ]) | ||
28 | |||
29 | const res = await uploadVideo(server.url, server.accessToken, {}) | ||
30 | videoUUID = res.body.video.uuid | ||
31 | videoId = res.body.video.id | ||
32 | }) | ||
33 | |||
34 | it('Should not have threads on this video', async function () { | ||
35 | const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) | ||
36 | |||
37 | expect(res.body.total).to.equal(0) | ||
38 | expect(res.body.data).to.be.an('array') | ||
39 | expect(res.body.data).to.have.lengthOf(0) | ||
40 | }) | ||
41 | |||
42 | it('Should create a thread in this video', async function () { | ||
43 | const text = 'my super first comment' | ||
44 | |||
45 | const res = await addVideoCommentThread(server.url, server.accessToken, videoUUID, text) | ||
46 | const comment = res.body.comment | ||
47 | |||
48 | expect(comment.inReplyToCommentId).to.be.null | ||
49 | expect(comment.text).equal('my super first comment') | ||
50 | expect(comment.videoId).to.equal(videoId) | ||
51 | expect(comment.id).to.equal(comment.threadId) | ||
52 | expect(comment.account.name).to.equal('root') | ||
53 | expect(comment.account.host).to.equal('localhost:9001') | ||
54 | expect(comment.totalReplies).to.equal(0) | ||
55 | expect(dateIsValid(comment.createdAt as string)).to.be.true | ||
56 | expect(dateIsValid(comment.updatedAt as string)).to.be.true | ||
57 | }) | ||
58 | |||
59 | it('Should list threads of this video', async function () { | ||
60 | const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) | ||
61 | |||
62 | expect(res.body.total).to.equal(1) | ||
63 | expect(res.body.data).to.be.an('array') | ||
64 | expect(res.body.data).to.have.lengthOf(1) | ||
65 | |||
66 | const comment: VideoComment = res.body.data[0] | ||
67 | expect(comment.inReplyToCommentId).to.be.null | ||
68 | expect(comment.text).equal('my super first comment') | ||
69 | expect(comment.videoId).to.equal(videoId) | ||
70 | expect(comment.id).to.equal(comment.threadId) | ||
71 | expect(comment.account.name).to.equal('root') | ||
72 | expect(comment.account.host).to.equal('localhost:9001') | ||
73 | expect(comment.totalReplies).to.equal(0) | ||
74 | expect(dateIsValid(comment.createdAt as string)).to.be.true | ||
75 | expect(dateIsValid(comment.updatedAt as string)).to.be.true | ||
76 | |||
77 | threadId = comment.threadId | ||
78 | }) | ||
79 | |||
80 | it('Should get all the thread created', async function () { | ||
81 | const res = await getVideoThreadComments(server.url, videoUUID, threadId) | ||
82 | |||
83 | const rootComment = res.body.comment | ||
84 | expect(rootComment.inReplyToCommentId).to.be.null | ||
85 | expect(rootComment.text).equal('my super first comment') | ||
86 | expect(rootComment.videoId).to.equal(videoId) | ||
87 | expect(dateIsValid(rootComment.createdAt as string)).to.be.true | ||
88 | expect(dateIsValid(rootComment.updatedAt as string)).to.be.true | ||
89 | }) | ||
90 | |||
91 | it('Should create multiple replies in this thread', async function () { | ||
92 | const text1 = 'my super answer to thread 1' | ||
93 | const childCommentRes = await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text1) | ||
94 | const childCommentId = childCommentRes.body.comment.id | ||
95 | |||
96 | const text2 = 'my super answer to answer of thread 1' | ||
97 | await addVideoCommentReply(server.url, server.accessToken, videoId, childCommentId, text2) | ||
98 | |||
99 | const text3 = 'my second answer to thread 1' | ||
100 | await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text3) | ||
101 | }) | ||
102 | |||
103 | it('Should get correctly the replies', async function () { | ||
104 | const res = await getVideoThreadComments(server.url, videoUUID, threadId) | ||
105 | |||
106 | const tree: VideoCommentThreadTree = res.body | ||
107 | expect(tree.comment.text).equal('my super first comment') | ||
108 | expect(tree.children).to.have.lengthOf(2) | ||
109 | |||
110 | const firstChild = tree.children[0] | ||
111 | expect(firstChild.comment.text).to.equal('my super answer to thread 1') | ||
112 | expect(firstChild.children).to.have.lengthOf(1) | ||
113 | |||
114 | const childOfFirstChild = firstChild.children[0] | ||
115 | expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1') | ||
116 | expect(childOfFirstChild.children).to.have.lengthOf(0) | ||
117 | |||
118 | const secondChild = tree.children[1] | ||
119 | expect(secondChild.comment.text).to.equal('my second answer to thread 1') | ||
120 | expect(secondChild.children).to.have.lengthOf(0) | ||
121 | }) | ||
122 | |||
123 | it('Should create other threads', async function () { | ||
124 | const text1 = 'super thread 2' | ||
125 | await addVideoCommentThread(server.url, server.accessToken, videoUUID, text1) | ||
126 | |||
127 | const text2 = 'super thread 3' | ||
128 | await addVideoCommentThread(server.url, server.accessToken, videoUUID, text2) | ||
129 | }) | ||
130 | |||
131 | it('Should list the threads', async function () { | ||
132 | const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt') | ||
133 | |||
134 | expect(res.body.total).to.equal(3) | ||
135 | expect(res.body.data).to.be.an('array') | ||
136 | expect(res.body.data).to.have.lengthOf(3) | ||
137 | |||
138 | expect(res.body.data[0].text).to.equal('my super first comment') | ||
139 | expect(res.body.data[0].totalReplies).to.equal(3) | ||
140 | expect(res.body.data[1].text).to.equal('super thread 2') | ||
141 | expect(res.body.data[1].totalReplies).to.equal(0) | ||
142 | expect(res.body.data[2].text).to.equal('super thread 3') | ||
143 | expect(res.body.data[2].totalReplies).to.equal(0) | ||
144 | }) | ||
145 | |||
146 | after(async function () { | ||
147 | killallServers([ server ]) | ||
148 | |||
149 | // Keep the logs if the test failed | ||
150 | if (this['ok']) { | ||
151 | await flushTests() | ||
152 | } | ||
153 | }) | ||
154 | }) | ||
diff --git a/server/tests/api/videos/video-description.ts b/server/tests/api/videos/video-description.ts new file mode 100644 index 000000000..c2985194c --- /dev/null +++ b/server/tests/api/videos/video-description.ts | |||
@@ -0,0 +1,111 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | ||
5 | import { | ||
6 | flushAndRunMultipleServers, | ||
7 | flushTests, | ||
8 | getVideo, | ||
9 | getVideoDescription, | ||
10 | getVideosList, | ||
11 | killallServers, | ||
12 | ServerInfo, | ||
13 | setAccessTokensToServers, | ||
14 | updateVideo, | ||
15 | uploadVideo, | ||
16 | wait | ||
17 | } from '../../utils/index' | ||
18 | import { doubleFollow } from '../../utils/server/follows' | ||
19 | |||
20 | const expect = chai.expect | ||
21 | |||
22 | describe('Test video description', function () { | ||
23 | let servers: ServerInfo[] = [] | ||
24 | let videoUUID = '' | ||
25 | let videoId: number | ||
26 | let longDescription = 'my super description for server 1'.repeat(50) | ||
27 | |||
28 | before(async function () { | ||
29 | this.timeout(40000) | ||
30 | |||
31 | // Run servers | ||
32 | servers = await flushAndRunMultipleServers(2) | ||
33 | |||
34 | // Get the access tokens | ||
35 | await setAccessTokensToServers(servers) | ||
36 | |||
37 | // Server 1 and server 2 follow each other | ||
38 | await doubleFollow(servers[0], servers[1]) | ||
39 | }) | ||
40 | |||
41 | it('Should upload video with long description', async function () { | ||
42 | this.timeout(10000) | ||
43 | |||
44 | const attributes = { | ||
45 | description: longDescription | ||
46 | } | ||
47 | await uploadVideo(servers[0].url, servers[0].accessToken, attributes) | ||
48 | |||
49 | await wait(5000) | ||
50 | |||
51 | const res = await getVideosList(servers[0].url) | ||
52 | |||
53 | videoId = res.body.data[0].id | ||
54 | videoUUID = res.body.data[0].uuid | ||
55 | }) | ||
56 | |||
57 | it('Should have a truncated description on each server', async function () { | ||
58 | for (const server of servers) { | ||
59 | const res = await getVideo(server.url, videoUUID) | ||
60 | const video = res.body | ||
61 | |||
62 | // 30 characters * 6 -> 240 characters | ||
63 | const truncatedDescription = 'my super description for server 1'.repeat(7) + | ||
64 | 'my super descrip...' | ||
65 | |||
66 | expect(video.description).to.equal(truncatedDescription) | ||
67 | } | ||
68 | }) | ||
69 | |||
70 | it('Should fetch long description on each server', async function () { | ||
71 | for (const server of servers) { | ||
72 | const res = await getVideo(server.url, videoUUID) | ||
73 | const video = res.body | ||
74 | |||
75 | const res2 = await getVideoDescription(server.url, video.descriptionPath) | ||
76 | expect(res2.body.description).to.equal(longDescription) | ||
77 | } | ||
78 | }) | ||
79 | |||
80 | it('Should update with a short description', async function () { | ||
81 | this.timeout(10000) | ||
82 | |||
83 | const attributes = { | ||
84 | description: 'short description' | ||
85 | } | ||
86 | await updateVideo(servers[0].url, servers[0].accessToken, videoId, attributes) | ||
87 | |||
88 | await wait(5000) | ||
89 | }) | ||
90 | |||
91 | it('Should have a small description on each server', async function () { | ||
92 | for (const server of servers) { | ||
93 | const res = await getVideo(server.url, videoUUID) | ||
94 | const video = res.body | ||
95 | |||
96 | expect(video.description).to.equal('short description') | ||
97 | |||
98 | const res2 = await getVideoDescription(server.url, video.descriptionPath) | ||
99 | expect(res2.body.description).to.equal('short description') | ||
100 | } | ||
101 | }) | ||
102 | |||
103 | after(async function () { | ||
104 | killallServers(servers) | ||
105 | |||
106 | // Keep the logs if the test failed | ||
107 | if (this['ok']) { | ||
108 | await flushTests() | ||
109 | } | ||
110 | }) | ||
111 | }) | ||
diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts new file mode 100644 index 000000000..de709f8f1 --- /dev/null +++ b/server/tests/api/videos/video-privacy.ts | |||
@@ -0,0 +1,159 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | ||
5 | import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' | ||
6 | import { | ||
7 | flushAndRunMultipleServers, | ||
8 | flushTests, | ||
9 | getVideosList, | ||
10 | killallServers, | ||
11 | ServerInfo, | ||
12 | setAccessTokensToServers, | ||
13 | uploadVideo, | ||
14 | wait | ||
15 | } from '../../utils/index' | ||
16 | import { doubleFollow } from '../../utils/server/follows' | ||
17 | import { getUserAccessToken } from '../../utils/users/login' | ||
18 | import { createUser } from '../../utils/users/users' | ||
19 | import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../utils/videos/videos' | ||
20 | |||
21 | const expect = chai.expect | ||
22 | |||
23 | describe('Test video privacy', function () { | ||
24 | let servers: ServerInfo[] = [] | ||
25 | let privateVideoId | ||
26 | let privateVideoUUID | ||
27 | let unlistedVideoUUID | ||
28 | |||
29 | before(async function () { | ||
30 | this.timeout(50000) | ||
31 | |||
32 | // Run servers | ||
33 | servers = await flushAndRunMultipleServers(2) | ||
34 | |||
35 | // Get the access tokens | ||
36 | await setAccessTokensToServers(servers) | ||
37 | |||
38 | // Server 1 and server 2 follow each other | ||
39 | await doubleFollow(servers[0], servers[1]) | ||
40 | }) | ||
41 | |||
42 | it('Should upload a private video on server 1', async function () { | ||
43 | this.timeout(10000) | ||
44 | |||
45 | const attributes = { | ||
46 | privacy: VideoPrivacy.PRIVATE | ||
47 | } | ||
48 | await uploadVideo(servers[0].url, servers[0].accessToken, attributes) | ||
49 | |||
50 | await wait(5000) | ||
51 | }) | ||
52 | |||
53 | it('Should not have this private video on server 2', async function () { | ||
54 | const res = await getVideosList(servers[1].url) | ||
55 | |||
56 | expect(res.body.total).to.equal(0) | ||
57 | expect(res.body.data).to.have.lengthOf(0) | ||
58 | }) | ||
59 | |||
60 | it('Should list my (private) videos', async function () { | ||
61 | const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 1) | ||
62 | |||
63 | expect(res.body.total).to.equal(1) | ||
64 | expect(res.body.data).to.have.lengthOf(1) | ||
65 | |||
66 | privateVideoId = res.body.data[0].id | ||
67 | privateVideoUUID = res.body.data[0].uuid | ||
68 | }) | ||
69 | |||
70 | it('Should not be able to watch this video with non authenticated user', async function () { | ||
71 | await getVideo(servers[0].url, privateVideoUUID, 401) | ||
72 | }) | ||
73 | |||
74 | it('Should not be able to watch this private video with another user', async function () { | ||
75 | const user = { | ||
76 | username: 'hello', | ||
77 | password: 'super password' | ||
78 | } | ||
79 | await createUser(servers[0].url, servers[0].accessToken, user.username, user.password) | ||
80 | |||
81 | const token = await getUserAccessToken(servers[0], user) | ||
82 | await getVideoWithToken(servers[0].url, token, privateVideoUUID, 403) | ||
83 | }) | ||
84 | |||
85 | it('Should be able to watch this video with the correct user', async function () { | ||
86 | await getVideoWithToken(servers[0].url, servers[0].accessToken, privateVideoUUID) | ||
87 | }) | ||
88 | |||
89 | it('Should upload an unlisted video on server 2', async function () { | ||
90 | this.timeout(30000) | ||
91 | |||
92 | const attributes = { | ||
93 | name: 'unlisted video', | ||
94 | privacy: VideoPrivacy.UNLISTED | ||
95 | } | ||
96 | await uploadVideo(servers[1].url, servers[1].accessToken, attributes) | ||
97 | |||
98 | // Server 2 has transcoding enabled | ||
99 | await wait(10000) | ||
100 | }) | ||
101 | |||
102 | it('Should not have this unlisted video listed on server 1 and 2', async function () { | ||
103 | for (const server of servers) { | ||
104 | const res = await getVideosList(server.url) | ||
105 | |||
106 | expect(res.body.total).to.equal(0) | ||
107 | expect(res.body.data).to.have.lengthOf(0) | ||
108 | } | ||
109 | }) | ||
110 | |||
111 | it('Should list my (unlisted) videos', async function () { | ||
112 | const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 1) | ||
113 | |||
114 | expect(res.body.total).to.equal(1) | ||
115 | expect(res.body.data).to.have.lengthOf(1) | ||
116 | |||
117 | unlistedVideoUUID = res.body.data[0].uuid | ||
118 | }) | ||
119 | |||
120 | it('Should be able to get this unlisted video', async function () { | ||
121 | for (const server of servers) { | ||
122 | const res = await getVideo(server.url, unlistedVideoUUID) | ||
123 | |||
124 | expect(res.body.name).to.equal('unlisted video') | ||
125 | } | ||
126 | }) | ||
127 | |||
128 | it('Should update the private video to public on server 1', async function () { | ||
129 | this.timeout(10000) | ||
130 | |||
131 | const attribute = { | ||
132 | name: 'super video public', | ||
133 | privacy: VideoPrivacy.PUBLIC | ||
134 | } | ||
135 | |||
136 | await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, attribute) | ||
137 | |||
138 | await wait(5000) | ||
139 | }) | ||
140 | |||
141 | it('Should have this new public video listed on server 1 and 2', async function () { | ||
142 | for (const server of servers) { | ||
143 | const res = await getVideosList(server.url) | ||
144 | |||
145 | expect(res.body.total).to.equal(1) | ||
146 | expect(res.body.data).to.have.lengthOf(1) | ||
147 | expect(res.body.data[0].name).to.equal('super video public') | ||
148 | } | ||
149 | }) | ||
150 | |||
151 | after(async function () { | ||
152 | killallServers(servers) | ||
153 | |||
154 | // Keep the logs if the test failed | ||
155 | if (this['ok']) { | ||
156 | await flushTests() | ||
157 | } | ||
158 | }) | ||
159 | }) | ||
diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts new file mode 100644 index 000000000..27927a594 --- /dev/null +++ b/server/tests/api/videos/video-transcoder.ts | |||
@@ -0,0 +1,97 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import * as chai from 'chai' | ||
5 | const expect = chai.expect | ||
6 | |||
7 | import { | ||
8 | ServerInfo, | ||
9 | flushTests, | ||
10 | uploadVideo, | ||
11 | getVideosList, | ||
12 | wait, | ||
13 | setAccessTokensToServers, | ||
14 | flushAndRunMultipleServers, | ||
15 | killallServers, | ||
16 | webtorrentAdd, | ||
17 | getVideo | ||
18 | } from '../../utils/index' | ||
19 | |||
20 | describe('Test video transcoding', function () { | ||
21 | let servers: ServerInfo[] = [] | ||
22 | |||
23 | before(async function () { | ||
24 | this.timeout(10000) | ||
25 | |||
26 | // Run servers | ||
27 | servers = await flushAndRunMultipleServers(2) | ||
28 | |||
29 | await setAccessTokensToServers(servers) | ||
30 | }) | ||
31 | |||
32 | it('Should not transcode video on server 1', async function () { | ||
33 | this.timeout(60000) | ||
34 | |||
35 | const videoAttributes = { | ||
36 | name: 'my super name for server 1', | ||
37 | description: 'my super description for server 1', | ||
38 | fixture: 'video_short.webm' | ||
39 | } | ||
40 | await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) | ||
41 | |||
42 | await wait(10000) | ||
43 | |||
44 | const res = await getVideosList(servers[0].url) | ||
45 | const video = res.body.data[0] | ||
46 | |||
47 | const res2 = await getVideo(servers[0].url, video.id) | ||
48 | const videoDetails = res2.body | ||
49 | expect(videoDetails.files).to.have.lengthOf(1) | ||
50 | |||
51 | const magnetUri = videoDetails.files[0].magnetUri | ||
52 | expect(magnetUri).to.match(/\.webm/) | ||
53 | |||
54 | const torrent = await webtorrentAdd(magnetUri) | ||
55 | expect(torrent.files).to.be.an('array') | ||
56 | expect(torrent.files.length).to.equal(1) | ||
57 | expect(torrent.files[0].path).match(/\.webm$/) | ||
58 | }) | ||
59 | |||
60 | it('Should transcode video on server 2', async function () { | ||
61 | this.timeout(60000) | ||
62 | |||
63 | const videoAttributes = { | ||
64 | name: 'my super name for server 2', | ||
65 | description: 'my super description for server 2', | ||
66 | fixture: 'video_short.webm' | ||
67 | } | ||
68 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | ||
69 | |||
70 | await wait(20000) | ||
71 | |||
72 | const res = await getVideosList(servers[1].url) | ||
73 | |||
74 | const video = res.body.data[0] | ||
75 | const res2 = await getVideo(servers[1].url, video.id) | ||
76 | const videoDetails = res2.body | ||
77 | |||
78 | expect(videoDetails.files).to.have.lengthOf(4) | ||
79 | |||
80 | const magnetUri = videoDetails.files[0].magnetUri | ||
81 | expect(magnetUri).to.match(/\.mp4/) | ||
82 | |||
83 | const torrent = await webtorrentAdd(magnetUri) | ||
84 | expect(torrent.files).to.be.an('array') | ||
85 | expect(torrent.files.length).to.equal(1) | ||
86 | expect(torrent.files[0].path).match(/\.mp4$/) | ||
87 | }) | ||
88 | |||
89 | after(async function () { | ||
90 | killallServers(servers) | ||
91 | |||
92 | // Keep the logs if the test failed | ||
93 | if (this['ok']) { | ||
94 | await flushTests() | ||
95 | } | ||
96 | }) | ||
97 | }) | ||