]>
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 C |
8 | checkVideoFilesWereRemoved, |
9 | completeVideoCheck, | |
10 | flushTests, | |
11 | getVideo, | |
12 | getVideoCategories, | |
13 | getVideoLanguages, | |
14 | getVideoLicences, | |
15 | getVideoPrivacies, | |
16 | getVideosList, | |
17 | getVideosListPagination, | |
18 | getVideosListSort, | |
d525fc39 | 19 | getVideosWithFilters, |
3cd0734f C |
20 | killallServers, |
21 | rateVideo, | |
22 | removeVideo, | |
23 | runServer, | |
3cd0734f C |
24 | ServerInfo, |
25 | setAccessTokensToServers, | |
26 | testImage, | |
27 | updateVideo, | |
28 | uploadVideo, | |
29 | viewVideo, | |
30 | wait | |
a20399c9 | 31 | } from '../../utils' |
0e1dc3e7 | 32 | |
8e7f08b5 C |
33 | const expect = chai.expect |
34 | ||
9a27cdc2 | 35 | describe('Test a single server', function () { |
0e1dc3e7 C |
36 | let server: ServerInfo = null |
37 | let videoId = -1 | |
38 | let videoUUID = '' | |
39 | let videosListBase: any[] = null | |
40 | ||
a20399c9 C |
41 | const getCheckAttributes = { |
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', | |
51 | host: 'localhost:9001' | |
52 | }, | |
a20399c9 | 53 | isLocal: true, |
b1f5b93e | 54 | duration: 5, |
a20399c9 C |
55 | tags: [ 'tag1', 'tag2', 'tag3' ], |
56 | privacy: VideoPrivacy.PUBLIC, | |
47564bbe | 57 | commentsEnabled: true, |
a20399c9 C |
58 | channel: { |
59 | name: 'Default root channel', | |
b1f5b93e | 60 | description: '', |
a20399c9 C |
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, | |
9d3ef9fe | 76 | language: 'ar', |
47564bbe | 77 | nsfw: false, |
a20399c9 | 78 | description: 'my super description updated', |
2422c46b | 79 | support: 'my super support text updated', |
b64c950a C |
80 | account: { |
81 | name: 'root', | |
82 | host: 'localhost:9001' | |
83 | }, | |
a20399c9 C |
84 | isLocal: true, |
85 | tags: [ 'tagup1', 'tagup2' ], | |
86 | privacy: VideoPrivacy.PUBLIC, | |
b1f5b93e | 87 | duration: 5, |
47564bbe | 88 | commentsEnabled: false, |
a20399c9 C |
89 | channel: { |
90 | name: 'Default root channel', | |
b1f5b93e | 91 | description: '', |
a20399c9 C |
92 | isLocal: true |
93 | }, | |
94 | fixture: 'video_short3.webm', | |
95 | files: [ | |
96 | { | |
97 | resolution: 720, | |
98 | size: 292677 | |
99 | } | |
100 | ] | |
101 | } | |
102 | ||
0e1dc3e7 | 103 | before(async function () { |
e212f887 | 104 | this.timeout(30000) |
0e1dc3e7 C |
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 | ||
9d3ef9fe | 137 | expect(languages['ru']).to.equal('Russian') |
0e1dc3e7 C |
138 | }) |
139 | ||
11474c3c C |
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 | ||
0e1dc3e7 C |
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 | } | |
cadb46d8 C |
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) | |
a20399c9 C |
169 | |
170 | videoId = res.body.video.id | |
171 | videoUUID = res.body.video.uuid | |
0e1dc3e7 C |
172 | }) |
173 | ||
a20399c9 | 174 | it('Should get and seed the uploaded video', async function () { |
b5c0e955 | 175 | this.timeout(5000) |
0e1dc3e7 C |
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] | |
a20399c9 | 184 | await completeVideoCheck(server.url, video, getCheckAttributes) |
0e1dc3e7 C |
185 | }) |
186 | ||
187 | it('Should get the video by UUID', async function () { | |
b5c0e955 | 188 | this.timeout(5000) |
0e1dc3e7 C |
189 | |
190 | const res = await getVideo(server.url, videoUUID) | |
191 | ||
192 | const video = res.body | |
a20399c9 | 193 | await completeVideoCheck(server.url, video, getCheckAttributes) |
0e1dc3e7 C |
194 | }) |
195 | ||
196 | it('Should have the views updated', async function () { | |
b5c0e955 C |
197 | this.timeout(10000) |
198 | ||
199 | await viewVideo(server.url, videoId) | |
200 | await viewVideo(server.url, videoId) | |
1f3e9fec | 201 | await viewVideo(server.url, videoId) |
b5c0e955 C |
202 | |
203 | await wait(1500) | |
204 | ||
205 | await viewVideo(server.url, videoId) | |
206 | await viewVideo(server.url, videoId) | |
207 | ||
208 | await wait(1500) | |
209 | ||
1f3e9fec C |
210 | await viewVideo(server.url, videoId) |
211 | await viewVideo(server.url, videoId) | |
212 | ||
0e1dc3e7 C |
213 | const res = await getVideo(server.url, videoId) |
214 | ||
215 | const video = res.body | |
5f04dd2f | 216 | expect(video.views).to.equal(3) |
0e1dc3e7 C |
217 | }) |
218 | ||
0e1dc3e7 C |
219 | it('Should remove the video', async function () { |
220 | await removeVideo(server.url, server.accessToken, videoId) | |
221 | ||
f05a1c30 | 222 | await checkVideoFilesWereRemoved(videoUUID, 1) |
0e1dc3e7 C |
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 | ||
e11f68a3 | 241 | const tasks: Promise<any>[] = [] |
0e1dc3e7 C |
242 | for (const video of videos) { |
243 | const videoAttributes = { | |
244 | name: video + ' name', | |
245 | description: video + ' description', | |
246 | category: 2, | |
247 | licence: 1, | |
9d3ef9fe | 248 | language: 'en', |
0e1dc3e7 C |
249 | nsfw: true, |
250 | tags: [ 'tag1', 'tag2', 'tag3' ], | |
251 | fixture: video | |
252 | } | |
253 | ||
254 | const p = uploadVideo(server.url, server.accessToken, videoAttributes) | |
e11f68a3 | 255 | tasks.push(p) |
0e1dc3e7 | 256 | } |
e11f68a3 C |
257 | |
258 | await Promise.all(tasks) | |
0e1dc3e7 C |
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', '') | |
7b0956ec | 287 | await testImage(server.url, videoName, video.thumbnailPath) |
0e1dc3e7 C |
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 | ||
0e1dc3e7 C |
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') | |
0e1dc3e7 | 333 | |
d525fc39 | 334 | videoId = videos[3].uuid |
0e1dc3e7 C |
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, | |
9d3ef9fe | 342 | language: 'ar', |
0e1dc3e7 C |
343 | nsfw: false, |
344 | description: 'my super description updated', | |
47564bbe | 345 | commentsEnabled: false, |
0e1dc3e7 C |
346 | tags: [ 'tagup1', 'tagup2' ] |
347 | } | |
348 | await updateVideo(server.url, server.accessToken, videoId, attributes) | |
349 | }) | |
350 | ||
d525fc39 C |
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 | ||
0e1dc3e7 C |
360 | it('Should have the video updated', async function () { |
361 | this.timeout(60000) | |
362 | ||
363 | const res = await getVideo(server.url, videoId) | |
0e1dc3e7 C |
364 | const video = res.body |
365 | ||
a20399c9 | 366 | await completeVideoCheck(server.url, video, updateCheckAttributes) |
0e1dc3e7 C |
367 | }) |
368 | ||
369 | it('Should update only the tags of a video', async function () { | |
370 | const attributes = { | |
a20399c9 | 371 | tags: [ 'supertag', 'tag1', 'tag2' ] |
0e1dc3e7 | 372 | } |
0e1dc3e7 C |
373 | await updateVideo(server.url, server.accessToken, videoId, attributes) |
374 | ||
375 | const res = await getVideo(server.url, videoId) | |
376 | const video = res.body | |
377 | ||
a20399c9 | 378 | await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes, attributes)) |
0e1dc3e7 C |
379 | }) |
380 | ||
381 | it('Should update only the description of a video', async function () { | |
382 | const attributes = { | |
383 | description: 'hello everybody' | |
384 | } | |
0e1dc3e7 C |
385 | await updateVideo(server.url, server.accessToken, videoId, attributes) |
386 | ||
387 | const res = await getVideo(server.url, videoId) | |
388 | const video = res.body | |
389 | ||
a20399c9 | 390 | await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes, attributes)) |
0e1dc3e7 C |
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 | }) |