]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
0e1dc3e7 | 2 | |
8e7f08b5 | 3 | import * as chai from 'chai' |
0e1dc3e7 | 4 | import { keyBy } from 'lodash' |
0e1dc3e7 | 5 | import 'mocha' |
a20399c9 | 6 | import { VideoPrivacy } from '../../../../shared/models/videos' |
0e1dc3e7 | 7 | import { |
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 |
32 | const expect = chai.expect |
33 | ||
9a27cdc2 | 34 | describe('Test a single server', function () { |
0e1dc3e7 C |
35 | let server: ServerInfo = null |
36 | let videoId = -1 | |
2fd59d7d | 37 | let videoId2 = -1 |
0e1dc3e7 C |
38 | let videoUUID = '' |
39 | let videosListBase: any[] = null | |
40 | ||
48f07b4a | 41 | const getCheckAttributes = () => ({ |
a20399c9 C |
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', | |
7243f84d | 51 | host: 'localhost:' + server.port |
b64c950a | 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 | ] | |
48f07b4a | 72 | }) |
a20399c9 | 73 | |
48f07b4a | 74 | const updateCheckAttributes = () => ({ |
a20399c9 C |
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', | |
7243f84d | 84 | host: 'localhost:' + server.port |
b64c950a | 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 | ] | |
48f07b4a | 105 | }) |
a20399c9 | 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 () { | |
33ff70ba C |
160 | this.timeout(10000) |
161 | ||
0e1dc3e7 C |
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] | |
48f07b4a | 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 | |
48f07b4a | 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 | ||
2fd59d7d | 243 | const videos = new Set([ |
0e1dc3e7 C |
244 | 'video_short.mp4', 'video_short.ogv', 'video_short.webm', |
245 | 'video_short1.webm', 'video_short2.webm', 'video_short3.webm' | |
2fd59d7d | 246 | ]) |
0e1dc3e7 | 247 | |
0e1dc3e7 C |
248 | for (const video of videos) { |
249 | const videoAttributes = { | |
250 | name: video + ' name', | |
251 | description: video + ' description', | |
252 | category: 2, | |
253 | licence: 1, | |
9d3ef9fe | 254 | language: 'en', |
0e1dc3e7 C |
255 | nsfw: true, |
256 | tags: [ 'tag1', 'tag2', 'tag3' ], | |
257 | fixture: video | |
258 | } | |
259 | ||
2fd59d7d | 260 | await uploadVideo(server.url, server.accessToken, videoAttributes) |
0e1dc3e7 | 261 | } |
0e1dc3e7 C |
262 | }) |
263 | ||
264 | it('Should have the correct durations', async function () { | |
265 | const res = await getVideosList(server.url) | |
266 | ||
267 | expect(res.body.total).to.equal(6) | |
268 | const videos = res.body.data | |
269 | expect(videos).to.be.an('array') | |
270 | expect(videos).to.have.lengthOf(6) | |
271 | ||
272 | const videosByName = keyBy<{ duration: number }>(videos, 'name') | |
273 | expect(videosByName['video_short.mp4 name'].duration).to.equal(5) | |
274 | expect(videosByName['video_short.ogv name'].duration).to.equal(5) | |
275 | expect(videosByName['video_short.webm name'].duration).to.equal(5) | |
276 | expect(videosByName['video_short1.webm name'].duration).to.equal(10) | |
277 | expect(videosByName['video_short2.webm name'].duration).to.equal(5) | |
278 | expect(videosByName['video_short3.webm name'].duration).to.equal(5) | |
279 | }) | |
280 | ||
281 | it('Should have the correct thumbnails', async function () { | |
282 | const res = await getVideosList(server.url) | |
283 | ||
284 | const videos = res.body.data | |
285 | // For the next test | |
286 | videosListBase = videos | |
287 | ||
288 | for (const video of videos) { | |
289 | const videoName = video.name.replace(' name', '') | |
7b0956ec | 290 | await testImage(server.url, videoName, video.thumbnailPath) |
0e1dc3e7 C |
291 | } |
292 | }) | |
293 | ||
294 | it('Should list only the two first videos', async function () { | |
295 | const res = await getVideosListPagination(server.url, 0, 2, 'name') | |
296 | ||
297 | const videos = res.body.data | |
298 | expect(res.body.total).to.equal(6) | |
299 | expect(videos.length).to.equal(2) | |
300 | expect(videos[0].name).to.equal(videosListBase[0].name) | |
301 | expect(videos[1].name).to.equal(videosListBase[1].name) | |
302 | }) | |
303 | ||
304 | it('Should list only the next three videos', async function () { | |
305 | const res = await getVideosListPagination(server.url, 2, 3, 'name') | |
306 | ||
307 | const videos = res.body.data | |
308 | expect(res.body.total).to.equal(6) | |
309 | expect(videos.length).to.equal(3) | |
310 | expect(videos[0].name).to.equal(videosListBase[2].name) | |
311 | expect(videos[1].name).to.equal(videosListBase[3].name) | |
312 | expect(videos[2].name).to.equal(videosListBase[4].name) | |
313 | }) | |
314 | ||
315 | it('Should list the last video', async function () { | |
316 | const res = await getVideosListPagination(server.url, 5, 6, 'name') | |
317 | ||
318 | const videos = res.body.data | |
319 | expect(res.body.total).to.equal(6) | |
320 | expect(videos.length).to.equal(1) | |
321 | expect(videos[0].name).to.equal(videosListBase[5].name) | |
322 | }) | |
323 | ||
fe987656 C |
324 | it('Should not have the total field', async function () { |
325 | const res = await getVideosListPagination(server.url, 5, 6, 'name', true) | |
326 | ||
327 | const videos = res.body.data | |
328 | expect(res.body.total).to.not.exist | |
329 | expect(videos.length).to.equal(1) | |
330 | expect(videos[0].name).to.equal(videosListBase[5].name) | |
331 | }) | |
332 | ||
0e1dc3e7 C |
333 | it('Should list and sort by name in descending order', async function () { |
334 | const res = await getVideosListSort(server.url, '-name') | |
335 | ||
336 | const videos = res.body.data | |
337 | expect(res.body.total).to.equal(6) | |
338 | expect(videos.length).to.equal(6) | |
339 | expect(videos[0].name).to.equal('video_short.webm name') | |
340 | expect(videos[1].name).to.equal('video_short.ogv name') | |
341 | expect(videos[2].name).to.equal('video_short.mp4 name') | |
342 | expect(videos[3].name).to.equal('video_short3.webm name') | |
343 | expect(videos[4].name).to.equal('video_short2.webm name') | |
344 | expect(videos[5].name).to.equal('video_short1.webm name') | |
0e1dc3e7 | 345 | |
d525fc39 | 346 | videoId = videos[3].uuid |
2fd59d7d | 347 | videoId2 = videos[5].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 | ||
2fd59d7d C |
436 | it('Should sort by originallyPublishedAt', async function () { |
437 | { | |
438 | ||
439 | { | |
440 | const now = new Date() | |
441 | const attributes = { originallyPublishedAt: now.toISOString() } | |
442 | await updateVideo(server.url, server.accessToken, videoId, attributes) | |
443 | ||
444 | const res = await getVideosListSort(server.url, '-originallyPublishedAt') | |
445 | const names = res.body.data.map(v => v.name) | |
446 | ||
447 | expect(names[0]).to.equal('my super video updated') | |
448 | expect(names[1]).to.equal('video_short2.webm name') | |
449 | expect(names[2]).to.equal('video_short1.webm name') | |
450 | expect(names[3]).to.equal('video_short.webm name') | |
451 | expect(names[4]).to.equal('video_short.ogv name') | |
452 | expect(names[5]).to.equal('video_short.mp4 name') | |
453 | } | |
454 | ||
455 | { | |
456 | const now = new Date() | |
457 | const attributes = { originallyPublishedAt: now.toISOString() } | |
458 | await updateVideo(server.url, server.accessToken, videoId2, attributes) | |
459 | ||
460 | const res = await getVideosListSort(server.url, '-originallyPublishedAt') | |
461 | const names = res.body.data.map(v => v.name) | |
462 | ||
463 | expect(names[0]).to.equal('video_short1.webm name') | |
464 | expect(names[1]).to.equal('my super video updated') | |
465 | expect(names[2]).to.equal('video_short2.webm name') | |
466 | expect(names[3]).to.equal('video_short.webm name') | |
467 | expect(names[4]).to.equal('video_short.ogv name') | |
468 | expect(names[5]).to.equal('video_short.mp4 name') | |
469 | } | |
470 | } | |
471 | }) | |
472 | ||
7c3b7976 C |
473 | after(async function () { |
474 | await cleanupTests([ server ]) | |
0e1dc3e7 C |
475 | }) |
476 | }) |