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