]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/single-server.ts
Fix rerunserver function
[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,
210feb6c 23 flushAndRunServer,
3cd0734f
C
24 ServerInfo,
25 setAccessTokensToServers,
26 testImage,
27 updateVideo,
28 uploadVideo,
29 viewVideo,
30 wait
94565d52 31} from '../../../../shared/extra-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 109
210feb6c 110 server = await flushAndRunServer(1)
0e1dc3e7
C
111
112 await setAccessTokensToServers([ server ])
113 })
114
115 it('Should list video categories', async function () {
116 const res = await getVideoCategories(server.url)
117
118 const categories = res.body
119 expect(Object.keys(categories)).to.have.length.above(10)
120
6f2ae7a1 121 expect(categories[11]).to.equal('News & Politics')
0e1dc3e7
C
122 })
123
124 it('Should list video licences', async function () {
125 const res = await getVideoLicences(server.url)
126
127 const licences = res.body
128 expect(Object.keys(licences)).to.have.length.above(5)
129
130 expect(licences[3]).to.equal('Attribution - No Derivatives')
131 })
132
133 it('Should list video languages', async function () {
134 const res = await getVideoLanguages(server.url)
135
136 const languages = res.body
137 expect(Object.keys(languages)).to.have.length.above(5)
138
9d3ef9fe 139 expect(languages['ru']).to.equal('Russian')
0e1dc3e7
C
140 })
141
11474c3c
C
142 it('Should list video privacies', async function () {
143 const res = await getVideoPrivacies(server.url)
144
145 const privacies = res.body
146 expect(Object.keys(privacies)).to.have.length.at.least(3)
147
148 expect(privacies[3]).to.equal('Private')
149 })
150
0e1dc3e7
C
151 it('Should not have videos', async function () {
152 const res = await getVideosList(server.url)
153
154 expect(res.body.total).to.equal(0)
155 expect(res.body.data).to.be.an('array')
156 expect(res.body.data.length).to.equal(0)
157 })
158
159 it('Should upload the video', async function () {
160 const videoAttributes = {
161 name: 'my super name',
162 category: 2,
163 nsfw: true,
164 licence: 6,
165 tags: [ 'tag1', 'tag2', 'tag3' ]
166 }
cadb46d8
C
167 const res = await uploadVideo(server.url, server.accessToken, videoAttributes)
168 expect(res.body.video).to.not.be.undefined
169 expect(res.body.video.id).to.equal(1)
170 expect(res.body.video.uuid).to.have.length.above(5)
a20399c9
C
171
172 videoId = res.body.video.id
173 videoUUID = res.body.video.uuid
0e1dc3e7
C
174 })
175
a20399c9 176 it('Should get and seed the uploaded video', async function () {
b5c0e955 177 this.timeout(5000)
0e1dc3e7
C
178
179 const res = await getVideosList(server.url)
180
181 expect(res.body.total).to.equal(1)
182 expect(res.body.data).to.be.an('array')
183 expect(res.body.data.length).to.equal(1)
184
185 const video = res.body.data[0]
a20399c9 186 await completeVideoCheck(server.url, video, getCheckAttributes)
0e1dc3e7
C
187 })
188
189 it('Should get the video by UUID', async function () {
b5c0e955 190 this.timeout(5000)
0e1dc3e7
C
191
192 const res = await getVideo(server.url, videoUUID)
193
194 const video = res.body
a20399c9 195 await completeVideoCheck(server.url, video, getCheckAttributes)
0e1dc3e7
C
196 })
197
198 it('Should have the views updated', async function () {
6b616860 199 this.timeout(20000)
b5c0e955
C
200
201 await viewVideo(server.url, videoId)
202 await viewVideo(server.url, videoId)
1f3e9fec 203 await viewVideo(server.url, videoId)
b5c0e955
C
204
205 await wait(1500)
206
207 await viewVideo(server.url, videoId)
208 await viewVideo(server.url, videoId)
209
210 await wait(1500)
211
1f3e9fec
C
212 await viewVideo(server.url, videoId)
213 await viewVideo(server.url, videoId)
214
6b616860
C
215 // Wait the repeatable job
216 await wait(8000)
217
0e1dc3e7
C
218 const res = await getVideo(server.url, videoId)
219
220 const video = res.body
5f04dd2f 221 expect(video.views).to.equal(3)
0e1dc3e7
C
222 })
223
0e1dc3e7
C
224 it('Should remove the video', async function () {
225 await removeVideo(server.url, server.accessToken, videoId)
226
f05a1c30 227 await checkVideoFilesWereRemoved(videoUUID, 1)
0e1dc3e7
C
228 })
229
230 it('Should not have videos', async function () {
231 const res = await getVideosList(server.url)
232
233 expect(res.body.total).to.equal(0)
234 expect(res.body.data).to.be.an('array')
235 expect(res.body.data).to.have.lengthOf(0)
236 })
237
238 it('Should upload 6 videos', async function () {
239 this.timeout(25000)
240
241 const videos = [
242 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
243 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
244 ]
245
e11f68a3 246 const tasks: Promise<any>[] = []
0e1dc3e7
C
247 for (const video of videos) {
248 const videoAttributes = {
249 name: video + ' name',
250 description: video + ' description',
251 category: 2,
252 licence: 1,
9d3ef9fe 253 language: 'en',
0e1dc3e7
C
254 nsfw: true,
255 tags: [ 'tag1', 'tag2', 'tag3' ],
256 fixture: video
257 }
258
259 const p = uploadVideo(server.url, server.accessToken, videoAttributes)
e11f68a3 260 tasks.push(p)
0e1dc3e7 261 }
e11f68a3
C
262
263 await Promise.all(tasks)
0e1dc3e7
C
264 })
265
266 it('Should have the correct durations', async function () {
267 const res = await getVideosList(server.url)
268
269 expect(res.body.total).to.equal(6)
270 const videos = res.body.data
271 expect(videos).to.be.an('array')
272 expect(videos).to.have.lengthOf(6)
273
274 const videosByName = keyBy<{ duration: number }>(videos, 'name')
275 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
276 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
277 expect(videosByName['video_short.webm name'].duration).to.equal(5)
278 expect(videosByName['video_short1.webm name'].duration).to.equal(10)
279 expect(videosByName['video_short2.webm name'].duration).to.equal(5)
280 expect(videosByName['video_short3.webm name'].duration).to.equal(5)
281 })
282
283 it('Should have the correct thumbnails', async function () {
284 const res = await getVideosList(server.url)
285
286 const videos = res.body.data
287 // For the next test
288 videosListBase = videos
289
290 for (const video of videos) {
291 const videoName = video.name.replace(' name', '')
7b0956ec 292 await testImage(server.url, videoName, video.thumbnailPath)
0e1dc3e7
C
293 }
294 })
295
296 it('Should list only the two first videos', async function () {
297 const res = await getVideosListPagination(server.url, 0, 2, 'name')
298
299 const videos = res.body.data
300 expect(res.body.total).to.equal(6)
301 expect(videos.length).to.equal(2)
302 expect(videos[0].name).to.equal(videosListBase[0].name)
303 expect(videos[1].name).to.equal(videosListBase[1].name)
304 })
305
306 it('Should list only the next three videos', async function () {
307 const res = await getVideosListPagination(server.url, 2, 3, 'name')
308
309 const videos = res.body.data
310 expect(res.body.total).to.equal(6)
311 expect(videos.length).to.equal(3)
312 expect(videos[0].name).to.equal(videosListBase[2].name)
313 expect(videos[1].name).to.equal(videosListBase[3].name)
314 expect(videos[2].name).to.equal(videosListBase[4].name)
315 })
316
317 it('Should list the last video', async function () {
318 const res = await getVideosListPagination(server.url, 5, 6, 'name')
319
320 const videos = res.body.data
321 expect(res.body.total).to.equal(6)
322 expect(videos.length).to.equal(1)
323 expect(videos[0].name).to.equal(videosListBase[5].name)
324 })
325
0e1dc3e7
C
326 it('Should list and sort by name in descending order', async function () {
327 const res = await getVideosListSort(server.url, '-name')
328
329 const videos = res.body.data
330 expect(res.body.total).to.equal(6)
331 expect(videos.length).to.equal(6)
332 expect(videos[0].name).to.equal('video_short.webm name')
333 expect(videos[1].name).to.equal('video_short.ogv name')
334 expect(videos[2].name).to.equal('video_short.mp4 name')
335 expect(videos[3].name).to.equal('video_short3.webm name')
336 expect(videos[4].name).to.equal('video_short2.webm name')
337 expect(videos[5].name).to.equal('video_short1.webm name')
0e1dc3e7 338
d525fc39 339 videoId = videos[3].uuid
0e1dc3e7
C
340 })
341
0b74c74a
C
342 it('Should list and sort by trending in descending order', async function () {
343 const res = await getVideosListPagination(server.url, 0, 2, '-trending')
344
345 const videos = res.body.data
346 expect(res.body.total).to.equal(6)
347 expect(videos.length).to.equal(2)
348 })
349
0e1dc3e7
C
350 it('Should update a video', async function () {
351 const attributes = {
352 name: 'my super video updated',
353 category: 4,
354 licence: 2,
9d3ef9fe 355 language: 'ar',
0e1dc3e7
C
356 nsfw: false,
357 description: 'my super description updated',
47564bbe 358 commentsEnabled: false,
7f2cfe3a 359 downloadEnabled: false,
0e1dc3e7
C
360 tags: [ 'tagup1', 'tagup2' ]
361 }
362 await updateVideo(server.url, server.accessToken, videoId, attributes)
363 })
364
d525fc39
C
365 it('Should filter by tags and category', async function () {
366 const res1 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: 4 })
367 expect(res1.body.total).to.equal(1)
368 expect(res1.body.data[0].name).to.equal('my super video updated')
369
370 const res2 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: 3 })
371 expect(res2.body.total).to.equal(0)
372 })
373
0e1dc3e7
C
374 it('Should have the video updated', async function () {
375 this.timeout(60000)
376
377 const res = await getVideo(server.url, videoId)
0e1dc3e7
C
378 const video = res.body
379
a20399c9 380 await completeVideoCheck(server.url, video, updateCheckAttributes)
0e1dc3e7
C
381 })
382
383 it('Should update only the tags of a video', async function () {
384 const attributes = {
a20399c9 385 tags: [ 'supertag', 'tag1', 'tag2' ]
0e1dc3e7 386 }
0e1dc3e7
C
387 await updateVideo(server.url, server.accessToken, videoId, attributes)
388
389 const res = await getVideo(server.url, videoId)
390 const video = res.body
391
a20399c9 392 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes, attributes))
0e1dc3e7
C
393 })
394
395 it('Should update only the description of a video', async function () {
396 const attributes = {
397 description: 'hello everybody'
398 }
0e1dc3e7
C
399 await updateVideo(server.url, server.accessToken, videoId, attributes)
400
401 const res = await getVideo(server.url, videoId)
402 const video = res.body
403
a20399c9 404 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes, attributes))
0e1dc3e7
C
405 })
406
407 it('Should like a video', async function () {
408 await rateVideo(server.url, server.accessToken, videoId, 'like')
409
410 const res = await getVideo(server.url, videoId)
411 const video = res.body
412
413 expect(video.likes).to.equal(1)
414 expect(video.dislikes).to.equal(0)
415 })
416
417 it('Should dislike the same video', async function () {
418 await rateVideo(server.url, server.accessToken, videoId, 'dislike')
419
420 const res = await getVideo(server.url, videoId)
421 const video = res.body
422
423 expect(video.likes).to.equal(0)
424 expect(video.dislikes).to.equal(1)
425 })
426
210feb6c 427 after(function () {
0e1dc3e7 428 killallServers([ server ])
0e1dc3e7
C
429 })
430})