]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/single-server.ts
nginx optimizations
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / single-server.ts
CommitLineData
0e1dc3e7
C
1/* tslint:disable:no-unused-expression */
2
8e7f08b5 3import * as chai from 'chai'
0e1dc3e7 4import { keyBy } from 'lodash'
0e1dc3e7 5import 'mocha'
a20399c9 6import { VideoPrivacy } from '../../../../shared/models/videos'
0e1dc3e7 7import {
f05a1c30
C
8 checkVideoFilesWereRemoved, completeVideoCheck, flushTests, getVideo, getVideoCategories, getVideoLanguages, getVideoLicences,
9 getVideoPrivacies, getVideosList, getVideosListPagination, getVideosListSort, killallServers, rateVideo, removeVideo, runServer,
10 searchVideo, searchVideoWithPagination, searchVideoWithSort, ServerInfo, setAccessTokensToServers, testImage, updateVideo, uploadVideo,
11 viewVideo
a20399c9 12} from '../../utils'
0e1dc3e7 13
8e7f08b5
C
14const expect = chai.expect
15
9a27cdc2 16describe('Test a single server', function () {
0e1dc3e7
C
17 let server: ServerInfo = null
18 let videoId = -1
19 let videoUUID = ''
20 let videosListBase: any[] = null
21
a20399c9
C
22 const getCheckAttributes = {
23 name: 'my super name',
24 category: 2,
25 licence: 6,
26 language: 3,
27 nsfw: true,
28 description: 'my super description',
29 host: 'localhost:9001',
30 account: 'root',
31 isLocal: true,
b1f5b93e 32 duration: 5,
a20399c9
C
33 tags: [ 'tag1', 'tag2', 'tag3' ],
34 privacy: VideoPrivacy.PUBLIC,
47564bbe 35 commentsEnabled: true,
a20399c9
C
36 channel: {
37 name: 'Default root channel',
b1f5b93e 38 description: '',
a20399c9
C
39 isLocal: true
40 },
41 fixture: 'video_short.webm',
42 files: [
43 {
44 resolution: 720,
45 size: 218910
46 }
47 ]
48 }
49
50 const updateCheckAttributes = {
51 name: 'my super video updated',
52 category: 4,
53 licence: 2,
54 language: 5,
47564bbe 55 nsfw: false,
a20399c9
C
56 description: 'my super description updated',
57 host: 'localhost:9001',
58 account: 'root',
59 isLocal: true,
60 tags: [ 'tagup1', 'tagup2' ],
61 privacy: VideoPrivacy.PUBLIC,
b1f5b93e 62 duration: 5,
47564bbe 63 commentsEnabled: false,
a20399c9
C
64 channel: {
65 name: 'Default root channel',
b1f5b93e 66 description: '',
a20399c9
C
67 isLocal: true
68 },
69 fixture: 'video_short3.webm',
70 files: [
71 {
72 resolution: 720,
73 size: 292677
74 }
75 ]
76 }
77
0e1dc3e7 78 before(async function () {
572f8d3d 79 this.timeout(10000)
0e1dc3e7
C
80
81 await flushTests()
82
83 server = await runServer(1)
84
85 await setAccessTokensToServers([ server ])
86 })
87
88 it('Should list video categories', async function () {
89 const res = await getVideoCategories(server.url)
90
91 const categories = res.body
92 expect(Object.keys(categories)).to.have.length.above(10)
93
94 expect(categories[11]).to.equal('News')
95 })
96
97 it('Should list video licences', async function () {
98 const res = await getVideoLicences(server.url)
99
100 const licences = res.body
101 expect(Object.keys(licences)).to.have.length.above(5)
102
103 expect(licences[3]).to.equal('Attribution - No Derivatives')
104 })
105
106 it('Should list video languages', async function () {
107 const res = await getVideoLanguages(server.url)
108
109 const languages = res.body
110 expect(Object.keys(languages)).to.have.length.above(5)
111
112 expect(languages[3]).to.equal('Mandarin')
113 })
114
11474c3c
C
115 it('Should list video privacies', async function () {
116 const res = await getVideoPrivacies(server.url)
117
118 const privacies = res.body
119 expect(Object.keys(privacies)).to.have.length.at.least(3)
120
121 expect(privacies[3]).to.equal('Private')
122 })
123
0e1dc3e7
C
124 it('Should not have videos', async function () {
125 const res = await getVideosList(server.url)
126
127 expect(res.body.total).to.equal(0)
128 expect(res.body.data).to.be.an('array')
129 expect(res.body.data.length).to.equal(0)
130 })
131
132 it('Should upload the video', async function () {
133 const videoAttributes = {
134 name: 'my super name',
135 category: 2,
136 nsfw: true,
137 licence: 6,
138 tags: [ 'tag1', 'tag2', 'tag3' ]
139 }
cadb46d8
C
140 const res = await uploadVideo(server.url, server.accessToken, videoAttributes)
141 expect(res.body.video).to.not.be.undefined
142 expect(res.body.video.id).to.equal(1)
143 expect(res.body.video.uuid).to.have.length.above(5)
a20399c9
C
144
145 videoId = res.body.video.id
146 videoUUID = res.body.video.uuid
0e1dc3e7
C
147 })
148
a20399c9 149 it('Should get and seed the uploaded video', async function () {
0e1dc3e7
C
150 // Yes, this could be long
151 this.timeout(60000)
152
153 const res = await getVideosList(server.url)
154
155 expect(res.body.total).to.equal(1)
156 expect(res.body.data).to.be.an('array')
157 expect(res.body.data.length).to.equal(1)
158
159 const video = res.body.data[0]
a20399c9 160 await completeVideoCheck(server.url, video, getCheckAttributes)
0e1dc3e7
C
161 })
162
163 it('Should get the video by UUID', async function () {
164 // Yes, this could be long
165 this.timeout(60000)
166
167 const res = await getVideo(server.url, videoUUID)
168
169 const video = res.body
a20399c9 170 await completeVideoCheck(server.url, video, getCheckAttributes)
0e1dc3e7
C
171 })
172
173 it('Should have the views updated', async function () {
1f3e9fec
C
174 await viewVideo(server.url, videoId)
175 await viewVideo(server.url, videoId)
176 await viewVideo(server.url, videoId)
177
0e1dc3e7
C
178 const res = await getVideo(server.url, videoId)
179
180 const video = res.body
5f04dd2f 181 expect(video.views).to.equal(3)
0e1dc3e7
C
182 })
183
f3aaa9a9 184 it('Should search the video by name', async function () {
0e1dc3e7
C
185 const res = await searchVideo(server.url, 'my')
186
187 expect(res.body.total).to.equal(1)
188 expect(res.body.data).to.be.an('array')
189 expect(res.body.data.length).to.equal(1)
190
191 const video = res.body.data[0]
a20399c9 192 await completeVideoCheck(server.url, video, getCheckAttributes)
0e1dc3e7
C
193 })
194
195 // Not implemented yet
afffe988 196 // it('Should search the video by serverHost', async function () {
0e1dc3e7
C
197 // const res = await videosUtils.searchVideo(server.url, '9001', 'host')
198
199 // expect(res.body.total).to.equal(1)
200 // expect(res.body.data).to.be.an('array')
201 // expect(res.body.data.length).to.equal(1)
202
203 // const video = res.body.data[0]
204 // expect(video.name).to.equal('my super name')
205 // expect(video.description).to.equal('my super description')
afffe988 206 // expect(video.serverHost).to.equal('localhost:9001')
0e1dc3e7
C
207 // expect(video.author).to.equal('root')
208 // expect(video.isLocal).to.be.true
209 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
210 // expect(dateIsValid(video.createdAt)).to.be.true
211 // expect(dateIsValid(video.updatedAt)).to.be.true
212
213 // const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
214 // expect(test).to.equal(true)
215
216 // done()
217 // })
218 // })
219 // })
220
f3aaa9a9
C
221 // Not implemented yet
222 // it('Should search the video by tag', async function () {
223 // const res = await searchVideo(server.url, 'tag1')
224 //
225 // expect(res.body.total).to.equal(1)
226 // expect(res.body.data).to.be.an('array')
227 // expect(res.body.data.length).to.equal(1)
228 //
229 // const video = res.body.data[0]
230 // expect(video.name).to.equal('my super name')
231 // expect(video.category).to.equal(2)
232 // expect(video.categoryLabel).to.equal('Films')
233 // expect(video.licence).to.equal(6)
234 // expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
235 // expect(video.language).to.equal(3)
236 // expect(video.languageLabel).to.equal('Mandarin')
237 // expect(video.nsfw).to.be.ok
238 // expect(video.description).to.equal('my super description')
239 // expect(video.serverHost).to.equal('localhost:9001')
b1fa3eba 240 // expect(video.accountName).to.equal('root')
f3aaa9a9
C
241 // expect(video.isLocal).to.be.true
242 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
243 // expect(dateIsValid(video.createdAt)).to.be.true
244 // expect(dateIsValid(video.updatedAt)).to.be.true
245 //
246 // const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
247 // expect(test).to.equal(true)
248 // })
0e1dc3e7 249
f3aaa9a9 250 it('Should not find a search by name', async function () {
0e1dc3e7
C
251 const res = await searchVideo(server.url, 'hello')
252
253 expect(res.body.total).to.equal(0)
254 expect(res.body.data).to.be.an('array')
255 expect(res.body.data.length).to.equal(0)
256 })
257
f3aaa9a9
C
258 // Not implemented yet
259 // it('Should not find a search by author', async function () {
260 // const res = await searchVideo(server.url, 'hello')
261 //
262 // expect(res.body.total).to.equal(0)
263 // expect(res.body.data).to.be.an('array')
264 // expect(res.body.data.length).to.equal(0)
265 // })
266 //
267 // Not implemented yet
268 // it('Should not find a search by tag', async function () {
269 // const res = await searchVideo(server.url, 'hello')
270 //
271 // expect(res.body.total).to.equal(0)
272 // expect(res.body.data).to.be.an('array')
273 // expect(res.body.data.length).to.equal(0)
274 // })
0e1dc3e7
C
275
276 it('Should remove the video', async function () {
277 await removeVideo(server.url, server.accessToken, videoId)
278
f05a1c30 279 await checkVideoFilesWereRemoved(videoUUID, 1)
0e1dc3e7
C
280 })
281
282 it('Should not have videos', async function () {
283 const res = await getVideosList(server.url)
284
285 expect(res.body.total).to.equal(0)
286 expect(res.body.data).to.be.an('array')
287 expect(res.body.data).to.have.lengthOf(0)
288 })
289
290 it('Should upload 6 videos', async function () {
291 this.timeout(25000)
292
293 const videos = [
294 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
295 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
296 ]
297
e11f68a3 298 const tasks: Promise<any>[] = []
0e1dc3e7
C
299 for (const video of videos) {
300 const videoAttributes = {
301 name: video + ' name',
302 description: video + ' description',
303 category: 2,
304 licence: 1,
305 language: 1,
306 nsfw: true,
307 tags: [ 'tag1', 'tag2', 'tag3' ],
308 fixture: video
309 }
310
311 const p = uploadVideo(server.url, server.accessToken, videoAttributes)
e11f68a3 312 tasks.push(p)
0e1dc3e7 313 }
e11f68a3
C
314
315 await Promise.all(tasks)
0e1dc3e7
C
316 })
317
318 it('Should have the correct durations', async function () {
319 const res = await getVideosList(server.url)
320
321 expect(res.body.total).to.equal(6)
322 const videos = res.body.data
323 expect(videos).to.be.an('array')
324 expect(videos).to.have.lengthOf(6)
325
326 const videosByName = keyBy<{ duration: number }>(videos, 'name')
327 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
328 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
329 expect(videosByName['video_short.webm name'].duration).to.equal(5)
330 expect(videosByName['video_short1.webm name'].duration).to.equal(10)
331 expect(videosByName['video_short2.webm name'].duration).to.equal(5)
332 expect(videosByName['video_short3.webm name'].duration).to.equal(5)
333 })
334
335 it('Should have the correct thumbnails', async function () {
336 const res = await getVideosList(server.url)
337
338 const videos = res.body.data
339 // For the next test
340 videosListBase = videos
341
342 for (const video of videos) {
343 const videoName = video.name.replace(' name', '')
f05a1c30 344 const test = await testImage(server.url, videoName, video.thumbnailPath)
0e1dc3e7
C
345
346 expect(test).to.equal(true)
347 }
348 })
349
350 it('Should list only the two first videos', async function () {
351 const res = await getVideosListPagination(server.url, 0, 2, 'name')
352
353 const videos = res.body.data
354 expect(res.body.total).to.equal(6)
355 expect(videos.length).to.equal(2)
356 expect(videos[0].name).to.equal(videosListBase[0].name)
357 expect(videos[1].name).to.equal(videosListBase[1].name)
358 })
359
360 it('Should list only the next three videos', async function () {
361 const res = await getVideosListPagination(server.url, 2, 3, 'name')
362
363 const videos = res.body.data
364 expect(res.body.total).to.equal(6)
365 expect(videos.length).to.equal(3)
366 expect(videos[0].name).to.equal(videosListBase[2].name)
367 expect(videos[1].name).to.equal(videosListBase[3].name)
368 expect(videos[2].name).to.equal(videosListBase[4].name)
369 })
370
371 it('Should list the last video', async function () {
372 const res = await getVideosListPagination(server.url, 5, 6, 'name')
373
374 const videos = res.body.data
375 expect(res.body.total).to.equal(6)
376 expect(videos.length).to.equal(1)
377 expect(videos[0].name).to.equal(videosListBase[5].name)
378 })
379
380 it('Should search the first video', async function () {
f3aaa9a9 381 const res = await searchVideoWithPagination(server.url, 'webm', 0, 1, 'name')
0e1dc3e7
C
382
383 const videos = res.body.data
384 expect(res.body.total).to.equal(4)
385 expect(videos.length).to.equal(1)
386 expect(videos[0].name).to.equal('video_short1.webm name')
387 })
388
389 it('Should search the last two videos', async function () {
f3aaa9a9 390 const res = await searchVideoWithPagination(server.url, 'webm', 2, 2, 'name')
0e1dc3e7
C
391
392 const videos = res.body.data
393 expect(res.body.total).to.equal(4)
394 expect(videos.length).to.equal(2)
395 expect(videos[0].name).to.equal('video_short3.webm name')
396 expect(videos[1].name).to.equal('video_short.webm name')
397 })
398
399 it('Should search all the webm videos', async function () {
f3aaa9a9 400 const res = await searchVideoWithPagination(server.url, 'webm', 0, 15)
0e1dc3e7
C
401
402 const videos = res.body.data
403 expect(res.body.total).to.equal(4)
404 expect(videos.length).to.equal(4)
405 })
406
f3aaa9a9
C
407 // Not implemented yet
408 // it('Should search all the root author videos', async function () {
409 // const res = await searchVideoWithPagination(server.url, 'root', 0, 15)
410 //
411 // const videos = res.body.data
412 // expect(res.body.total).to.equal(6)
413 // expect(videos.length).to.equal(6)
414 // })
0e1dc3e7
C
415
416 // Not implemented yet
417 // it('Should search all the 9001 port videos', async function () {
418 // const res = await videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15)
419
420 // const videos = res.body.data
421 // expect(res.body.total).to.equal(6)
422 // expect(videos.length).to.equal(6)
423
424 // done()
425 // })
426 // })
427
428 // it('Should search all the localhost videos', async function () {
429 // const res = await videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15)
430
431 // const videos = res.body.data
432 // expect(res.body.total).to.equal(6)
433 // expect(videos.length).to.equal(6)
434
435 // done()
436 // })
437 // })
438
0e1dc3e7
C
439 it('Should list and sort by name in descending order', async function () {
440 const res = await getVideosListSort(server.url, '-name')
441
442 const videos = res.body.data
443 expect(res.body.total).to.equal(6)
444 expect(videos.length).to.equal(6)
445 expect(videos[0].name).to.equal('video_short.webm name')
446 expect(videos[1].name).to.equal('video_short.ogv name')
447 expect(videos[2].name).to.equal('video_short.mp4 name')
448 expect(videos[3].name).to.equal('video_short3.webm name')
449 expect(videos[4].name).to.equal('video_short2.webm name')
450 expect(videos[5].name).to.equal('video_short1.webm name')
451 })
452
453 it('Should search and sort by name in ascending order', async function () {
454 const res = await searchVideoWithSort(server.url, 'webm', 'name')
455
456 const videos = res.body.data
457 expect(res.body.total).to.equal(4)
458 expect(videos.length).to.equal(4)
459
460 expect(videos[0].name).to.equal('video_short1.webm name')
461 expect(videos[1].name).to.equal('video_short2.webm name')
462 expect(videos[2].name).to.equal('video_short3.webm name')
463 expect(videos[3].name).to.equal('video_short.webm name')
464
465 videoId = videos[2].id
466 })
467
468 it('Should update a video', async function () {
469 const attributes = {
470 name: 'my super video updated',
471 category: 4,
472 licence: 2,
473 language: 5,
474 nsfw: false,
475 description: 'my super description updated',
47564bbe 476 commentsEnabled: false,
0e1dc3e7
C
477 tags: [ 'tagup1', 'tagup2' ]
478 }
479 await updateVideo(server.url, server.accessToken, videoId, attributes)
480 })
481
482 it('Should have the video updated', async function () {
483 this.timeout(60000)
484
485 const res = await getVideo(server.url, videoId)
0e1dc3e7
C
486 const video = res.body
487
a20399c9 488 await completeVideoCheck(server.url, video, updateCheckAttributes)
0e1dc3e7
C
489 })
490
491 it('Should update only the tags of a video', async function () {
492 const attributes = {
a20399c9 493 tags: [ 'supertag', 'tag1', 'tag2' ]
0e1dc3e7 494 }
0e1dc3e7
C
495 await updateVideo(server.url, server.accessToken, videoId, attributes)
496
497 const res = await getVideo(server.url, videoId)
498 const video = res.body
499
a20399c9 500 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes, attributes))
0e1dc3e7
C
501 })
502
503 it('Should update only the description of a video', async function () {
504 const attributes = {
505 description: 'hello everybody'
506 }
0e1dc3e7
C
507 await updateVideo(server.url, server.accessToken, videoId, attributes)
508
509 const res = await getVideo(server.url, videoId)
510 const video = res.body
511
a20399c9 512 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes, attributes))
0e1dc3e7
C
513 })
514
515 it('Should like a video', async function () {
516 await rateVideo(server.url, server.accessToken, videoId, 'like')
517
518 const res = await getVideo(server.url, videoId)
519 const video = res.body
520
521 expect(video.likes).to.equal(1)
522 expect(video.dislikes).to.equal(0)
523 })
524
525 it('Should dislike the same video', async function () {
526 await rateVideo(server.url, server.accessToken, videoId, 'dislike')
527
528 const res = await getVideo(server.url, videoId)
529 const video = res.body
530
531 expect(video.likes).to.equal(0)
532 expect(video.dislikes).to.equal(1)
533 })
534
535 after(async function () {
536 killallServers([ server ])
537
538 // Keep the logs if the test failed
539 if (this['ok']) {
540 await flushTests()
541 }
542 })
543})