diff options
Diffstat (limited to 'server/tests/api/single-server.ts')
-rw-r--r-- | server/tests/api/single-server.ts | 694 |
1 files changed, 694 insertions, 0 deletions
diff --git a/server/tests/api/single-server.ts b/server/tests/api/single-server.ts new file mode 100644 index 000000000..82ecc68ee --- /dev/null +++ b/server/tests/api/single-server.ts | |||
@@ -0,0 +1,694 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import { keyBy } from 'lodash' | ||
4 | import { join } from 'path' | ||
5 | import 'mocha' | ||
6 | import * as chai from 'chai' | ||
7 | const expect = chai.expect | ||
8 | |||
9 | import { | ||
10 | ServerInfo, | ||
11 | flushTests, | ||
12 | runServer, | ||
13 | uploadVideo, | ||
14 | getVideosList, | ||
15 | rateVideo, | ||
16 | removeVideo, | ||
17 | wait, | ||
18 | setAccessTokensToServers, | ||
19 | searchVideo, | ||
20 | killallServers, | ||
21 | dateIsValid, | ||
22 | getVideoCategories, | ||
23 | getVideoLicences, | ||
24 | getVideoLanguages, | ||
25 | getVideoPrivacies, | ||
26 | testVideoImage, | ||
27 | webtorrentAdd, | ||
28 | getVideo, | ||
29 | readdirPromise, | ||
30 | getVideosListPagination, | ||
31 | searchVideoWithPagination, | ||
32 | getVideosListSort, | ||
33 | searchVideoWithSort, | ||
34 | updateVideo | ||
35 | } from '../utils' | ||
36 | |||
37 | describe('Test a single server', function () { | ||
38 | let server: ServerInfo = null | ||
39 | let videoId = -1 | ||
40 | let videoUUID = '' | ||
41 | let videosListBase: any[] = null | ||
42 | |||
43 | before(async function () { | ||
44 | this.timeout(120000) | ||
45 | |||
46 | await flushTests() | ||
47 | |||
48 | server = await runServer(1) | ||
49 | |||
50 | await setAccessTokensToServers([ server ]) | ||
51 | }) | ||
52 | |||
53 | it('Should list video categories', async function () { | ||
54 | const res = await getVideoCategories(server.url) | ||
55 | |||
56 | const categories = res.body | ||
57 | expect(Object.keys(categories)).to.have.length.above(10) | ||
58 | |||
59 | expect(categories[11]).to.equal('News') | ||
60 | }) | ||
61 | |||
62 | it('Should list video licences', async function () { | ||
63 | const res = await getVideoLicences(server.url) | ||
64 | |||
65 | const licences = res.body | ||
66 | expect(Object.keys(licences)).to.have.length.above(5) | ||
67 | |||
68 | expect(licences[3]).to.equal('Attribution - No Derivatives') | ||
69 | }) | ||
70 | |||
71 | it('Should list video languages', async function () { | ||
72 | const res = await getVideoLanguages(server.url) | ||
73 | |||
74 | const languages = res.body | ||
75 | expect(Object.keys(languages)).to.have.length.above(5) | ||
76 | |||
77 | expect(languages[3]).to.equal('Mandarin') | ||
78 | }) | ||
79 | |||
80 | it('Should list video privacies', async function () { | ||
81 | const res = await getVideoPrivacies(server.url) | ||
82 | |||
83 | const privacies = res.body | ||
84 | expect(Object.keys(privacies)).to.have.length.at.least(3) | ||
85 | |||
86 | expect(privacies[3]).to.equal('Private') | ||
87 | }) | ||
88 | |||
89 | it('Should not have videos', async function () { | ||
90 | const res = await getVideosList(server.url) | ||
91 | |||
92 | expect(res.body.total).to.equal(0) | ||
93 | expect(res.body.data).to.be.an('array') | ||
94 | expect(res.body.data.length).to.equal(0) | ||
95 | }) | ||
96 | |||
97 | it('Should upload the video', async function () { | ||
98 | const videoAttributes = { | ||
99 | name: 'my super name', | ||
100 | category: 2, | ||
101 | nsfw: true, | ||
102 | licence: 6, | ||
103 | tags: [ 'tag1', 'tag2', 'tag3' ] | ||
104 | } | ||
105 | await uploadVideo(server.url, server.accessToken, videoAttributes) | ||
106 | }) | ||
107 | |||
108 | it('Should seed the uploaded video', async function () { | ||
109 | // Yes, this could be long | ||
110 | this.timeout(60000) | ||
111 | |||
112 | const res = await getVideosList(server.url) | ||
113 | |||
114 | expect(res.body.total).to.equal(1) | ||
115 | expect(res.body.data).to.be.an('array') | ||
116 | expect(res.body.data.length).to.equal(1) | ||
117 | |||
118 | const video = res.body.data[0] | ||
119 | expect(video.name).to.equal('my super name') | ||
120 | expect(video.category).to.equal(2) | ||
121 | expect(video.categoryLabel).to.equal('Films') | ||
122 | expect(video.licence).to.equal(6) | ||
123 | expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | ||
124 | expect(video.language).to.equal(3) | ||
125 | expect(video.languageLabel).to.equal('Mandarin') | ||
126 | expect(video.nsfw).to.be.ok | ||
127 | expect(video.description).to.equal('my super description') | ||
128 | expect(video.serverHost).to.equal('localhost:9001') | ||
129 | expect(video.account).to.equal('root') | ||
130 | expect(video.isLocal).to.be.true | ||
131 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | ||
132 | expect(dateIsValid(video.createdAt)).to.be.true | ||
133 | expect(dateIsValid(video.updatedAt)).to.be.true | ||
134 | |||
135 | const res2 = await getVideo(server.url, res.body.data[0].id) | ||
136 | const videoDetails = res2.body | ||
137 | |||
138 | expect(videoDetails.files).to.have.lengthOf(1) | ||
139 | |||
140 | const file = videoDetails.files[0] | ||
141 | const magnetUri = file.magnetUri | ||
142 | expect(file.magnetUri).to.have.lengthOf.above(2) | ||
143 | expect(file.torrentUrl).to.equal(`${server.url}/static/torrents/${videoDetails.uuid}-${file.resolution}.torrent`) | ||
144 | expect(file.fileUrl).to.equal(`${server.url}/static/webseed/${videoDetails.uuid}-${file.resolution}.webm`) | ||
145 | expect(file.resolution).to.equal(720) | ||
146 | expect(file.resolutionLabel).to.equal('720p') | ||
147 | expect(file.size).to.equal(218910) | ||
148 | |||
149 | const test = await testVideoImage(server.url, 'video_short.webm', videoDetails.thumbnailPath) | ||
150 | expect(test).to.equal(true) | ||
151 | |||
152 | videoId = videoDetails.id | ||
153 | videoUUID = videoDetails.uuid | ||
154 | |||
155 | const torrent = await webtorrentAdd(magnetUri) | ||
156 | expect(torrent.files).to.be.an('array') | ||
157 | expect(torrent.files.length).to.equal(1) | ||
158 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
159 | }) | ||
160 | |||
161 | it('Should get the video', async function () { | ||
162 | // Yes, this could be long | ||
163 | this.timeout(60000) | ||
164 | |||
165 | const res = await getVideo(server.url, videoId) | ||
166 | |||
167 | const video = res.body | ||
168 | expect(video.name).to.equal('my super name') | ||
169 | expect(video.category).to.equal(2) | ||
170 | expect(video.categoryLabel).to.equal('Films') | ||
171 | expect(video.licence).to.equal(6) | ||
172 | expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | ||
173 | expect(video.language).to.equal(3) | ||
174 | expect(video.languageLabel).to.equal('Mandarin') | ||
175 | expect(video.nsfw).to.be.ok | ||
176 | expect(video.description).to.equal('my super description') | ||
177 | expect(video.serverHost).to.equal('localhost:9001') | ||
178 | expect(video.account).to.equal('root') | ||
179 | expect(video.isLocal).to.be.true | ||
180 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | ||
181 | expect(dateIsValid(video.createdAt)).to.be.true | ||
182 | expect(dateIsValid(video.updatedAt)).to.be.true | ||
183 | expect(video.channel.name).to.equal('Default root channel') | ||
184 | expect(video.channel.isLocal).to.be.true | ||
185 | expect(dateIsValid(video.channel.createdAt)).to.be.true | ||
186 | expect(dateIsValid(video.channel.updatedAt)).to.be.true | ||
187 | |||
188 | expect(video.files).to.have.lengthOf(1) | ||
189 | |||
190 | const file = video.files[0] | ||
191 | expect(file.magnetUri).to.have.lengthOf.above(2) | ||
192 | expect(file.resolution).to.equal(720) | ||
193 | expect(file.resolutionLabel).to.equal('720p') | ||
194 | expect(file.size).to.equal(218910) | ||
195 | |||
196 | const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath) | ||
197 | expect(test).to.equal(true) | ||
198 | |||
199 | // Wait the async views increment | ||
200 | await wait(500) | ||
201 | }) | ||
202 | |||
203 | it('Should get the video by UUID', async function () { | ||
204 | // Yes, this could be long | ||
205 | this.timeout(60000) | ||
206 | |||
207 | const res = await getVideo(server.url, videoUUID) | ||
208 | |||
209 | const video = res.body | ||
210 | expect(video.name).to.equal('my super name') | ||
211 | |||
212 | // Wait the async views increment | ||
213 | await wait(500) | ||
214 | }) | ||
215 | |||
216 | it('Should have the views updated', async function () { | ||
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 search the video by name by default', async function () { | ||
224 | const res = await searchVideo(server.url, 'my') | ||
225 | |||
226 | expect(res.body.total).to.equal(1) | ||
227 | expect(res.body.data).to.be.an('array') | ||
228 | expect(res.body.data.length).to.equal(1) | ||
229 | |||
230 | const video = res.body.data[0] | ||
231 | expect(video.name).to.equal('my super name') | ||
232 | expect(video.category).to.equal(2) | ||
233 | expect(video.categoryLabel).to.equal('Films') | ||
234 | expect(video.licence).to.equal(6) | ||
235 | expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | ||
236 | expect(video.language).to.equal(3) | ||
237 | expect(video.languageLabel).to.equal('Mandarin') | ||
238 | expect(video.nsfw).to.be.ok | ||
239 | expect(video.description).to.equal('my super description') | ||
240 | expect(video.serverHost).to.equal('localhost:9001') | ||
241 | expect(video.account).to.equal('root') | ||
242 | expect(video.isLocal).to.be.true | ||
243 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | ||
244 | expect(dateIsValid(video.createdAt)).to.be.true | ||
245 | expect(dateIsValid(video.updatedAt)).to.be.true | ||
246 | |||
247 | const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath) | ||
248 | expect(test).to.equal(true) | ||
249 | }) | ||
250 | |||
251 | // Not implemented yet | ||
252 | // it('Should search the video by serverHost', async function () { | ||
253 | // const res = await videosUtils.searchVideo(server.url, '9001', 'host') | ||
254 | |||
255 | // expect(res.body.total).to.equal(1) | ||
256 | // expect(res.body.data).to.be.an('array') | ||
257 | // expect(res.body.data.length).to.equal(1) | ||
258 | |||
259 | // const video = res.body.data[0] | ||
260 | // expect(video.name).to.equal('my super name') | ||
261 | // expect(video.description).to.equal('my super description') | ||
262 | // expect(video.serverHost).to.equal('localhost:9001') | ||
263 | // expect(video.author).to.equal('root') | ||
264 | // expect(video.isLocal).to.be.true | ||
265 | // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | ||
266 | // expect(dateIsValid(video.createdAt)).to.be.true | ||
267 | // expect(dateIsValid(video.updatedAt)).to.be.true | ||
268 | |||
269 | // const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath) | ||
270 | // expect(test).to.equal(true) | ||
271 | |||
272 | // done() | ||
273 | // }) | ||
274 | // }) | ||
275 | // }) | ||
276 | |||
277 | it('Should search the video by tag', async function () { | ||
278 | const res = await searchVideo(server.url, 'tag1', 'tags') | ||
279 | |||
280 | expect(res.body.total).to.equal(1) | ||
281 | expect(res.body.data).to.be.an('array') | ||
282 | expect(res.body.data.length).to.equal(1) | ||
283 | |||
284 | const video = res.body.data[0] | ||
285 | expect(video.name).to.equal('my super name') | ||
286 | expect(video.category).to.equal(2) | ||
287 | expect(video.categoryLabel).to.equal('Films') | ||
288 | expect(video.licence).to.equal(6) | ||
289 | expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | ||
290 | expect(video.language).to.equal(3) | ||
291 | expect(video.languageLabel).to.equal('Mandarin') | ||
292 | expect(video.nsfw).to.be.ok | ||
293 | expect(video.description).to.equal('my super description') | ||
294 | expect(video.serverHost).to.equal('localhost:9001') | ||
295 | expect(video.account).to.equal('root') | ||
296 | expect(video.isLocal).to.be.true | ||
297 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | ||
298 | expect(dateIsValid(video.createdAt)).to.be.true | ||
299 | expect(dateIsValid(video.updatedAt)).to.be.true | ||
300 | |||
301 | const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath) | ||
302 | expect(test).to.equal(true) | ||
303 | }) | ||
304 | |||
305 | it('Should not find a search by name by default', async function () { | ||
306 | const res = await searchVideo(server.url, 'hello') | ||
307 | |||
308 | expect(res.body.total).to.equal(0) | ||
309 | expect(res.body.data).to.be.an('array') | ||
310 | expect(res.body.data.length).to.equal(0) | ||
311 | }) | ||
312 | |||
313 | it('Should not find a search by author', async function () { | ||
314 | const res = await searchVideo(server.url, 'hello', 'account') | ||
315 | |||
316 | expect(res.body.total).to.equal(0) | ||
317 | expect(res.body.data).to.be.an('array') | ||
318 | expect(res.body.data.length).to.equal(0) | ||
319 | }) | ||
320 | |||
321 | it('Should not find a search by tag', async function () { | ||
322 | const res = await searchVideo(server.url, 'hello', 'tags') | ||
323 | |||
324 | expect(res.body.total).to.equal(0) | ||
325 | expect(res.body.data).to.be.an('array') | ||
326 | expect(res.body.data.length).to.equal(0) | ||
327 | }) | ||
328 | |||
329 | it('Should remove the video', async function () { | ||
330 | await removeVideo(server.url, server.accessToken, videoId) | ||
331 | |||
332 | const files1 = await readdirPromise(join(__dirname, '..', '..', '..', 'test1/videos/')) | ||
333 | expect(files1).to.have.lengthOf(0) | ||
334 | |||
335 | const files2 = await readdirPromise(join(__dirname, '..', '..', '..', 'test1/thumbnails/')) | ||
336 | expect(files2).to.have.lengthOf(0) | ||
337 | }) | ||
338 | |||
339 | it('Should not have videos', async function () { | ||
340 | const res = await getVideosList(server.url) | ||
341 | |||
342 | expect(res.body.total).to.equal(0) | ||
343 | expect(res.body.data).to.be.an('array') | ||
344 | expect(res.body.data).to.have.lengthOf(0) | ||
345 | }) | ||
346 | |||
347 | it('Should upload 6 videos', async function () { | ||
348 | this.timeout(25000) | ||
349 | |||
350 | const videos = [ | ||
351 | 'video_short.mp4', 'video_short.ogv', 'video_short.webm', | ||
352 | 'video_short1.webm', 'video_short2.webm', 'video_short3.webm' | ||
353 | ] | ||
354 | |||
355 | // const tasks: Promise<any>[] = [] | ||
356 | for (const video of videos) { | ||
357 | const videoAttributes = { | ||
358 | name: video + ' name', | ||
359 | description: video + ' description', | ||
360 | category: 2, | ||
361 | licence: 1, | ||
362 | language: 1, | ||
363 | nsfw: true, | ||
364 | tags: [ 'tag1', 'tag2', 'tag3' ], | ||
365 | fixture: video | ||
366 | } | ||
367 | |||
368 | const p = uploadVideo(server.url, server.accessToken, videoAttributes) | ||
369 | await p | ||
370 | } | ||
371 | // FIXME: concurrent uploads does not work :( | ||
372 | // tasks.push(p) | ||
373 | // } | ||
374 | // | ||
375 | // await Promise.all(tasks) | ||
376 | }) | ||
377 | |||
378 | it('Should have the correct durations', async function () { | ||
379 | const res = await getVideosList(server.url) | ||
380 | |||
381 | expect(res.body.total).to.equal(6) | ||
382 | const videos = res.body.data | ||
383 | expect(videos).to.be.an('array') | ||
384 | expect(videos).to.have.lengthOf(6) | ||
385 | |||
386 | const videosByName = keyBy<{ duration: number }>(videos, 'name') | ||
387 | expect(videosByName['video_short.mp4 name'].duration).to.equal(5) | ||
388 | expect(videosByName['video_short.ogv name'].duration).to.equal(5) | ||
389 | expect(videosByName['video_short.webm name'].duration).to.equal(5) | ||
390 | expect(videosByName['video_short1.webm name'].duration).to.equal(10) | ||
391 | expect(videosByName['video_short2.webm name'].duration).to.equal(5) | ||
392 | expect(videosByName['video_short3.webm name'].duration).to.equal(5) | ||
393 | }) | ||
394 | |||
395 | it('Should have the correct thumbnails', async function () { | ||
396 | const res = await getVideosList(server.url) | ||
397 | |||
398 | const videos = res.body.data | ||
399 | // For the next test | ||
400 | videosListBase = videos | ||
401 | |||
402 | for (const video of videos) { | ||
403 | const videoName = video.name.replace(' name', '') | ||
404 | const test = await testVideoImage(server.url, videoName, video.thumbnailPath) | ||
405 | |||
406 | expect(test).to.equal(true) | ||
407 | } | ||
408 | }) | ||
409 | |||
410 | it('Should list only the two first videos', async function () { | ||
411 | const res = await getVideosListPagination(server.url, 0, 2, 'name') | ||
412 | |||
413 | const videos = res.body.data | ||
414 | expect(res.body.total).to.equal(6) | ||
415 | expect(videos.length).to.equal(2) | ||
416 | expect(videos[0].name).to.equal(videosListBase[0].name) | ||
417 | expect(videos[1].name).to.equal(videosListBase[1].name) | ||
418 | }) | ||
419 | |||
420 | it('Should list only the next three videos', async function () { | ||
421 | const res = await getVideosListPagination(server.url, 2, 3, 'name') | ||
422 | |||
423 | const videos = res.body.data | ||
424 | expect(res.body.total).to.equal(6) | ||
425 | expect(videos.length).to.equal(3) | ||
426 | expect(videos[0].name).to.equal(videosListBase[2].name) | ||
427 | expect(videos[1].name).to.equal(videosListBase[3].name) | ||
428 | expect(videos[2].name).to.equal(videosListBase[4].name) | ||
429 | }) | ||
430 | |||
431 | it('Should list the last video', async function () { | ||
432 | const res = await getVideosListPagination(server.url, 5, 6, 'name') | ||
433 | |||
434 | const videos = res.body.data | ||
435 | expect(res.body.total).to.equal(6) | ||
436 | expect(videos.length).to.equal(1) | ||
437 | expect(videos[0].name).to.equal(videosListBase[5].name) | ||
438 | }) | ||
439 | |||
440 | it('Should search the first video', async function () { | ||
441 | const res = await searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, 'name') | ||
442 | |||
443 | const videos = res.body.data | ||
444 | expect(res.body.total).to.equal(4) | ||
445 | expect(videos.length).to.equal(1) | ||
446 | expect(videos[0].name).to.equal('video_short1.webm name') | ||
447 | }) | ||
448 | |||
449 | it('Should search the last two videos', async function () { | ||
450 | const res = await searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, 'name') | ||
451 | |||
452 | const videos = res.body.data | ||
453 | expect(res.body.total).to.equal(4) | ||
454 | expect(videos.length).to.equal(2) | ||
455 | expect(videos[0].name).to.equal('video_short3.webm name') | ||
456 | expect(videos[1].name).to.equal('video_short.webm name') | ||
457 | }) | ||
458 | |||
459 | it('Should search all the webm videos', async function () { | ||
460 | const res = await searchVideoWithPagination(server.url, 'webm', 'name', 0, 15) | ||
461 | |||
462 | const videos = res.body.data | ||
463 | expect(res.body.total).to.equal(4) | ||
464 | expect(videos.length).to.equal(4) | ||
465 | }) | ||
466 | |||
467 | it('Should search all the root author videos', async function () { | ||
468 | const res = await searchVideoWithPagination(server.url, 'root', 'account', 0, 15) | ||
469 | |||
470 | const videos = res.body.data | ||
471 | expect(res.body.total).to.equal(6) | ||
472 | expect(videos.length).to.equal(6) | ||
473 | }) | ||
474 | |||
475 | // Not implemented yet | ||
476 | // it('Should search all the 9001 port videos', async function () { | ||
477 | // const res = await videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15) | ||
478 | |||
479 | // const videos = res.body.data | ||
480 | // expect(res.body.total).to.equal(6) | ||
481 | // expect(videos.length).to.equal(6) | ||
482 | |||
483 | // done() | ||
484 | // }) | ||
485 | // }) | ||
486 | |||
487 | // it('Should search all the localhost videos', async function () { | ||
488 | // const res = await videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15) | ||
489 | |||
490 | // const videos = res.body.data | ||
491 | // expect(res.body.total).to.equal(6) | ||
492 | // expect(videos.length).to.equal(6) | ||
493 | |||
494 | // done() | ||
495 | // }) | ||
496 | // }) | ||
497 | |||
498 | it('Should list and sort by name in descending order', async function () { | ||
499 | const res = await getVideosListSort(server.url, '-name') | ||
500 | |||
501 | const videos = res.body.data | ||
502 | expect(res.body.total).to.equal(6) | ||
503 | expect(videos.length).to.equal(6) | ||
504 | expect(videos[0].name).to.equal('video_short.webm name') | ||
505 | expect(videos[1].name).to.equal('video_short.ogv name') | ||
506 | expect(videos[2].name).to.equal('video_short.mp4 name') | ||
507 | expect(videos[3].name).to.equal('video_short3.webm name') | ||
508 | expect(videos[4].name).to.equal('video_short2.webm name') | ||
509 | expect(videos[5].name).to.equal('video_short1.webm name') | ||
510 | }) | ||
511 | |||
512 | it('Should search and sort by name in ascending order', async function () { | ||
513 | const res = await searchVideoWithSort(server.url, 'webm', 'name') | ||
514 | |||
515 | const videos = res.body.data | ||
516 | expect(res.body.total).to.equal(4) | ||
517 | expect(videos.length).to.equal(4) | ||
518 | |||
519 | expect(videos[0].name).to.equal('video_short1.webm name') | ||
520 | expect(videos[1].name).to.equal('video_short2.webm name') | ||
521 | expect(videos[2].name).to.equal('video_short3.webm name') | ||
522 | expect(videos[3].name).to.equal('video_short.webm name') | ||
523 | |||
524 | videoId = videos[2].id | ||
525 | }) | ||
526 | |||
527 | it('Should update a video', async function () { | ||
528 | const attributes = { | ||
529 | name: 'my super video updated', | ||
530 | category: 4, | ||
531 | licence: 2, | ||
532 | language: 5, | ||
533 | nsfw: false, | ||
534 | description: 'my super description updated', | ||
535 | tags: [ 'tagup1', 'tagup2' ] | ||
536 | } | ||
537 | await updateVideo(server.url, server.accessToken, videoId, attributes) | ||
538 | }) | ||
539 | |||
540 | it('Should have the video updated', async function () { | ||
541 | this.timeout(60000) | ||
542 | |||
543 | const res = await getVideo(server.url, videoId) | ||
544 | |||
545 | const video = res.body | ||
546 | |||
547 | expect(video.name).to.equal('my super video updated') | ||
548 | expect(video.category).to.equal(4) | ||
549 | expect(video.categoryLabel).to.equal('Art') | ||
550 | expect(video.licence).to.equal(2) | ||
551 | expect(video.licenceLabel).to.equal('Attribution - Share Alike') | ||
552 | expect(video.language).to.equal(5) | ||
553 | expect(video.languageLabel).to.equal('Arabic') | ||
554 | expect(video.nsfw).to.be.ok | ||
555 | expect(video.description).to.equal('my super description updated') | ||
556 | expect(video.serverHost).to.equal('localhost:9001') | ||
557 | expect(video.account).to.equal('root') | ||
558 | expect(video.isLocal).to.be.true | ||
559 | expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ]) | ||
560 | expect(dateIsValid(video.createdAt)).to.be.true | ||
561 | expect(dateIsValid(video.updatedAt)).to.be.true | ||
562 | |||
563 | expect(video.channel.name).to.equal('Default root channel') | ||
564 | expect(video.channel.isLocal).to.be.true | ||
565 | expect(dateIsValid(video.channel.createdAt)).to.be.true | ||
566 | expect(dateIsValid(video.channel.updatedAt)).to.be.true | ||
567 | |||
568 | expect(video.files).to.have.lengthOf(1) | ||
569 | |||
570 | const file = video.files[0] | ||
571 | const magnetUri = file.magnetUri | ||
572 | expect(file.magnetUri).to.have.lengthOf.above(2) | ||
573 | expect(file.resolution).to.equal(720) | ||
574 | expect(file.resolutionLabel).to.equal('720p') | ||
575 | expect(file.size).to.equal(292677) | ||
576 | |||
577 | const test = await testVideoImage(server.url, 'video_short3.webm', video.thumbnailPath) | ||
578 | expect(test).to.equal(true) | ||
579 | |||
580 | const torrent = await webtorrentAdd(magnetUri) | ||
581 | expect(torrent.files).to.be.an('array') | ||
582 | expect(torrent.files.length).to.equal(1) | ||
583 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | ||
584 | }) | ||
585 | |||
586 | it('Should update only the tags of a video', async function () { | ||
587 | const attributes = { | ||
588 | tags: [ 'tag1', 'tag2', 'supertag' ] | ||
589 | } | ||
590 | |||
591 | await updateVideo(server.url, server.accessToken, videoId, attributes) | ||
592 | |||
593 | const res = await getVideo(server.url, videoId) | ||
594 | const video = res.body | ||
595 | |||
596 | expect(video.name).to.equal('my super video updated') | ||
597 | expect(video.category).to.equal(4) | ||
598 | expect(video.categoryLabel).to.equal('Art') | ||
599 | expect(video.licence).to.equal(2) | ||
600 | expect(video.licenceLabel).to.equal('Attribution - Share Alike') | ||
601 | expect(video.language).to.equal(5) | ||
602 | expect(video.languageLabel).to.equal('Arabic') | ||
603 | expect(video.nsfw).to.be.ok | ||
604 | expect(video.description).to.equal('my super description updated') | ||
605 | expect(video.serverHost).to.equal('localhost:9001') | ||
606 | expect(video.account).to.equal('root') | ||
607 | expect(video.isLocal).to.be.true | ||
608 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ]) | ||
609 | expect(dateIsValid(video.createdAt)).to.be.true | ||
610 | expect(dateIsValid(video.updatedAt)).to.be.true | ||
611 | |||
612 | expect(video.channel.name).to.equal('Default root channel') | ||
613 | expect(video.channel.isLocal).to.be.true | ||
614 | expect(dateIsValid(video.channel.createdAt)).to.be.true | ||
615 | expect(dateIsValid(video.channel.updatedAt)).to.be.true | ||
616 | |||
617 | expect(video.files).to.have.lengthOf(1) | ||
618 | |||
619 | const file = video.files[0] | ||
620 | expect(file.magnetUri).to.have.lengthOf.above(2) | ||
621 | expect(file.resolution).to.equal(720) | ||
622 | expect(file.resolutionLabel).to.equal('720p') | ||
623 | expect(file.size).to.equal(292677) | ||
624 | }) | ||
625 | |||
626 | it('Should update only the description of a video', async function () { | ||
627 | const attributes = { | ||
628 | description: 'hello everybody' | ||
629 | } | ||
630 | |||
631 | await updateVideo(server.url, server.accessToken, videoId, attributes) | ||
632 | |||
633 | const res = await getVideo(server.url, videoId) | ||
634 | const video = res.body | ||
635 | |||
636 | expect(video.name).to.equal('my super video updated') | ||
637 | expect(video.category).to.equal(4) | ||
638 | expect(video.categoryLabel).to.equal('Art') | ||
639 | expect(video.licence).to.equal(2) | ||
640 | expect(video.licenceLabel).to.equal('Attribution - Share Alike') | ||
641 | expect(video.language).to.equal(5) | ||
642 | expect(video.languageLabel).to.equal('Arabic') | ||
643 | expect(video.nsfw).to.be.ok | ||
644 | expect(video.description).to.equal('hello everybody') | ||
645 | expect(video.serverHost).to.equal('localhost:9001') | ||
646 | expect(video.account).to.equal('root') | ||
647 | expect(video.isLocal).to.be.true | ||
648 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ]) | ||
649 | expect(dateIsValid(video.createdAt)).to.be.true | ||
650 | expect(dateIsValid(video.updatedAt)).to.be.true | ||
651 | |||
652 | expect(video.channel.name).to.equal('Default root channel') | ||
653 | expect(video.channel.isLocal).to.be.true | ||
654 | expect(dateIsValid(video.channel.createdAt)).to.be.true | ||
655 | expect(dateIsValid(video.channel.updatedAt)).to.be.true | ||
656 | |||
657 | expect(video.files).to.have.lengthOf(1) | ||
658 | |||
659 | const file = video.files[0] | ||
660 | expect(file.magnetUri).to.have.lengthOf.above(2) | ||
661 | expect(file.resolution).to.equal(720) | ||
662 | expect(file.resolutionLabel).to.equal('720p') | ||
663 | expect(file.size).to.equal(292677) | ||
664 | }) | ||
665 | |||
666 | it('Should like a video', async function () { | ||
667 | await rateVideo(server.url, server.accessToken, videoId, 'like') | ||
668 | |||
669 | const res = await getVideo(server.url, videoId) | ||
670 | const video = res.body | ||
671 | |||
672 | expect(video.likes).to.equal(1) | ||
673 | expect(video.dislikes).to.equal(0) | ||
674 | }) | ||
675 | |||
676 | it('Should dislike the same video', async function () { | ||
677 | await rateVideo(server.url, server.accessToken, videoId, 'dislike') | ||
678 | |||
679 | const res = await getVideo(server.url, videoId) | ||
680 | const video = res.body | ||
681 | |||
682 | expect(video.likes).to.equal(0) | ||
683 | expect(video.dislikes).to.equal(1) | ||
684 | }) | ||
685 | |||
686 | after(async function () { | ||
687 | killallServers([ server ]) | ||
688 | |||
689 | // Keep the logs if the test failed | ||
690 | if (this['ok']) { | ||
691 | await flushTests() | ||
692 | } | ||
693 | }) | ||
694 | }) | ||