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