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