]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
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 | cleanupTests, | |
10 | completeVideoCheck, | |
11 | flushAndRunServer, | |
12 | getVideo, | |
13 | getVideoCategories, | |
14 | getVideoLanguages, | |
15 | getVideoLicences, | |
16 | getVideoPrivacies, | |
17 | getVideosList, | |
18 | getVideosListPagination, | |
19 | getVideosListSort, | |
20 | getVideosWithFilters, | |
21 | rateVideo, | |
22 | removeVideo, | |
23 | ServerInfo, | |
24 | setAccessTokensToServers, | |
25 | testImage, | |
26 | updateVideo, | |
27 | uploadVideo, | |
28 | viewVideo, | |
29 | wait | |
30 | } from '../../../../shared/extra-utils' | |
31 | ||
32 | const expect = chai.expect | |
33 | ||
34 | describe('Test a single server', function () { | |
35 | let server: ServerInfo = null | |
36 | let videoId = -1 | |
37 | let videoUUID = '' | |
38 | let videosListBase: any[] = null | |
39 | ||
40 | const getCheckAttributes = () => ({ | |
41 | name: 'my super name', | |
42 | category: 2, | |
43 | licence: 6, | |
44 | language: 'zh', | |
45 | nsfw: true, | |
46 | description: 'my super description', | |
47 | support: 'my super support text', | |
48 | account: { | |
49 | name: 'root', | |
50 | host: 'localhost:' + server.port | |
51 | }, | |
52 | isLocal: true, | |
53 | duration: 5, | |
54 | tags: [ 'tag1', 'tag2', 'tag3' ], | |
55 | privacy: VideoPrivacy.PUBLIC, | |
56 | commentsEnabled: true, | |
57 | downloadEnabled: true, | |
58 | channel: { | |
59 | displayName: 'Main root channel', | |
60 | name: 'root_channel', | |
61 | description: '', | |
62 | isLocal: true | |
63 | }, | |
64 | fixture: 'video_short.webm', | |
65 | files: [ | |
66 | { | |
67 | resolution: 720, | |
68 | size: 218910 | |
69 | } | |
70 | ] | |
71 | }) | |
72 | ||
73 | const updateCheckAttributes = () => ({ | |
74 | name: 'my super video updated', | |
75 | category: 4, | |
76 | licence: 2, | |
77 | language: 'ar', | |
78 | nsfw: false, | |
79 | description: 'my super description updated', | |
80 | support: 'my super support text updated', | |
81 | account: { | |
82 | name: 'root', | |
83 | host: 'localhost:' + server.port | |
84 | }, | |
85 | isLocal: true, | |
86 | tags: [ 'tagup1', 'tagup2' ], | |
87 | privacy: VideoPrivacy.PUBLIC, | |
88 | duration: 5, | |
89 | commentsEnabled: false, | |
90 | downloadEnabled: false, | |
91 | channel: { | |
92 | name: 'root_channel', | |
93 | displayName: 'Main root channel', | |
94 | description: '', | |
95 | isLocal: true | |
96 | }, | |
97 | fixture: 'video_short3.webm', | |
98 | files: [ | |
99 | { | |
100 | resolution: 720, | |
101 | size: 292677 | |
102 | } | |
103 | ] | |
104 | }) | |
105 | ||
106 | before(async function () { | |
107 | this.timeout(30000) | |
108 | ||
109 | server = await flushAndRunServer(1) | |
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 | ||
120 | expect(categories[11]).to.equal('News & Politics') | |
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 | ||
138 | expect(languages['ru']).to.equal('Russian') | |
139 | }) | |
140 | ||
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 | ||
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 | } | |
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) | |
170 | ||
171 | videoId = res.body.video.id | |
172 | videoUUID = res.body.video.uuid | |
173 | }) | |
174 | ||
175 | it('Should get and seed the uploaded video', async function () { | |
176 | this.timeout(5000) | |
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] | |
185 | await completeVideoCheck(server.url, video, getCheckAttributes()) | |
186 | }) | |
187 | ||
188 | it('Should get the video by UUID', async function () { | |
189 | this.timeout(5000) | |
190 | ||
191 | const res = await getVideo(server.url, videoUUID) | |
192 | ||
193 | const video = res.body | |
194 | await completeVideoCheck(server.url, video, getCheckAttributes()) | |
195 | }) | |
196 | ||
197 | it('Should have the views updated', async function () { | |
198 | this.timeout(20000) | |
199 | ||
200 | await viewVideo(server.url, videoId) | |
201 | await viewVideo(server.url, videoId) | |
202 | await viewVideo(server.url, videoId) | |
203 | ||
204 | await wait(1500) | |
205 | ||
206 | await viewVideo(server.url, videoId) | |
207 | await viewVideo(server.url, videoId) | |
208 | ||
209 | await wait(1500) | |
210 | ||
211 | await viewVideo(server.url, videoId) | |
212 | await viewVideo(server.url, videoId) | |
213 | ||
214 | // Wait the repeatable job | |
215 | await wait(8000) | |
216 | ||
217 | const res = await getVideo(server.url, videoId) | |
218 | ||
219 | const video = res.body | |
220 | expect(video.views).to.equal(3) | |
221 | }) | |
222 | ||
223 | it('Should remove the video', async function () { | |
224 | await removeVideo(server.url, server.accessToken, videoId) | |
225 | ||
226 | await checkVideoFilesWereRemoved(videoUUID, 1) | |
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 | ||
245 | const tasks: Promise<any>[] = [] | |
246 | for (const video of videos) { | |
247 | const videoAttributes = { | |
248 | name: video + ' name', | |
249 | description: video + ' description', | |
250 | category: 2, | |
251 | licence: 1, | |
252 | language: 'en', | |
253 | nsfw: true, | |
254 | tags: [ 'tag1', 'tag2', 'tag3' ], | |
255 | fixture: video | |
256 | } | |
257 | ||
258 | const p = uploadVideo(server.url, server.accessToken, videoAttributes) | |
259 | tasks.push(p) | |
260 | } | |
261 | ||
262 | await Promise.all(tasks) | |
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', '') | |
291 | await testImage(server.url, videoName, video.thumbnailPath) | |
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 | ||
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 | ||
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') | |
346 | ||
347 | videoId = videos[3].uuid | |
348 | }) | |
349 | ||
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 | ||
358 | it('Should update a video', async function () { | |
359 | const attributes = { | |
360 | name: 'my super video updated', | |
361 | category: 4, | |
362 | licence: 2, | |
363 | language: 'ar', | |
364 | nsfw: false, | |
365 | description: 'my super description updated', | |
366 | commentsEnabled: false, | |
367 | downloadEnabled: false, | |
368 | tags: [ 'tagup1', 'tagup2' ] | |
369 | } | |
370 | await updateVideo(server.url, server.accessToken, videoId, attributes) | |
371 | }) | |
372 | ||
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 | ||
382 | it('Should have the video updated', async function () { | |
383 | this.timeout(60000) | |
384 | ||
385 | const res = await getVideo(server.url, videoId) | |
386 | const video = res.body | |
387 | ||
388 | await completeVideoCheck(server.url, video, updateCheckAttributes()) | |
389 | }) | |
390 | ||
391 | it('Should update only the tags of a video', async function () { | |
392 | const attributes = { | |
393 | tags: [ 'supertag', 'tag1', 'tag2' ] | |
394 | } | |
395 | await updateVideo(server.url, server.accessToken, videoId, attributes) | |
396 | ||
397 | const res = await getVideo(server.url, videoId) | |
398 | const video = res.body | |
399 | ||
400 | await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes(), attributes)) | |
401 | }) | |
402 | ||
403 | it('Should update only the description of a video', async function () { | |
404 | const attributes = { | |
405 | description: 'hello everybody' | |
406 | } | |
407 | await updateVideo(server.url, server.accessToken, videoId, attributes) | |
408 | ||
409 | const res = await getVideo(server.url, videoId) | |
410 | const video = res.body | |
411 | ||
412 | const expectedAttributes = Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes) | |
413 | await completeVideoCheck(server.url, video, expectedAttributes) | |
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 | ||
436 | after(async function () { | |
437 | await cleanupTests([ server ]) | |
438 | }) | |
439 | }) |