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