]>
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) { | |
25 | this.timeout(20000) | |
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 | |
ede4db9e | 184 | done() |
876d1bcf | 185 | }) |
8c308c2b | 186 | }) |
9f10b292 | 187 | }) |
8c308c2b | 188 | |
9e167724 C |
189 | it('Should have the views updated', function (done) { |
190 | videosUtils.getVideo(server.url, videoId, function (err, res) { | |
191 | if (err) throw err | |
192 | ||
193 | const video = res.body | |
194 | expect(video.views).to.equal(1) | |
195 | ||
196 | done() | |
197 | }) | |
198 | }) | |
199 | ||
46246b5f | 200 | it('Should search the video by name by default', function (done) { |
8d309058 | 201 | videosUtils.searchVideo(server.url, 'my', function (err, res) { |
9f10b292 | 202 | if (err) throw err |
4d5f8138 | 203 | |
68ce3ae0 C |
204 | expect(res.body.total).to.equal(1) |
205 | expect(res.body.data).to.be.an('array') | |
206 | expect(res.body.data.length).to.equal(1) | |
4d5f8138 | 207 | |
68ce3ae0 | 208 | const video = res.body.data[0] |
9f10b292 | 209 | expect(video.name).to.equal('my super name') |
6e07c3de C |
210 | expect(video.category).to.equal(2) |
211 | expect(video.categoryLabel).to.equal('Films') | |
6f0c39e2 C |
212 | expect(video.licence).to.equal(6) |
213 | expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | |
3092476e C |
214 | expect(video.language).to.equal(3) |
215 | expect(video.languageLabel).to.equal('Mandarin') | |
31b59b47 | 216 | expect(video.nsfw).to.be.truthy |
9f10b292 | 217 | expect(video.description).to.equal('my super description') |
a4254ea1 | 218 | expect(video.podHost).to.equal('localhost:9001') |
6d8ada5f C |
219 | expect(video.author).to.equal('root') |
220 | expect(video.isLocal).to.be.true | |
be587647 | 221 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) |
feb4bdfd | 222 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true |
79066fdf | 223 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true |
4d5f8138 | 224 | |
8d309058 | 225 | videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { |
9e5f3740 C |
226 | if (err) throw err |
227 | expect(test).to.equal(true) | |
228 | ||
229 | done() | |
230 | }) | |
4d5f8138 | 231 | }) |
9f10b292 | 232 | }) |
4d5f8138 | 233 | |
7920c273 C |
234 | // Not implemented yet |
235 | // it('Should search the video by podHost', function (done) { | |
236 | // videosUtils.searchVideo(server.url, '9001', 'host', function (err, res) { | |
237 | // if (err) throw err | |
238 | ||
239 | // expect(res.body.total).to.equal(1) | |
240 | // expect(res.body.data).to.be.an('array') | |
241 | // expect(res.body.data.length).to.equal(1) | |
242 | ||
243 | // const video = res.body.data[0] | |
244 | // expect(video.name).to.equal('my super name') | |
245 | // expect(video.description).to.equal('my super description') | |
246 | // expect(video.podHost).to.equal('localhost:9001') | |
247 | // expect(video.author).to.equal('root') | |
248 | // expect(video.isLocal).to.be.true | |
249 | // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | |
250 | // expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | |
79066fdf | 251 | // expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true |
7920c273 C |
252 | |
253 | // videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { | |
254 | // if (err) throw err | |
255 | // expect(test).to.equal(true) | |
256 | ||
257 | // done() | |
258 | // }) | |
259 | // }) | |
260 | // }) | |
46246b5f | 261 | |
8d199cb8 | 262 | it('Should search the video by tag', function (done) { |
8d309058 | 263 | videosUtils.searchVideo(server.url, 'tag1', 'tags', function (err, res) { |
8d199cb8 C |
264 | if (err) throw err |
265 | ||
266 | expect(res.body.total).to.equal(1) | |
267 | expect(res.body.data).to.be.an('array') | |
268 | expect(res.body.data.length).to.equal(1) | |
269 | ||
270 | const video = res.body.data[0] | |
271 | expect(video.name).to.equal('my super name') | |
6e07c3de C |
272 | expect(video.category).to.equal(2) |
273 | expect(video.categoryLabel).to.equal('Films') | |
6f0c39e2 C |
274 | expect(video.licence).to.equal(6) |
275 | expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | |
3092476e C |
276 | expect(video.language).to.equal(3) |
277 | expect(video.languageLabel).to.equal('Mandarin') | |
31b59b47 | 278 | expect(video.nsfw).to.be.truthy |
8d199cb8 | 279 | expect(video.description).to.equal('my super description') |
a4254ea1 | 280 | expect(video.podHost).to.equal('localhost:9001') |
8d199cb8 C |
281 | expect(video.author).to.equal('root') |
282 | expect(video.isLocal).to.be.true | |
283 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | |
feb4bdfd | 284 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true |
79066fdf | 285 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true |
8d199cb8 | 286 | |
8d309058 | 287 | videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { |
8d199cb8 C |
288 | if (err) throw err |
289 | expect(test).to.equal(true) | |
290 | ||
291 | done() | |
292 | }) | |
293 | }) | |
294 | }) | |
295 | ||
46246b5f | 296 | it('Should not find a search by name by default', function (done) { |
8d309058 | 297 | videosUtils.searchVideo(server.url, 'hello', function (err, res) { |
9f10b292 | 298 | if (err) throw err |
4d5f8138 | 299 | |
68ce3ae0 C |
300 | expect(res.body.total).to.equal(0) |
301 | expect(res.body.data).to.be.an('array') | |
302 | expect(res.body.data.length).to.equal(0) | |
4d5f8138 | 303 | |
9f10b292 | 304 | done() |
4d5f8138 | 305 | }) |
9f10b292 | 306 | }) |
4d5f8138 | 307 | |
46246b5f | 308 | it('Should not find a search by author', function (done) { |
8d309058 | 309 | videosUtils.searchVideo(server.url, 'hello', 'author', function (err, res) { |
46246b5f C |
310 | if (err) throw err |
311 | ||
312 | expect(res.body.total).to.equal(0) | |
313 | expect(res.body.data).to.be.an('array') | |
314 | expect(res.body.data.length).to.equal(0) | |
315 | ||
316 | done() | |
317 | }) | |
318 | }) | |
319 | ||
8d199cb8 | 320 | it('Should not find a search by tag', function (done) { |
7920c273 | 321 | videosUtils.searchVideo(server.url, 'hello', 'tags', function (err, res) { |
8d199cb8 C |
322 | if (err) throw err |
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 | done() | |
329 | }) | |
330 | }) | |
331 | ||
9f10b292 | 332 | it('Should remove the video', function (done) { |
8d309058 | 333 | videosUtils.removeVideo(server.url, server.accessToken, videoId, function (err) { |
9f10b292 | 334 | if (err) throw err |
f5a60a51 | 335 | |
15103f11 | 336 | fs.readdir(pathUtils.join(__dirname, '..', '..', '..', 'test1/videos/'), function (err, files) { |
9f10b292 | 337 | if (err) throw err |
f5a60a51 | 338 | |
9f10b292 | 339 | expect(files.length).to.equal(0) |
b3d92510 | 340 | |
15103f11 | 341 | fs.readdir(pathUtils.join(__dirname, '..', '..', '..', 'test1/thumbnails/'), function (err, files) { |
b3d92510 C |
342 | if (err) throw err |
343 | ||
344 | expect(files.length).to.equal(0) | |
345 | ||
346 | done() | |
347 | }) | |
876d1bcf | 348 | }) |
8c308c2b | 349 | }) |
9f10b292 | 350 | }) |
8c308c2b | 351 | |
9f10b292 | 352 | it('Should not have videos', function (done) { |
8d309058 | 353 | videosUtils.getVideosList(server.url, function (err, res) { |
9f10b292 | 354 | if (err) throw err |
8c308c2b | 355 | |
68ce3ae0 C |
356 | expect(res.body.total).to.equal(0) |
357 | expect(res.body.data).to.be.an('array') | |
358 | expect(res.body.data.length).to.equal(0) | |
8c308c2b | 359 | |
9f10b292 | 360 | done() |
8c308c2b | 361 | }) |
9f10b292 | 362 | }) |
8c308c2b | 363 | |
3a8a8b51 C |
364 | it('Should upload 6 videos', function (done) { |
365 | this.timeout(25000) | |
366 | const videos = [ | |
367 | 'video_short.mp4', 'video_short.ogv', 'video_short.webm', | |
368 | 'video_short1.webm', 'video_short2.webm', 'video_short3.webm' | |
369 | ] | |
1a42c9e2 | 370 | each(videos, function (video, callbackEach) { |
b4c5ac97 C |
371 | const videoAttributes = { |
372 | name: video + ' name', | |
373 | description: video + ' description', | |
374 | category: 2, | |
6f0c39e2 | 375 | licence: 1, |
3092476e | 376 | language: 1, |
31b59b47 | 377 | nsfw: true, |
b4c5ac97 C |
378 | tags: [ 'tag1', 'tag2', 'tag3' ], |
379 | fixture: video | |
380 | } | |
be587647 | 381 | |
b4c5ac97 | 382 | videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, callbackEach) |
3a8a8b51 C |
383 | }, done) |
384 | }) | |
385 | ||
386 | it('Should have the correct durations', function (done) { | |
8d309058 | 387 | videosUtils.getVideosList(server.url, function (err, res) { |
3a8a8b51 C |
388 | if (err) throw err |
389 | ||
68ce3ae0 C |
390 | expect(res.body.total).to.equal(6) |
391 | const videos = res.body.data | |
3a8a8b51 C |
392 | expect(videos).to.be.an('array') |
393 | expect(videos.length).to.equal(6) | |
394 | ||
bc503c2a C |
395 | const videosByName = keyBy(videos, 'name') |
396 | expect(videosByName['video_short.mp4 name'].duration).to.equal(5) | |
397 | expect(videosByName['video_short.ogv name'].duration).to.equal(5) | |
398 | expect(videosByName['video_short.webm name'].duration).to.equal(5) | |
399 | expect(videosByName['video_short1.webm name'].duration).to.equal(10) | |
400 | expect(videosByName['video_short2.webm name'].duration).to.equal(5) | |
401 | expect(videosByName['video_short3.webm name'].duration).to.equal(5) | |
3a8a8b51 C |
402 | |
403 | done() | |
404 | }) | |
405 | }) | |
406 | ||
9e5f3740 | 407 | it('Should have the correct thumbnails', function (done) { |
8d309058 | 408 | videosUtils.getVideosList(server.url, function (err, res) { |
fbf1134e C |
409 | if (err) throw err |
410 | ||
68ce3ae0 | 411 | const videos = res.body.data |
fbf1134e C |
412 | // For the next test |
413 | videosListBase = videos | |
9e5f3740 | 414 | |
1a42c9e2 | 415 | each(videos, function (video, callbackEach) { |
9e5f3740 | 416 | if (err) throw err |
bc503c2a | 417 | const videoName = video.name.replace(' name', '') |
9e5f3740 | 418 | |
8d309058 | 419 | videosUtils.testVideoImage(server.url, videoName, video.thumbnailPath, function (err, test) { |
9e5f3740 C |
420 | if (err) throw err |
421 | ||
422 | expect(test).to.equal(true) | |
bc503c2a | 423 | callbackEach() |
9e5f3740 C |
424 | }) |
425 | }, done) | |
426 | }) | |
427 | }) | |
428 | ||
fbf1134e | 429 | it('Should list only the two first videos', function (done) { |
91cc839a | 430 | videosUtils.getVideosListPagination(server.url, 0, 2, 'name', function (err, res) { |
fbf1134e C |
431 | if (err) throw err |
432 | ||
68ce3ae0 C |
433 | const videos = res.body.data |
434 | expect(res.body.total).to.equal(6) | |
fbf1134e | 435 | expect(videos.length).to.equal(2) |
91cc839a C |
436 | expect(videos[0].name).to.equal(videosListBase[0].name) |
437 | expect(videos[1].name).to.equal(videosListBase[1].name) | |
fbf1134e C |
438 | |
439 | done() | |
440 | }) | |
441 | }) | |
442 | ||
443 | it('Should list only the next three videos', function (done) { | |
91cc839a | 444 | videosUtils.getVideosListPagination(server.url, 2, 3, 'name', function (err, res) { |
fbf1134e C |
445 | if (err) throw err |
446 | ||
68ce3ae0 C |
447 | const videos = res.body.data |
448 | expect(res.body.total).to.equal(6) | |
022856f8 | 449 | expect(videos.length).to.equal(3) |
91cc839a C |
450 | expect(videos[0].name).to.equal(videosListBase[2].name) |
451 | expect(videos[1].name).to.equal(videosListBase[3].name) | |
452 | expect(videos[2].name).to.equal(videosListBase[4].name) | |
fbf1134e C |
453 | |
454 | done() | |
455 | }) | |
456 | }) | |
457 | ||
458 | it('Should list the last video', function (done) { | |
91cc839a | 459 | videosUtils.getVideosListPagination(server.url, 5, 6, 'name', function (err, res) { |
fbf1134e C |
460 | if (err) throw err |
461 | ||
68ce3ae0 C |
462 | const videos = res.body.data |
463 | expect(res.body.total).to.equal(6) | |
fbf1134e | 464 | expect(videos.length).to.equal(1) |
91cc839a | 465 | expect(videos[0].name).to.equal(videosListBase[5].name) |
fbf1134e C |
466 | |
467 | done() | |
468 | }) | |
469 | }) | |
470 | ||
471 | it('Should search the first video', function (done) { | |
91cc839a | 472 | videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, 'name', function (err, res) { |
fbf1134e C |
473 | if (err) throw err |
474 | ||
68ce3ae0 C |
475 | const videos = res.body.data |
476 | expect(res.body.total).to.equal(4) | |
fbf1134e | 477 | expect(videos.length).to.equal(1) |
91cc839a | 478 | expect(videos[0].name).to.equal('video_short1.webm name') |
fbf1134e C |
479 | |
480 | done() | |
481 | }) | |
482 | }) | |
483 | ||
484 | it('Should search the last two videos', function (done) { | |
91cc839a | 485 | videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, 'name', function (err, res) { |
fbf1134e C |
486 | if (err) throw err |
487 | ||
68ce3ae0 C |
488 | const videos = res.body.data |
489 | expect(res.body.total).to.equal(4) | |
fbf1134e | 490 | expect(videos.length).to.equal(2) |
91cc839a C |
491 | expect(videos[0].name).to.equal('video_short3.webm name') |
492 | expect(videos[1].name).to.equal('video_short.webm name') | |
fbf1134e C |
493 | |
494 | done() | |
495 | }) | |
496 | }) | |
497 | ||
46246b5f | 498 | it('Should search all the webm videos', function (done) { |
8d309058 | 499 | videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 15, function (err, res) { |
fbf1134e C |
500 | if (err) throw err |
501 | ||
68ce3ae0 C |
502 | const videos = res.body.data |
503 | expect(res.body.total).to.equal(4) | |
fbf1134e C |
504 | expect(videos.length).to.equal(4) |
505 | ||
506 | done() | |
507 | }) | |
508 | }) | |
509 | ||
46246b5f | 510 | it('Should search all the root author videos', function (done) { |
8d309058 | 511 | videosUtils.searchVideoWithPagination(server.url, 'root', 'author', 0, 15, function (err, res) { |
46246b5f C |
512 | if (err) throw err |
513 | ||
514 | const videos = res.body.data | |
515 | expect(res.body.total).to.equal(6) | |
516 | expect(videos.length).to.equal(6) | |
517 | ||
518 | done() | |
519 | }) | |
520 | }) | |
521 | ||
7920c273 C |
522 | // Not implemented yet |
523 | // it('Should search all the 9001 port videos', function (done) { | |
524 | // videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15, function (err, res) { | |
525 | // if (err) throw err | |
46246b5f | 526 | |
7920c273 C |
527 | // const videos = res.body.data |
528 | // expect(res.body.total).to.equal(6) | |
529 | // expect(videos.length).to.equal(6) | |
46246b5f | 530 | |
7920c273 C |
531 | // done() |
532 | // }) | |
533 | // }) | |
46246b5f | 534 | |
7920c273 C |
535 | // it('Should search all the localhost videos', function (done) { |
536 | // videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15, function (err, res) { | |
537 | // if (err) throw err | |
46246b5f | 538 | |
7920c273 C |
539 | // const videos = res.body.data |
540 | // expect(res.body.total).to.equal(6) | |
541 | // expect(videos.length).to.equal(6) | |
46246b5f | 542 | |
7920c273 C |
543 | // done() |
544 | // }) | |
545 | // }) | |
46246b5f | 546 | |
6e07c3de | 547 | it('Should search the right magnetUri video', function (done) { |
46246b5f | 548 | const video = videosListBase[0] |
8d309058 | 549 | videosUtils.searchVideoWithPagination(server.url, encodeURIComponent(video.magnetUri), 'magnetUri', 0, 15, function (err, res) { |
46246b5f C |
550 | if (err) throw err |
551 | ||
552 | const videos = res.body.data | |
553 | expect(res.body.total).to.equal(1) | |
554 | expect(videos.length).to.equal(1) | |
555 | expect(videos[0].name).to.equal(video.name) | |
556 | ||
557 | done() | |
558 | }) | |
559 | }) | |
560 | ||
a877d5ac | 561 | it('Should list and sort by name in descending order', function (done) { |
8d309058 | 562 | videosUtils.getVideosListSort(server.url, '-name', function (err, res) { |
a877d5ac C |
563 | if (err) throw err |
564 | ||
68ce3ae0 C |
565 | const videos = res.body.data |
566 | expect(res.body.total).to.equal(6) | |
a877d5ac | 567 | expect(videos.length).to.equal(6) |
91cc839a C |
568 | expect(videos[0].name).to.equal('video_short.webm name') |
569 | expect(videos[1].name).to.equal('video_short.ogv name') | |
570 | expect(videos[2].name).to.equal('video_short.mp4 name') | |
571 | expect(videos[3].name).to.equal('video_short3.webm name') | |
572 | expect(videos[4].name).to.equal('video_short2.webm name') | |
573 | expect(videos[5].name).to.equal('video_short1.webm name') | |
a877d5ac C |
574 | |
575 | done() | |
576 | }) | |
577 | }) | |
578 | ||
579 | it('Should search and sort by name in ascending order', function (done) { | |
8d309058 | 580 | videosUtils.searchVideoWithSort(server.url, 'webm', 'name', function (err, res) { |
a877d5ac C |
581 | if (err) throw err |
582 | ||
68ce3ae0 C |
583 | const videos = res.body.data |
584 | expect(res.body.total).to.equal(4) | |
a877d5ac C |
585 | expect(videos.length).to.equal(4) |
586 | ||
91cc839a C |
587 | expect(videos[0].name).to.equal('video_short1.webm name') |
588 | expect(videos[1].name).to.equal('video_short2.webm name') | |
589 | expect(videos[2].name).to.equal('video_short3.webm name') | |
590 | expect(videos[3].name).to.equal('video_short.webm name') | |
a877d5ac | 591 | |
91cc839a | 592 | videoId = videos[2].id |
7b1f49de | 593 | |
a877d5ac C |
594 | done() |
595 | }) | |
596 | }) | |
597 | ||
7b1f49de | 598 | it('Should update a video', function (done) { |
b4c5ac97 C |
599 | const attributes = { |
600 | name: 'my super video updated', | |
601 | category: 4, | |
6f0c39e2 | 602 | licence: 2, |
3092476e | 603 | language: 5, |
31b59b47 | 604 | nsfw: false, |
b4c5ac97 C |
605 | description: 'my super description updated', |
606 | tags: [ 'tagup1', 'tagup2' ] | |
607 | } | |
608 | videosUtils.updateVideo(server.url, server.accessToken, videoId, attributes, done) | |
7b1f49de C |
609 | }) |
610 | ||
611 | it('Should have the video updated', function (done) { | |
7f4e7c36 C |
612 | this.timeout(60000) |
613 | ||
7b1f49de C |
614 | videosUtils.getVideo(server.url, videoId, function (err, res) { |
615 | if (err) throw err | |
616 | ||
617 | const video = res.body | |
618 | ||
619 | expect(video.name).to.equal('my super video updated') | |
6e07c3de C |
620 | expect(video.category).to.equal(4) |
621 | expect(video.categoryLabel).to.equal('Art') | |
6f0c39e2 C |
622 | expect(video.licence).to.equal(2) |
623 | expect(video.licenceLabel).to.equal('Attribution - Share Alike') | |
3092476e C |
624 | expect(video.language).to.equal(5) |
625 | expect(video.languageLabel).to.equal('Arabic') | |
31b59b47 | 626 | expect(video.nsfw).to.be.truthy |
7b1f49de C |
627 | expect(video.description).to.equal('my super description updated') |
628 | expect(video.podHost).to.equal('localhost:9001') | |
629 | expect(video.author).to.equal('root') | |
630 | expect(video.isLocal).to.be.true | |
631 | expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ]) | |
632 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | |
79066fdf | 633 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true |
7b1f49de | 634 | |
7f4e7c36 C |
635 | videosUtils.testVideoImage(server.url, 'video_short3.webm', video.thumbnailPath, function (err, test) { |
636 | if (err) throw err | |
637 | expect(test).to.equal(true) | |
638 | ||
7f4e7c36 C |
639 | webtorrent.add(video.magnetUri, function (torrent) { |
640 | expect(torrent.files).to.exist | |
641 | expect(torrent.files.length).to.equal(1) | |
642 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
643 | ||
644 | done() | |
645 | }) | |
646 | }) | |
7b1f49de C |
647 | }) |
648 | }) | |
649 | ||
650 | it('Should update only the tags of a video', function (done) { | |
b4c5ac97 C |
651 | const attributes = { |
652 | tags: [ 'tag1', 'tag2', 'supertag' ] | |
653 | } | |
7b1f49de | 654 | |
b4c5ac97 | 655 | videosUtils.updateVideo(server.url, server.accessToken, videoId, attributes, function (err) { |
7b1f49de C |
656 | if (err) throw err |
657 | ||
658 | videosUtils.getVideo(server.url, videoId, function (err, res) { | |
659 | if (err) throw err | |
660 | ||
661 | const video = res.body | |
662 | ||
663 | expect(video.name).to.equal('my super video updated') | |
6e07c3de C |
664 | expect(video.category).to.equal(4) |
665 | expect(video.categoryLabel).to.equal('Art') | |
6f0c39e2 C |
666 | expect(video.licence).to.equal(2) |
667 | expect(video.licenceLabel).to.equal('Attribution - Share Alike') | |
3092476e C |
668 | expect(video.language).to.equal(5) |
669 | expect(video.languageLabel).to.equal('Arabic') | |
31b59b47 | 670 | expect(video.nsfw).to.be.truthy |
7b1f49de C |
671 | expect(video.description).to.equal('my super description updated') |
672 | expect(video.podHost).to.equal('localhost:9001') | |
673 | expect(video.author).to.equal('root') | |
674 | expect(video.isLocal).to.be.true | |
675 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ]) | |
676 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | |
79066fdf | 677 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true |
7b1f49de C |
678 | |
679 | done() | |
680 | }) | |
681 | }) | |
682 | }) | |
683 | ||
684 | it('Should update only the description of a video', function (done) { | |
b4c5ac97 C |
685 | const attributes = { |
686 | description: 'hello everybody' | |
687 | } | |
7b1f49de | 688 | |
b4c5ac97 | 689 | videosUtils.updateVideo(server.url, server.accessToken, videoId, attributes, function (err) { |
7b1f49de C |
690 | if (err) throw err |
691 | ||
692 | videosUtils.getVideo(server.url, videoId, function (err, res) { | |
693 | if (err) throw err | |
694 | ||
695 | const video = res.body | |
696 | ||
697 | expect(video.name).to.equal('my super video updated') | |
6e07c3de C |
698 | expect(video.category).to.equal(4) |
699 | expect(video.categoryLabel).to.equal('Art') | |
6f0c39e2 C |
700 | expect(video.licence).to.equal(2) |
701 | expect(video.licenceLabel).to.equal('Attribution - Share Alike') | |
3092476e C |
702 | expect(video.language).to.equal(5) |
703 | expect(video.languageLabel).to.equal('Arabic') | |
31b59b47 | 704 | expect(video.nsfw).to.be.truthy |
7b1f49de C |
705 | expect(video.description).to.equal('hello everybody') |
706 | expect(video.podHost).to.equal('localhost:9001') | |
707 | expect(video.author).to.equal('root') | |
708 | expect(video.isLocal).to.be.true | |
709 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ]) | |
710 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | |
79066fdf | 711 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true |
7b1f49de C |
712 | |
713 | done() | |
714 | }) | |
715 | }) | |
716 | }) | |
717 | ||
d38b8281 C |
718 | it('Should like a video', function (done) { |
719 | videosUtils.rateVideo(server.url, server.accessToken, videoId, 'like', function (err) { | |
720 | if (err) throw err | |
721 | ||
722 | videosUtils.getVideo(server.url, videoId, function (err, res) { | |
723 | if (err) throw err | |
724 | ||
725 | const video = res.body | |
726 | ||
727 | expect(video.likes).to.equal(1) | |
728 | expect(video.dislikes).to.equal(0) | |
729 | ||
730 | done() | |
731 | }) | |
732 | }) | |
733 | }) | |
734 | ||
735 | it('Should dislike the same video', function (done) { | |
736 | videosUtils.rateVideo(server.url, server.accessToken, videoId, 'dislike', function (err) { | |
737 | if (err) throw err | |
738 | ||
739 | videosUtils.getVideo(server.url, videoId, function (err, res) { | |
740 | if (err) throw err | |
741 | ||
742 | const video = res.body | |
743 | ||
744 | expect(video.likes).to.equal(0) | |
745 | expect(video.dislikes).to.equal(1) | |
746 | ||
747 | done() | |
748 | }) | |
749 | }) | |
750 | }) | |
751 | ||
9f10b292 | 752 | after(function (done) { |
0c1cbbfe | 753 | process.kill(-server.app.pid) |
8c308c2b | 754 | |
9f10b292 C |
755 | // Keep the logs if the test failed |
756 | if (this.ok) { | |
8d309058 | 757 | serversUtils.flushTests(done) |
9f10b292 C |
758 | } else { |
759 | done() | |
760 | } | |
8c308c2b | 761 | }) |
9f10b292 | 762 | }) |