]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/single-server.ts
Remove tmp file on image processing error
[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 {
3cd0734f
C
8 checkVideoFilesWereRemoved,
9 completeVideoCheck,
10 flushTests,
11 getVideo,
12 getVideoCategories,
13 getVideoLanguages,
14 getVideoLicences,
15 getVideoPrivacies,
16 getVideosList,
17 getVideosListPagination,
18 getVideosListSort,
d525fc39 19 getVideosWithFilters,
3cd0734f
C
20 killallServers,
21 rateVideo,
22 removeVideo,
23 runServer,
3cd0734f
C
24 ServerInfo,
25 setAccessTokensToServers,
26 testImage,
27 updateVideo,
28 uploadVideo,
29 viewVideo,
30 wait
9639bd17 31} from '../../../../shared/utils'
0e1dc3e7 32
8e7f08b5
C
33const expect = chai.expect
34
9a27cdc2 35describe('Test a single server', function () {
0e1dc3e7
C
36 let server: ServerInfo = null
37 let videoId = -1
38 let videoUUID = ''
39 let videosListBase: any[] = null
40
a20399c9
C
41 const getCheckAttributes = {
42 name: 'my super name',
43 category: 2,
44 licence: 6,
9d3ef9fe 45 language: 'zh',
a20399c9
C
46 nsfw: true,
47 description: 'my super description',
2422c46b 48 support: 'my super support text',
b64c950a
C
49 account: {
50 name: 'root',
51 host: 'localhost:9001'
52 },
a20399c9 53 isLocal: true,
b1f5b93e 54 duration: 5,
a20399c9
C
55 tags: [ 'tag1', 'tag2', 'tag3' ],
56 privacy: VideoPrivacy.PUBLIC,
47564bbe 57 commentsEnabled: true,
7f2cfe3a 58 downloadEnabled: true,
a20399c9 59 channel: {
f6eebcb3
C
60 displayName: 'Main root channel',
61 name: 'root_channel',
b1f5b93e 62 description: '',
a20399c9
C
63 isLocal: true
64 },
65 fixture: 'video_short.webm',
66 files: [
67 {
68 resolution: 720,
69 size: 218910
70 }
71 ]
72 }
73
74 const updateCheckAttributes = {
75 name: 'my super video updated',
76 category: 4,
77 licence: 2,
9d3ef9fe 78 language: 'ar',
47564bbe 79 nsfw: false,
a20399c9 80 description: 'my super description updated',
2422c46b 81 support: 'my super support text updated',
b64c950a
C
82 account: {
83 name: 'root',
84 host: 'localhost:9001'
85 },
a20399c9
C
86 isLocal: true,
87 tags: [ 'tagup1', 'tagup2' ],
88 privacy: VideoPrivacy.PUBLIC,
b1f5b93e 89 duration: 5,
47564bbe 90 commentsEnabled: false,
7f2cfe3a 91 downloadEnabled: false,
a20399c9 92 channel: {
f6eebcb3
C
93 name: 'root_channel',
94 displayName: 'Main root channel',
b1f5b93e 95 description: '',
a20399c9
C
96 isLocal: true
97 },
98 fixture: 'video_short3.webm',
99 files: [
100 {
101 resolution: 720,
102 size: 292677
103 }
104 ]
105 }
106
0e1dc3e7 107 before(async function () {
e212f887 108 this.timeout(30000)
0e1dc3e7
C
109
110 await flushTests()
111
112 server = await runServer(1)
113
114 await setAccessTokensToServers([ server ])
115 })
116
117 it('Should list video categories', async function () {
118 const res = await getVideoCategories(server.url)
119
120 const categories = res.body
121 expect(Object.keys(categories)).to.have.length.above(10)
122
6f2ae7a1 123 expect(categories[11]).to.equal('News & Politics')
0e1dc3e7
C
124 })
125
126 it('Should list video licences', async function () {
127 const res = await getVideoLicences(server.url)
128
129 const licences = res.body
130 expect(Object.keys(licences)).to.have.length.above(5)
131
132 expect(licences[3]).to.equal('Attribution - No Derivatives')
133 })
134
135 it('Should list video languages', async function () {
136 const res = await getVideoLanguages(server.url)
137
138 const languages = res.body
139 expect(Object.keys(languages)).to.have.length.above(5)
140
9d3ef9fe 141 expect(languages['ru']).to.equal('Russian')
0e1dc3e7
C
142 })
143
11474c3c
C
144 it('Should list video privacies', async function () {
145 const res = await getVideoPrivacies(server.url)
146
147 const privacies = res.body
148 expect(Object.keys(privacies)).to.have.length.at.least(3)
149
150 expect(privacies[3]).to.equal('Private')
151 })
152
0e1dc3e7
C
153 it('Should not have videos', async function () {
154 const res = await getVideosList(server.url)
155
156 expect(res.body.total).to.equal(0)
157 expect(res.body.data).to.be.an('array')
158 expect(res.body.data.length).to.equal(0)
159 })
160
161 it('Should upload the video', async function () {
162 const videoAttributes = {
163 name: 'my super name',
164 category: 2,
165 nsfw: true,
166 licence: 6,
167 tags: [ 'tag1', 'tag2', 'tag3' ]
168 }
cadb46d8
C
169 const res = await uploadVideo(server.url, server.accessToken, videoAttributes)
170 expect(res.body.video).to.not.be.undefined
171 expect(res.body.video.id).to.equal(1)
172 expect(res.body.video.uuid).to.have.length.above(5)
a20399c9
C
173
174 videoId = res.body.video.id
175 videoUUID = res.body.video.uuid
0e1dc3e7
C
176 })
177
a20399c9 178 it('Should get and seed the uploaded video', async function () {
b5c0e955 179 this.timeout(5000)
0e1dc3e7
C
180
181 const res = await getVideosList(server.url)
182
183 expect(res.body.total).to.equal(1)
184 expect(res.body.data).to.be.an('array')
185 expect(res.body.data.length).to.equal(1)
186
187 const video = res.body.data[0]
a20399c9 188 await completeVideoCheck(server.url, video, getCheckAttributes)
0e1dc3e7
C
189 })
190
191 it('Should get the video by UUID', async function () {
b5c0e955 192 this.timeout(5000)
0e1dc3e7
C
193
194 const res = await getVideo(server.url, videoUUID)
195
196 const video = res.body
a20399c9 197 await completeVideoCheck(server.url, video, getCheckAttributes)
0e1dc3e7
C
198 })
199
200 it('Should have the views updated', async function () {
6b616860 201 this.timeout(20000)
b5c0e955
C
202
203 await viewVideo(server.url, videoId)
204 await viewVideo(server.url, videoId)
1f3e9fec 205 await viewVideo(server.url, videoId)
b5c0e955
C
206
207 await wait(1500)
208
209 await viewVideo(server.url, videoId)
210 await viewVideo(server.url, videoId)
211
212 await wait(1500)
213
1f3e9fec
C
214 await viewVideo(server.url, videoId)
215 await viewVideo(server.url, videoId)
216
6b616860
C
217 // Wait the repeatable job
218 await wait(8000)
219
0e1dc3e7
C
220 const res = await getVideo(server.url, videoId)
221
222 const video = res.body
5f04dd2f 223 expect(video.views).to.equal(3)
0e1dc3e7
C
224 })
225
0e1dc3e7
C
226 it('Should remove the video', async function () {
227 await removeVideo(server.url, server.accessToken, videoId)
228
f05a1c30 229 await checkVideoFilesWereRemoved(videoUUID, 1)
0e1dc3e7
C
230 })
231
232 it('Should not have videos', async function () {
233 const res = await getVideosList(server.url)
234
235 expect(res.body.total).to.equal(0)
236 expect(res.body.data).to.be.an('array')
237 expect(res.body.data).to.have.lengthOf(0)
238 })
239
240 it('Should upload 6 videos', async function () {
241 this.timeout(25000)
242
243 const videos = [
244 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
245 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
246 ]
247
e11f68a3 248 const tasks: Promise<any>[] = []
0e1dc3e7
C
249 for (const video of videos) {
250 const videoAttributes = {
251 name: video + ' name',
252 description: video + ' description',
253 category: 2,
254 licence: 1,
9d3ef9fe 255 language: 'en',
0e1dc3e7
C
256 nsfw: true,
257 tags: [ 'tag1', 'tag2', 'tag3' ],
258 fixture: video
259 }
260
261 const p = uploadVideo(server.url, server.accessToken, videoAttributes)
e11f68a3 262 tasks.push(p)
0e1dc3e7 263 }
e11f68a3
C
264
265 await Promise.all(tasks)
0e1dc3e7
C
266 })
267
268 it('Should have the correct durations', async function () {
269 const res = await getVideosList(server.url)
270
271 expect(res.body.total).to.equal(6)
272 const videos = res.body.data
273 expect(videos).to.be.an('array')
274 expect(videos).to.have.lengthOf(6)
275
276 const videosByName = keyBy<{ duration: number }>(videos, 'name')
277 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
278 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
279 expect(videosByName['video_short.webm name'].duration).to.equal(5)
280 expect(videosByName['video_short1.webm name'].duration).to.equal(10)
281 expect(videosByName['video_short2.webm name'].duration).to.equal(5)
282 expect(videosByName['video_short3.webm name'].duration).to.equal(5)
283 })
284
285 it('Should have the correct thumbnails', async function () {
286 const res = await getVideosList(server.url)
287
288 const videos = res.body.data
289 // For the next test
290 videosListBase = videos
291
292 for (const video of videos) {
293 const videoName = video.name.replace(' name', '')
7b0956ec 294 await testImage(server.url, videoName, video.thumbnailPath)
0e1dc3e7
C
295 }
296 })
297
298 it('Should list only the two first videos', async function () {
299 const res = await getVideosListPagination(server.url, 0, 2, 'name')
300
301 const videos = res.body.data
302 expect(res.body.total).to.equal(6)
303 expect(videos.length).to.equal(2)
304 expect(videos[0].name).to.equal(videosListBase[0].name)
305 expect(videos[1].name).to.equal(videosListBase[1].name)
306 })
307
308 it('Should list only the next three videos', async function () {
309 const res = await getVideosListPagination(server.url, 2, 3, 'name')
310
311 const videos = res.body.data
312 expect(res.body.total).to.equal(6)
313 expect(videos.length).to.equal(3)
314 expect(videos[0].name).to.equal(videosListBase[2].name)
315 expect(videos[1].name).to.equal(videosListBase[3].name)
316 expect(videos[2].name).to.equal(videosListBase[4].name)
317 })
318
319 it('Should list the last video', async function () {
320 const res = await getVideosListPagination(server.url, 5, 6, 'name')
321
322 const videos = res.body.data
323 expect(res.body.total).to.equal(6)
324 expect(videos.length).to.equal(1)
325 expect(videos[0].name).to.equal(videosListBase[5].name)
326 })
327
0e1dc3e7
C
328 it('Should list and sort by name in descending order', async function () {
329 const res = await getVideosListSort(server.url, '-name')
330
331 const videos = res.body.data
332 expect(res.body.total).to.equal(6)
333 expect(videos.length).to.equal(6)
334 expect(videos[0].name).to.equal('video_short.webm name')
335 expect(videos[1].name).to.equal('video_short.ogv name')
336 expect(videos[2].name).to.equal('video_short.mp4 name')
337 expect(videos[3].name).to.equal('video_short3.webm name')
338 expect(videos[4].name).to.equal('video_short2.webm name')
339 expect(videos[5].name).to.equal('video_short1.webm name')
0e1dc3e7 340
d525fc39 341 videoId = videos[3].uuid
0e1dc3e7
C
342 })
343
0b74c74a
C
344 it('Should list and sort by trending in descending order', async function () {
345 const res = await getVideosListPagination(server.url, 0, 2, '-trending')
346
347 const videos = res.body.data
348 expect(res.body.total).to.equal(6)
349 expect(videos.length).to.equal(2)
350 })
351
0e1dc3e7
C
352 it('Should update a video', async function () {
353 const attributes = {
354 name: 'my super video updated',
355 category: 4,
356 licence: 2,
9d3ef9fe 357 language: 'ar',
0e1dc3e7
C
358 nsfw: false,
359 description: 'my super description updated',
47564bbe 360 commentsEnabled: false,
7f2cfe3a 361 downloadEnabled: false,
0e1dc3e7
C
362 tags: [ 'tagup1', 'tagup2' ]
363 }
364 await updateVideo(server.url, server.accessToken, videoId, attributes)
365 })
366
d525fc39
C
367 it('Should filter by tags and category', async function () {
368 const res1 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: 4 })
369 expect(res1.body.total).to.equal(1)
370 expect(res1.body.data[0].name).to.equal('my super video updated')
371
372 const res2 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: 3 })
373 expect(res2.body.total).to.equal(0)
374 })
375
0e1dc3e7
C
376 it('Should have the video updated', async function () {
377 this.timeout(60000)
378
379 const res = await getVideo(server.url, videoId)
0e1dc3e7
C
380 const video = res.body
381
a20399c9 382 await completeVideoCheck(server.url, video, updateCheckAttributes)
0e1dc3e7
C
383 })
384
385 it('Should update only the tags of a video', async function () {
386 const attributes = {
a20399c9 387 tags: [ 'supertag', 'tag1', 'tag2' ]
0e1dc3e7 388 }
0e1dc3e7
C
389 await updateVideo(server.url, server.accessToken, videoId, attributes)
390
391 const res = await getVideo(server.url, videoId)
392 const video = res.body
393
a20399c9 394 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes, attributes))
0e1dc3e7
C
395 })
396
397 it('Should update only the description of a video', async function () {
398 const attributes = {
399 description: 'hello everybody'
400 }
0e1dc3e7
C
401 await updateVideo(server.url, server.accessToken, videoId, attributes)
402
403 const res = await getVideo(server.url, videoId)
404 const video = res.body
405
a20399c9 406 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes, attributes))
0e1dc3e7
C
407 })
408
409 it('Should like a video', async function () {
410 await rateVideo(server.url, server.accessToken, videoId, 'like')
411
412 const res = await getVideo(server.url, videoId)
413 const video = res.body
414
415 expect(video.likes).to.equal(1)
416 expect(video.dislikes).to.equal(0)
417 })
418
419 it('Should dislike the same video', async function () {
420 await rateVideo(server.url, server.accessToken, videoId, 'dislike')
421
422 const res = await getVideo(server.url, videoId)
423 const video = res.body
424
425 expect(video.likes).to.equal(0)
426 expect(video.dislikes).to.equal(1)
427 })
428
429 after(async function () {
430 killallServers([ server ])
431
432 // Keep the logs if the test failed
433 if (this['ok']) {
434 await flushTests()
435 }
436 })
437})