]>
Commit | Line | Data |
---|---|---|
72329aaa C |
1 | /* eslint-disable no-unused-expressions */ |
2 | ||
9f10b292 C |
3 | 'use strict' |
4 | ||
f0f5567b | 5 | const chai = require('chai') |
1a42c9e2 | 6 | const each = require('async/each') |
f0f5567b C |
7 | const expect = chai.expect |
8 | const fs = require('fs') | |
3a8a8b51 | 9 | const keyBy = require('lodash/keyBy') |
f0f5567b | 10 | const pathUtils = require('path') |
1a42c9e2 | 11 | const series = require('async/series') |
bf94b6f0 | 12 | const webtorrent = new (require('webtorrent'))() |
9f10b292 | 13 | |
8d309058 C |
14 | const loginUtils = require('../utils/login') |
15 | const miscsUtils = require('../utils/miscs') | |
16 | const serversUtils = require('../utils/servers') | |
17 | const videosUtils = require('../utils/videos') | |
9f10b292 | 18 | |
9f10b292 | 19 | describe('Test a single pod', function () { |
0c1cbbfe | 20 | let server = null |
bc503c2a | 21 | let videoId = -1 |
fbf1134e | 22 | let videosListBase = null |
9f10b292 C |
23 | |
24 | before(function (done) { | |
5fe7e898 | 25 | this.timeout(120000) |
9f10b292 | 26 | |
1a42c9e2 | 27 | series([ |
9f10b292 | 28 | function (next) { |
8d309058 | 29 | serversUtils.flushTests(next) |
9f10b292 C |
30 | }, |
31 | function (next) { | |
8d309058 | 32 | serversUtils.runServer(1, function (server1) { |
0c1cbbfe C |
33 | server = server1 |
34 | next() | |
35 | }) | |
36 | }, | |
37 | function (next) { | |
8d309058 | 38 | loginUtils.loginAndGetAccessToken(server, function (err, token) { |
0c1cbbfe | 39 | if (err) throw err |
b6c6f935 | 40 | server.accessToken = token |
9f10b292 C |
41 | next() |
42 | }) | |
9f10b292 C |
43 | } |
44 | ], done) | |
45 | }) | |
8c308c2b | 46 | |
6e07c3de C |
47 | it('Should list video categories', function (done) { |
48 | videosUtils.getVideoCategories(server.url, function (err, res) { | |
49 | if (err) throw err | |
50 | ||
51 | const categories = res.body | |
52 | expect(Object.keys(categories)).to.have.length.above(10) | |
53 | ||
54 | expect(categories[11]).to.equal('News') | |
55 | ||
56 | done() | |
57 | }) | |
58 | }) | |
59 | ||
6f0c39e2 C |
60 | it('Should list video licences', function (done) { |
61 | videosUtils.getVideoLicences(server.url, function (err, res) { | |
62 | if (err) throw err | |
63 | ||
64 | const licences = res.body | |
65 | expect(Object.keys(licences)).to.have.length.above(5) | |
66 | ||
67 | expect(licences[3]).to.equal('Attribution - No Derivatives') | |
68 | ||
69 | done() | |
70 | }) | |
71 | }) | |
72 | ||
3092476e C |
73 | it('Should list video languages', function (done) { |
74 | videosUtils.getVideoLanguages(server.url, function (err, res) { | |
75 | if (err) throw err | |
76 | ||
77 | const languages = res.body | |
78 | expect(Object.keys(languages)).to.have.length.above(5) | |
79 | ||
80 | expect(languages[3]).to.equal('Mandarin') | |
81 | ||
82 | done() | |
83 | }) | |
84 | }) | |
85 | ||
9f10b292 | 86 | it('Should not have videos', function (done) { |
8d309058 | 87 | videosUtils.getVideosList(server.url, function (err, res) { |
9f10b292 | 88 | if (err) throw err |
8c308c2b | 89 | |
68ce3ae0 C |
90 | expect(res.body.total).to.equal(0) |
91 | expect(res.body.data).to.be.an('array') | |
92 | expect(res.body.data.length).to.equal(0) | |
8c308c2b | 93 | |
9f10b292 | 94 | done() |
8c308c2b | 95 | }) |
9f10b292 | 96 | }) |
8c308c2b | 97 | |
9f10b292 | 98 | it('Should upload the video', function (done) { |
b4c5ac97 C |
99 | const videoAttributes = { |
100 | name: 'my super name', | |
101 | category: 2, | |
31b59b47 | 102 | nsfw: true, |
6f0c39e2 | 103 | licence: 6, |
b4c5ac97 C |
104 | tags: [ 'tag1', 'tag2', 'tag3' ] |
105 | } | |
106 | videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, done) | |
9f10b292 | 107 | }) |
8c308c2b | 108 | |
9f10b292 C |
109 | it('Should seed the uploaded video', function (done) { |
110 | // Yes, this could be long | |
111 | this.timeout(60000) | |
8c308c2b | 112 | |
8d309058 | 113 | videosUtils.getVideosList(server.url, function (err, res) { |
9f10b292 | 114 | if (err) throw err |
8c308c2b | 115 | |
68ce3ae0 C |
116 | expect(res.body.total).to.equal(1) |
117 | expect(res.body.data).to.be.an('array') | |
118 | expect(res.body.data.length).to.equal(1) | |
8c308c2b | 119 | |
68ce3ae0 | 120 | const video = res.body.data[0] |
9f10b292 | 121 | expect(video.name).to.equal('my super name') |
6e07c3de C |
122 | expect(video.category).to.equal(2) |
123 | expect(video.categoryLabel).to.equal('Films') | |
6f0c39e2 C |
124 | expect(video.licence).to.equal(6) |
125 | expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | |
3092476e C |
126 | expect(video.language).to.equal(3) |
127 | expect(video.languageLabel).to.equal('Mandarin') | |
31b59b47 | 128 | expect(video.nsfw).to.be.truthy |
9f10b292 | 129 | expect(video.description).to.equal('my super description') |
a4254ea1 | 130 | expect(video.podHost).to.equal('localhost:9001') |
9f10b292 | 131 | expect(video.magnetUri).to.exist |
6d8ada5f C |
132 | expect(video.author).to.equal('root') |
133 | expect(video.isLocal).to.be.true | |
be587647 | 134 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) |
feb4bdfd | 135 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true |
79066fdf | 136 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true |
8c308c2b | 137 | |
8d309058 | 138 | videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { |
9e5f3740 C |
139 | if (err) throw err |
140 | expect(test).to.equal(true) | |
2df82d42 | 141 | |
bc503c2a | 142 | videoId = video.id |
2df82d42 | 143 | |
9e5f3740 C |
144 | webtorrent.add(video.magnetUri, function (torrent) { |
145 | expect(torrent.files).to.exist | |
146 | expect(torrent.files.length).to.equal(1) | |
147 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
148 | ||
790e65fc | 149 | done() |
9e5f3740 | 150 | }) |
2df82d42 C |
151 | }) |
152 | }) | |
153 | }) | |
154 | ||
155 | it('Should get the video', function (done) { | |
156 | // Yes, this could be long | |
157 | this.timeout(60000) | |
158 | ||
8d309058 | 159 | videosUtils.getVideo(server.url, videoId, function (err, res) { |
2df82d42 C |
160 | if (err) throw err |
161 | ||
162 | const video = res.body | |
163 | expect(video.name).to.equal('my super name') | |
6e07c3de C |
164 | expect(video.category).to.equal(2) |
165 | expect(video.categoryLabel).to.equal('Films') | |
6f0c39e2 C |
166 | expect(video.licence).to.equal(6) |
167 | expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | |
3092476e C |
168 | expect(video.language).to.equal(3) |
169 | expect(video.languageLabel).to.equal('Mandarin') | |
31b59b47 | 170 | expect(video.nsfw).to.be.truthy |
2df82d42 | 171 | expect(video.description).to.equal('my super description') |
a4254ea1 | 172 | expect(video.podHost).to.equal('localhost:9001') |
2df82d42 | 173 | expect(video.magnetUri).to.exist |
6d8ada5f C |
174 | expect(video.author).to.equal('root') |
175 | expect(video.isLocal).to.be.true | |
be587647 | 176 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) |
feb4bdfd | 177 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true |
79066fdf | 178 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true |
8c308c2b | 179 | |
8d309058 | 180 | videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { |
9e5f3740 C |
181 | if (err) throw err |
182 | expect(test).to.equal(true) | |
8c308c2b | 183 | |
5fe7e898 GS |
184 | // Wait the async views increment |
185 | setTimeout(done, 500) | |
876d1bcf | 186 | }) |
8c308c2b | 187 | }) |
9f10b292 | 188 | }) |
8c308c2b | 189 | |
9e167724 C |
190 | it('Should have the views updated', function (done) { |
191 | videosUtils.getVideo(server.url, videoId, function (err, res) { | |
192 | if (err) throw err | |
193 | ||
194 | const video = res.body | |
195 | expect(video.views).to.equal(1) | |
196 | ||
197 | done() | |
198 | }) | |
199 | }) | |
200 | ||
46246b5f | 201 | it('Should search the video by name by default', function (done) { |
8d309058 | 202 | videosUtils.searchVideo(server.url, 'my', function (err, res) { |
9f10b292 | 203 | if (err) throw err |
4d5f8138 | 204 | |
68ce3ae0 C |
205 | expect(res.body.total).to.equal(1) |
206 | expect(res.body.data).to.be.an('array') | |
207 | expect(res.body.data.length).to.equal(1) | |
4d5f8138 | 208 | |
68ce3ae0 | 209 | const video = res.body.data[0] |
9f10b292 | 210 | expect(video.name).to.equal('my super name') |
6e07c3de C |
211 | expect(video.category).to.equal(2) |
212 | expect(video.categoryLabel).to.equal('Films') | |
6f0c39e2 C |
213 | expect(video.licence).to.equal(6) |
214 | expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | |
3092476e C |
215 | expect(video.language).to.equal(3) |
216 | expect(video.languageLabel).to.equal('Mandarin') | |
31b59b47 | 217 | expect(video.nsfw).to.be.truthy |
9f10b292 | 218 | expect(video.description).to.equal('my super description') |
a4254ea1 | 219 | expect(video.podHost).to.equal('localhost:9001') |
6d8ada5f C |
220 | expect(video.author).to.equal('root') |
221 | expect(video.isLocal).to.be.true | |
be587647 | 222 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) |
feb4bdfd | 223 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true |
79066fdf | 224 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true |
4d5f8138 | 225 | |
8d309058 | 226 | videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { |
9e5f3740 C |
227 | if (err) throw err |
228 | expect(test).to.equal(true) | |
229 | ||
230 | done() | |
231 | }) | |
4d5f8138 | 232 | }) |
9f10b292 | 233 | }) |
4d5f8138 | 234 | |
7920c273 C |
235 | // Not implemented yet |
236 | // it('Should search the video by podHost', function (done) { | |
237 | // videosUtils.searchVideo(server.url, '9001', 'host', function (err, res) { | |
238 | // if (err) throw err | |
239 | ||
240 | // expect(res.body.total).to.equal(1) | |
241 | // expect(res.body.data).to.be.an('array') | |
242 | // expect(res.body.data.length).to.equal(1) | |
243 | ||
244 | // const video = res.body.data[0] | |
245 | // expect(video.name).to.equal('my super name') | |
246 | // expect(video.description).to.equal('my super description') | |
247 | // expect(video.podHost).to.equal('localhost:9001') | |
248 | // expect(video.author).to.equal('root') | |
249 | // expect(video.isLocal).to.be.true | |
250 | // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | |
251 | // expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | |
79066fdf | 252 | // expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true |
7920c273 C |
253 | |
254 | // videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { | |
255 | // if (err) throw err | |
256 | // expect(test).to.equal(true) | |
257 | ||
258 | // done() | |
259 | // }) | |
260 | // }) | |
261 | // }) | |
46246b5f | 262 | |
8d199cb8 | 263 | it('Should search the video by tag', function (done) { |
8d309058 | 264 | videosUtils.searchVideo(server.url, 'tag1', 'tags', function (err, res) { |
8d199cb8 C |
265 | if (err) throw err |
266 | ||
267 | expect(res.body.total).to.equal(1) | |
268 | expect(res.body.data).to.be.an('array') | |
269 | expect(res.body.data.length).to.equal(1) | |
270 | ||
271 | const video = res.body.data[0] | |
272 | expect(video.name).to.equal('my super name') | |
6e07c3de C |
273 | expect(video.category).to.equal(2) |
274 | expect(video.categoryLabel).to.equal('Films') | |
6f0c39e2 C |
275 | expect(video.licence).to.equal(6) |
276 | expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | |
3092476e C |
277 | expect(video.language).to.equal(3) |
278 | expect(video.languageLabel).to.equal('Mandarin') | |
31b59b47 | 279 | expect(video.nsfw).to.be.truthy |
8d199cb8 | 280 | expect(video.description).to.equal('my super description') |
a4254ea1 | 281 | expect(video.podHost).to.equal('localhost:9001') |
8d199cb8 C |
282 | expect(video.author).to.equal('root') |
283 | expect(video.isLocal).to.be.true | |
284 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | |
feb4bdfd | 285 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true |
79066fdf | 286 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true |
8d199cb8 | 287 | |
8d309058 | 288 | videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { |
8d199cb8 C |
289 | if (err) throw err |
290 | expect(test).to.equal(true) | |
291 | ||
292 | done() | |
293 | }) | |
294 | }) | |
295 | }) | |
296 | ||
46246b5f | 297 | it('Should not find a search by name by default', function (done) { |
8d309058 | 298 | videosUtils.searchVideo(server.url, 'hello', function (err, res) { |
9f10b292 | 299 | if (err) throw err |
4d5f8138 | 300 | |
68ce3ae0 C |
301 | expect(res.body.total).to.equal(0) |
302 | expect(res.body.data).to.be.an('array') | |
303 | expect(res.body.data.length).to.equal(0) | |
4d5f8138 | 304 | |
9f10b292 | 305 | done() |
4d5f8138 | 306 | }) |
9f10b292 | 307 | }) |
4d5f8138 | 308 | |
46246b5f | 309 | it('Should not find a search by author', function (done) { |
8d309058 | 310 | videosUtils.searchVideo(server.url, 'hello', 'author', function (err, res) { |
46246b5f C |
311 | if (err) throw err |
312 | ||
313 | expect(res.body.total).to.equal(0) | |
314 | expect(res.body.data).to.be.an('array') | |
315 | expect(res.body.data.length).to.equal(0) | |
316 | ||
317 | done() | |
318 | }) | |
319 | }) | |
320 | ||
8d199cb8 | 321 | it('Should not find a search by tag', function (done) { |
7920c273 | 322 | videosUtils.searchVideo(server.url, 'hello', 'tags', function (err, res) { |
8d199cb8 C |
323 | if (err) throw err |
324 | ||
325 | expect(res.body.total).to.equal(0) | |
326 | expect(res.body.data).to.be.an('array') | |
327 | expect(res.body.data.length).to.equal(0) | |
328 | ||
329 | done() | |
330 | }) | |
331 | }) | |
332 | ||
9f10b292 | 333 | it('Should remove the video', function (done) { |
8d309058 | 334 | videosUtils.removeVideo(server.url, server.accessToken, videoId, function (err) { |
9f10b292 | 335 | if (err) throw err |
f5a60a51 | 336 | |
15103f11 | 337 | fs.readdir(pathUtils.join(__dirname, '..', '..', '..', 'test1/videos/'), function (err, files) { |
9f10b292 | 338 | if (err) throw err |
f5a60a51 | 339 | |
9f10b292 | 340 | expect(files.length).to.equal(0) |
b3d92510 | 341 | |
15103f11 | 342 | fs.readdir(pathUtils.join(__dirname, '..', '..', '..', 'test1/thumbnails/'), function (err, files) { |
b3d92510 C |
343 | if (err) throw err |
344 | ||
345 | expect(files.length).to.equal(0) | |
346 | ||
347 | done() | |
348 | }) | |
876d1bcf | 349 | }) |
8c308c2b | 350 | }) |
9f10b292 | 351 | }) |
8c308c2b | 352 | |
9f10b292 | 353 | it('Should not have videos', function (done) { |
8d309058 | 354 | videosUtils.getVideosList(server.url, function (err, res) { |
9f10b292 | 355 | if (err) throw err |
8c308c2b | 356 | |
68ce3ae0 C |
357 | expect(res.body.total).to.equal(0) |
358 | expect(res.body.data).to.be.an('array') | |
359 | expect(res.body.data.length).to.equal(0) | |
8c308c2b | 360 | |
9f10b292 | 361 | done() |
8c308c2b | 362 | }) |
9f10b292 | 363 | }) |
8c308c2b | 364 | |
3a8a8b51 C |
365 | it('Should upload 6 videos', function (done) { |
366 | this.timeout(25000) | |
367 | const videos = [ | |
368 | 'video_short.mp4', 'video_short.ogv', 'video_short.webm', | |
369 | 'video_short1.webm', 'video_short2.webm', 'video_short3.webm' | |
370 | ] | |
1a42c9e2 | 371 | each(videos, function (video, callbackEach) { |
b4c5ac97 C |
372 | const videoAttributes = { |
373 | name: video + ' name', | |
374 | description: video + ' description', | |
375 | category: 2, | |
6f0c39e2 | 376 | licence: 1, |
3092476e | 377 | language: 1, |
31b59b47 | 378 | nsfw: true, |
b4c5ac97 C |
379 | tags: [ 'tag1', 'tag2', 'tag3' ], |
380 | fixture: video | |
381 | } | |
be587647 | 382 | |
b4c5ac97 | 383 | videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, callbackEach) |
3a8a8b51 C |
384 | }, done) |
385 | }) | |
386 | ||
387 | it('Should have the correct durations', function (done) { | |
8d309058 | 388 | videosUtils.getVideosList(server.url, function (err, res) { |
3a8a8b51 C |
389 | if (err) throw err |
390 | ||
68ce3ae0 C |
391 | expect(res.body.total).to.equal(6) |
392 | const videos = res.body.data | |
3a8a8b51 C |
393 | expect(videos).to.be.an('array') |
394 | expect(videos.length).to.equal(6) | |
395 | ||
bc503c2a C |
396 | const videosByName = keyBy(videos, 'name') |
397 | expect(videosByName['video_short.mp4 name'].duration).to.equal(5) | |
398 | expect(videosByName['video_short.ogv name'].duration).to.equal(5) | |
399 | expect(videosByName['video_short.webm name'].duration).to.equal(5) | |
400 | expect(videosByName['video_short1.webm name'].duration).to.equal(10) | |
401 | expect(videosByName['video_short2.webm name'].duration).to.equal(5) | |
402 | expect(videosByName['video_short3.webm name'].duration).to.equal(5) | |
3a8a8b51 C |
403 | |
404 | done() | |
405 | }) | |
406 | }) | |
407 | ||
9e5f3740 | 408 | it('Should have the correct thumbnails', function (done) { |
8d309058 | 409 | videosUtils.getVideosList(server.url, function (err, res) { |
fbf1134e C |
410 | if (err) throw err |
411 | ||
68ce3ae0 | 412 | const videos = res.body.data |
fbf1134e C |
413 | // For the next test |
414 | videosListBase = videos | |
9e5f3740 | 415 | |
1a42c9e2 | 416 | each(videos, function (video, callbackEach) { |
9e5f3740 | 417 | if (err) throw err |
bc503c2a | 418 | const videoName = video.name.replace(' name', '') |
9e5f3740 | 419 | |
8d309058 | 420 | videosUtils.testVideoImage(server.url, videoName, video.thumbnailPath, function (err, test) { |
9e5f3740 C |
421 | if (err) throw err |
422 | ||
423 | expect(test).to.equal(true) | |
bc503c2a | 424 | callbackEach() |
9e5f3740 C |
425 | }) |
426 | }, done) | |
427 | }) | |
428 | }) | |
429 | ||
fbf1134e | 430 | it('Should list only the two first videos', function (done) { |
91cc839a | 431 | videosUtils.getVideosListPagination(server.url, 0, 2, 'name', function (err, res) { |
fbf1134e C |
432 | if (err) throw err |
433 | ||
68ce3ae0 C |
434 | const videos = res.body.data |
435 | expect(res.body.total).to.equal(6) | |
fbf1134e | 436 | expect(videos.length).to.equal(2) |
91cc839a C |
437 | expect(videos[0].name).to.equal(videosListBase[0].name) |
438 | expect(videos[1].name).to.equal(videosListBase[1].name) | |
fbf1134e C |
439 | |
440 | done() | |
441 | }) | |
442 | }) | |
443 | ||
444 | it('Should list only the next three videos', function (done) { | |
91cc839a | 445 | videosUtils.getVideosListPagination(server.url, 2, 3, 'name', function (err, res) { |
fbf1134e C |
446 | if (err) throw err |
447 | ||
68ce3ae0 C |
448 | const videos = res.body.data |
449 | expect(res.body.total).to.equal(6) | |
022856f8 | 450 | expect(videos.length).to.equal(3) |
91cc839a C |
451 | expect(videos[0].name).to.equal(videosListBase[2].name) |
452 | expect(videos[1].name).to.equal(videosListBase[3].name) | |
453 | expect(videos[2].name).to.equal(videosListBase[4].name) | |
fbf1134e C |
454 | |
455 | done() | |
456 | }) | |
457 | }) | |
458 | ||
459 | it('Should list the last video', function (done) { | |
91cc839a | 460 | videosUtils.getVideosListPagination(server.url, 5, 6, 'name', function (err, res) { |
fbf1134e C |
461 | if (err) throw err |
462 | ||
68ce3ae0 C |
463 | const videos = res.body.data |
464 | expect(res.body.total).to.equal(6) | |
fbf1134e | 465 | expect(videos.length).to.equal(1) |
91cc839a | 466 | expect(videos[0].name).to.equal(videosListBase[5].name) |
fbf1134e C |
467 | |
468 | done() | |
469 | }) | |
470 | }) | |
471 | ||
472 | it('Should search the first video', function (done) { | |
91cc839a | 473 | videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, 'name', function (err, res) { |
fbf1134e C |
474 | if (err) throw err |
475 | ||
68ce3ae0 C |
476 | const videos = res.body.data |
477 | expect(res.body.total).to.equal(4) | |
fbf1134e | 478 | expect(videos.length).to.equal(1) |
91cc839a | 479 | expect(videos[0].name).to.equal('video_short1.webm name') |
fbf1134e C |
480 | |
481 | done() | |
482 | }) | |
483 | }) | |
484 | ||
485 | it('Should search the last two videos', function (done) { | |
91cc839a | 486 | videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, 'name', function (err, res) { |
fbf1134e C |
487 | if (err) throw err |
488 | ||
68ce3ae0 C |
489 | const videos = res.body.data |
490 | expect(res.body.total).to.equal(4) | |
fbf1134e | 491 | expect(videos.length).to.equal(2) |
91cc839a C |
492 | expect(videos[0].name).to.equal('video_short3.webm name') |
493 | expect(videos[1].name).to.equal('video_short.webm name') | |
fbf1134e C |
494 | |
495 | done() | |
496 | }) | |
497 | }) | |
498 | ||
46246b5f | 499 | it('Should search all the webm videos', function (done) { |
8d309058 | 500 | videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 15, function (err, res) { |
fbf1134e C |
501 | if (err) throw err |
502 | ||
68ce3ae0 C |
503 | const videos = res.body.data |
504 | expect(res.body.total).to.equal(4) | |
fbf1134e C |
505 | expect(videos.length).to.equal(4) |
506 | ||
507 | done() | |
508 | }) | |
509 | }) | |
510 | ||
46246b5f | 511 | it('Should search all the root author videos', function (done) { |
8d309058 | 512 | videosUtils.searchVideoWithPagination(server.url, 'root', 'author', 0, 15, function (err, res) { |
46246b5f C |
513 | if (err) throw err |
514 | ||
515 | const videos = res.body.data | |
516 | expect(res.body.total).to.equal(6) | |
517 | expect(videos.length).to.equal(6) | |
518 | ||
519 | done() | |
520 | }) | |
521 | }) | |
522 | ||
7920c273 C |
523 | // Not implemented yet |
524 | // it('Should search all the 9001 port videos', function (done) { | |
525 | // videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15, function (err, res) { | |
526 | // if (err) throw err | |
46246b5f | 527 | |
7920c273 C |
528 | // const videos = res.body.data |
529 | // expect(res.body.total).to.equal(6) | |
530 | // expect(videos.length).to.equal(6) | |
46246b5f | 531 | |
7920c273 C |
532 | // done() |
533 | // }) | |
534 | // }) | |
46246b5f | 535 | |
7920c273 C |
536 | // it('Should search all the localhost videos', function (done) { |
537 | // videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15, function (err, res) { | |
538 | // if (err) throw err | |
46246b5f | 539 | |
7920c273 C |
540 | // const videos = res.body.data |
541 | // expect(res.body.total).to.equal(6) | |
542 | // expect(videos.length).to.equal(6) | |
46246b5f | 543 | |
7920c273 C |
544 | // done() |
545 | // }) | |
546 | // }) | |
46246b5f | 547 | |
6e07c3de | 548 | it('Should search the right magnetUri video', function (done) { |
46246b5f | 549 | const video = videosListBase[0] |
8d309058 | 550 | videosUtils.searchVideoWithPagination(server.url, encodeURIComponent(video.magnetUri), 'magnetUri', 0, 15, function (err, res) { |
46246b5f C |
551 | if (err) throw err |
552 | ||
553 | const videos = res.body.data | |
554 | expect(res.body.total).to.equal(1) | |
555 | expect(videos.length).to.equal(1) | |
556 | expect(videos[0].name).to.equal(video.name) | |
557 | ||
558 | done() | |
559 | }) | |
560 | }) | |
561 | ||
a877d5ac | 562 | it('Should list and sort by name in descending order', function (done) { |
8d309058 | 563 | videosUtils.getVideosListSort(server.url, '-name', function (err, res) { |
a877d5ac C |
564 | if (err) throw err |
565 | ||
68ce3ae0 C |
566 | const videos = res.body.data |
567 | expect(res.body.total).to.equal(6) | |
a877d5ac | 568 | expect(videos.length).to.equal(6) |
91cc839a C |
569 | expect(videos[0].name).to.equal('video_short.webm name') |
570 | expect(videos[1].name).to.equal('video_short.ogv name') | |
571 | expect(videos[2].name).to.equal('video_short.mp4 name') | |
572 | expect(videos[3].name).to.equal('video_short3.webm name') | |
573 | expect(videos[4].name).to.equal('video_short2.webm name') | |
574 | expect(videos[5].name).to.equal('video_short1.webm name') | |
a877d5ac C |
575 | |
576 | done() | |
577 | }) | |
578 | }) | |
579 | ||
580 | it('Should search and sort by name in ascending order', function (done) { | |
8d309058 | 581 | videosUtils.searchVideoWithSort(server.url, 'webm', 'name', function (err, res) { |
a877d5ac C |
582 | if (err) throw err |
583 | ||
68ce3ae0 C |
584 | const videos = res.body.data |
585 | expect(res.body.total).to.equal(4) | |
a877d5ac C |
586 | expect(videos.length).to.equal(4) |
587 | ||
91cc839a C |
588 | expect(videos[0].name).to.equal('video_short1.webm name') |
589 | expect(videos[1].name).to.equal('video_short2.webm name') | |
590 | expect(videos[2].name).to.equal('video_short3.webm name') | |
591 | expect(videos[3].name).to.equal('video_short.webm name') | |
a877d5ac | 592 | |
91cc839a | 593 | videoId = videos[2].id |
7b1f49de | 594 | |
a877d5ac C |
595 | done() |
596 | }) | |
597 | }) | |
598 | ||
7b1f49de | 599 | it('Should update a video', function (done) { |
b4c5ac97 C |
600 | const attributes = { |
601 | name: 'my super video updated', | |
602 | category: 4, | |
6f0c39e2 | 603 | licence: 2, |
3092476e | 604 | language: 5, |
31b59b47 | 605 | nsfw: false, |
b4c5ac97 C |
606 | description: 'my super description updated', |
607 | tags: [ 'tagup1', 'tagup2' ] | |
608 | } | |
609 | videosUtils.updateVideo(server.url, server.accessToken, videoId, attributes, done) | |
7b1f49de C |
610 | }) |
611 | ||
612 | it('Should have the video updated', function (done) { | |
7f4e7c36 C |
613 | this.timeout(60000) |
614 | ||
7b1f49de C |
615 | videosUtils.getVideo(server.url, videoId, function (err, res) { |
616 | if (err) throw err | |
617 | ||
618 | const video = res.body | |
619 | ||
620 | expect(video.name).to.equal('my super video updated') | |
6e07c3de C |
621 | expect(video.category).to.equal(4) |
622 | expect(video.categoryLabel).to.equal('Art') | |
6f0c39e2 C |
623 | expect(video.licence).to.equal(2) |
624 | expect(video.licenceLabel).to.equal('Attribution - Share Alike') | |
3092476e C |
625 | expect(video.language).to.equal(5) |
626 | expect(video.languageLabel).to.equal('Arabic') | |
31b59b47 | 627 | expect(video.nsfw).to.be.truthy |
7b1f49de C |
628 | expect(video.description).to.equal('my super description updated') |
629 | expect(video.podHost).to.equal('localhost:9001') | |
630 | expect(video.author).to.equal('root') | |
631 | expect(video.isLocal).to.be.true | |
632 | expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ]) | |
633 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | |
79066fdf | 634 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true |
7b1f49de | 635 | |
7f4e7c36 C |
636 | videosUtils.testVideoImage(server.url, 'video_short3.webm', video.thumbnailPath, function (err, test) { |
637 | if (err) throw err | |
638 | expect(test).to.equal(true) | |
639 | ||
7f4e7c36 C |
640 | webtorrent.add(video.magnetUri, function (torrent) { |
641 | expect(torrent.files).to.exist | |
642 | expect(torrent.files.length).to.equal(1) | |
643 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
644 | ||
645 | done() | |
646 | }) | |
647 | }) | |
7b1f49de C |
648 | }) |
649 | }) | |
650 | ||
651 | it('Should update only the tags of a video', function (done) { | |
b4c5ac97 C |
652 | const attributes = { |
653 | tags: [ 'tag1', 'tag2', 'supertag' ] | |
654 | } | |
7b1f49de | 655 | |
b4c5ac97 | 656 | videosUtils.updateVideo(server.url, server.accessToken, videoId, attributes, function (err) { |
7b1f49de C |
657 | if (err) throw err |
658 | ||
659 | videosUtils.getVideo(server.url, videoId, function (err, res) { | |
660 | if (err) throw err | |
661 | ||
662 | const video = res.body | |
663 | ||
664 | expect(video.name).to.equal('my super video updated') | |
6e07c3de C |
665 | expect(video.category).to.equal(4) |
666 | expect(video.categoryLabel).to.equal('Art') | |
6f0c39e2 C |
667 | expect(video.licence).to.equal(2) |
668 | expect(video.licenceLabel).to.equal('Attribution - Share Alike') | |
3092476e C |
669 | expect(video.language).to.equal(5) |
670 | expect(video.languageLabel).to.equal('Arabic') | |
31b59b47 | 671 | expect(video.nsfw).to.be.truthy |
7b1f49de C |
672 | expect(video.description).to.equal('my super description updated') |
673 | expect(video.podHost).to.equal('localhost:9001') | |
674 | expect(video.author).to.equal('root') | |
675 | expect(video.isLocal).to.be.true | |
676 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ]) | |
677 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | |
79066fdf | 678 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true |
7b1f49de C |
679 | |
680 | done() | |
681 | }) | |
682 | }) | |
683 | }) | |
684 | ||
685 | it('Should update only the description of a video', function (done) { | |
b4c5ac97 C |
686 | const attributes = { |
687 | description: 'hello everybody' | |
688 | } | |
7b1f49de | 689 | |
b4c5ac97 | 690 | videosUtils.updateVideo(server.url, server.accessToken, videoId, attributes, function (err) { |
7b1f49de C |
691 | if (err) throw err |
692 | ||
693 | videosUtils.getVideo(server.url, videoId, function (err, res) { | |
694 | if (err) throw err | |
695 | ||
696 | const video = res.body | |
697 | ||
698 | expect(video.name).to.equal('my super video updated') | |
6e07c3de C |
699 | expect(video.category).to.equal(4) |
700 | expect(video.categoryLabel).to.equal('Art') | |
6f0c39e2 C |
701 | expect(video.licence).to.equal(2) |
702 | expect(video.licenceLabel).to.equal('Attribution - Share Alike') | |
3092476e C |
703 | expect(video.language).to.equal(5) |
704 | expect(video.languageLabel).to.equal('Arabic') | |
31b59b47 | 705 | expect(video.nsfw).to.be.truthy |
7b1f49de C |
706 | expect(video.description).to.equal('hello everybody') |
707 | expect(video.podHost).to.equal('localhost:9001') | |
708 | expect(video.author).to.equal('root') | |
709 | expect(video.isLocal).to.be.true | |
710 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ]) | |
711 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | |
79066fdf | 712 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true |
7b1f49de C |
713 | |
714 | done() | |
715 | }) | |
716 | }) | |
717 | }) | |
718 | ||
d38b8281 C |
719 | it('Should like a video', function (done) { |
720 | videosUtils.rateVideo(server.url, server.accessToken, videoId, 'like', function (err) { | |
721 | if (err) throw err | |
722 | ||
723 | videosUtils.getVideo(server.url, videoId, function (err, res) { | |
724 | if (err) throw err | |
725 | ||
726 | const video = res.body | |
727 | ||
728 | expect(video.likes).to.equal(1) | |
729 | expect(video.dislikes).to.equal(0) | |
730 | ||
731 | done() | |
732 | }) | |
733 | }) | |
734 | }) | |
735 | ||
736 | it('Should dislike the same video', function (done) { | |
737 | videosUtils.rateVideo(server.url, server.accessToken, videoId, 'dislike', function (err) { | |
738 | if (err) throw err | |
739 | ||
740 | videosUtils.getVideo(server.url, videoId, function (err, res) { | |
741 | if (err) throw err | |
742 | ||
743 | const video = res.body | |
744 | ||
745 | expect(video.likes).to.equal(0) | |
746 | expect(video.dislikes).to.equal(1) | |
747 | ||
748 | done() | |
749 | }) | |
750 | }) | |
751 | }) | |
752 | ||
9f10b292 | 753 | after(function (done) { |
0c1cbbfe | 754 | process.kill(-server.app.pid) |
8c308c2b | 755 | |
9f10b292 C |
756 | // Keep the logs if the test failed |
757 | if (this.ok) { | |
8d309058 | 758 | serversUtils.flushTests(done) |
9f10b292 C |
759 | } else { |
760 | done() | |
761 | } | |
8c308c2b | 762 | }) |
9f10b292 | 763 | }) |