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