]>
Commit | Line | Data |
---|---|---|
0e1dc3e7 C |
1 | /* tslint:disable:no-unused-expression */ |
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 | |
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 | ||
0e1dc3e7 C |
325 | it('Should list and sort by name in descending order', async function () { |
326 | const res = await getVideosListSort(server.url, '-name') | |
327 | ||
328 | const videos = res.body.data | |
329 | expect(res.body.total).to.equal(6) | |
330 | expect(videos.length).to.equal(6) | |
331 | expect(videos[0].name).to.equal('video_short.webm name') | |
332 | expect(videos[1].name).to.equal('video_short.ogv name') | |
333 | expect(videos[2].name).to.equal('video_short.mp4 name') | |
334 | expect(videos[3].name).to.equal('video_short3.webm name') | |
335 | expect(videos[4].name).to.equal('video_short2.webm name') | |
336 | expect(videos[5].name).to.equal('video_short1.webm name') | |
0e1dc3e7 | 337 | |
d525fc39 | 338 | videoId = videos[3].uuid |
0e1dc3e7 C |
339 | }) |
340 | ||
0b74c74a C |
341 | it('Should list and sort by trending in descending order', async function () { |
342 | const res = await getVideosListPagination(server.url, 0, 2, '-trending') | |
343 | ||
344 | const videos = res.body.data | |
345 | expect(res.body.total).to.equal(6) | |
346 | expect(videos.length).to.equal(2) | |
347 | }) | |
348 | ||
0e1dc3e7 C |
349 | it('Should update a video', async function () { |
350 | const attributes = { | |
351 | name: 'my super video updated', | |
352 | category: 4, | |
353 | licence: 2, | |
9d3ef9fe | 354 | language: 'ar', |
0e1dc3e7 C |
355 | nsfw: false, |
356 | description: 'my super description updated', | |
47564bbe | 357 | commentsEnabled: false, |
7f2cfe3a | 358 | downloadEnabled: false, |
0e1dc3e7 C |
359 | tags: [ 'tagup1', 'tagup2' ] |
360 | } | |
361 | await updateVideo(server.url, server.accessToken, videoId, attributes) | |
362 | }) | |
363 | ||
d525fc39 C |
364 | it('Should filter by tags and category', async function () { |
365 | const res1 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: 4 }) | |
366 | expect(res1.body.total).to.equal(1) | |
367 | expect(res1.body.data[0].name).to.equal('my super video updated') | |
368 | ||
369 | const res2 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: 3 }) | |
370 | expect(res2.body.total).to.equal(0) | |
371 | }) | |
372 | ||
0e1dc3e7 C |
373 | it('Should have the video updated', async function () { |
374 | this.timeout(60000) | |
375 | ||
376 | const res = await getVideo(server.url, videoId) | |
0e1dc3e7 C |
377 | const video = res.body |
378 | ||
48f07b4a | 379 | await completeVideoCheck(server.url, video, updateCheckAttributes()) |
0e1dc3e7 C |
380 | }) |
381 | ||
382 | it('Should update only the tags of a video', async function () { | |
383 | const attributes = { | |
a20399c9 | 384 | tags: [ 'supertag', 'tag1', 'tag2' ] |
0e1dc3e7 | 385 | } |
0e1dc3e7 C |
386 | await updateVideo(server.url, server.accessToken, videoId, attributes) |
387 | ||
388 | const res = await getVideo(server.url, videoId) | |
389 | const video = res.body | |
390 | ||
48f07b4a | 391 | await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes(), attributes)) |
0e1dc3e7 C |
392 | }) |
393 | ||
394 | it('Should update only the description of a video', async function () { | |
395 | const attributes = { | |
396 | description: 'hello everybody' | |
397 | } | |
0e1dc3e7 C |
398 | await updateVideo(server.url, server.accessToken, videoId, attributes) |
399 | ||
400 | const res = await getVideo(server.url, videoId) | |
401 | const video = res.body | |
402 | ||
48f07b4a C |
403 | const expectedAttributes = Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes) |
404 | await completeVideoCheck(server.url, video, expectedAttributes) | |
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 | ||
7c3b7976 C |
427 | after(async function () { |
428 | await cleanupTests([ server ]) | |
0e1dc3e7 C |
429 | }) |
430 | }) |