]>
Commit | Line | Data |
---|---|---|
9f10b292 C |
1 | 'use strict' |
2 | ||
f0f5567b | 3 | const chai = require('chai') |
1a42c9e2 | 4 | const each = require('async/each') |
f0f5567b C |
5 | const expect = chai.expect |
6 | const fs = require('fs') | |
3a8a8b51 | 7 | const keyBy = require('lodash/keyBy') |
f0f5567b | 8 | const pathUtils = require('path') |
1a42c9e2 | 9 | const series = require('async/series') |
9f10b292 | 10 | |
f0f5567b | 11 | const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent')) |
9f10b292 C |
12 | webtorrent.silent = true |
13 | ||
f0f5567b | 14 | const utils = require('./utils') |
9f10b292 C |
15 | |
16 | describe('Test a single pod', function () { | |
0c1cbbfe | 17 | let server = null |
bc503c2a | 18 | let videoId = -1 |
fbf1134e | 19 | let videosListBase = null |
9f10b292 C |
20 | |
21 | before(function (done) { | |
22 | this.timeout(20000) | |
23 | ||
1a42c9e2 | 24 | series([ |
9f10b292 C |
25 | function (next) { |
26 | utils.flushTests(next) | |
27 | }, | |
28 | function (next) { | |
0c1cbbfe C |
29 | utils.runServer(1, function (server1) { |
30 | server = server1 | |
31 | next() | |
32 | }) | |
33 | }, | |
34 | function (next) { | |
35 | utils.loginAndGetAccessToken(server, function (err, token) { | |
36 | if (err) throw err | |
b6c6f935 | 37 | server.accessToken = token |
9f10b292 C |
38 | next() |
39 | }) | |
40 | }, | |
41 | function (next) { | |
42 | webtorrent.create({ host: 'client', port: '1' }, next) | |
43 | } | |
44 | ], done) | |
45 | }) | |
8c308c2b | 46 | |
9f10b292 | 47 | it('Should not have videos', function (done) { |
0c1cbbfe | 48 | utils.getVideosList(server.url, function (err, res) { |
9f10b292 | 49 | if (err) throw err |
8c308c2b | 50 | |
68ce3ae0 C |
51 | expect(res.body.total).to.equal(0) |
52 | expect(res.body.data).to.be.an('array') | |
53 | expect(res.body.data.length).to.equal(0) | |
8c308c2b | 54 | |
9f10b292 | 55 | done() |
8c308c2b | 56 | }) |
9f10b292 | 57 | }) |
8c308c2b | 58 | |
9f10b292 C |
59 | it('Should upload the video', function (done) { |
60 | this.timeout(5000) | |
be587647 C |
61 | const name = 'my super name' |
62 | const description = 'my super description' | |
63 | const tags = [ 'tag1', 'tag2', 'tag3' ] | |
64 | const file = 'video_short.webm' | |
65 | utils.uploadVideo(server.url, server.accessToken, name, description, tags, file, done) | |
9f10b292 | 66 | }) |
8c308c2b | 67 | |
9f10b292 C |
68 | it('Should seed the uploaded video', function (done) { |
69 | // Yes, this could be long | |
70 | this.timeout(60000) | |
8c308c2b | 71 | |
0c1cbbfe | 72 | utils.getVideosList(server.url, function (err, res) { |
9f10b292 | 73 | if (err) throw err |
8c308c2b | 74 | |
68ce3ae0 C |
75 | expect(res.body.total).to.equal(1) |
76 | expect(res.body.data).to.be.an('array') | |
77 | expect(res.body.data.length).to.equal(1) | |
8c308c2b | 78 | |
68ce3ae0 | 79 | const video = res.body.data[0] |
9f10b292 C |
80 | expect(video.name).to.equal('my super name') |
81 | expect(video.description).to.equal('my super description') | |
68ce3ae0 | 82 | expect(video.podUrl).to.equal('localhost:9001') |
9f10b292 | 83 | expect(video.magnetUri).to.exist |
6d8ada5f C |
84 | expect(video.author).to.equal('root') |
85 | expect(video.isLocal).to.be.true | |
be587647 | 86 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) |
bb10240e | 87 | expect(utils.dateIsValid(video.createdDate)).to.be.true |
8c308c2b | 88 | |
36d56024 | 89 | utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { |
9e5f3740 C |
90 | if (err) throw err |
91 | expect(test).to.equal(true) | |
2df82d42 | 92 | |
bc503c2a | 93 | videoId = video.id |
2df82d42 | 94 | |
9e5f3740 C |
95 | webtorrent.add(video.magnetUri, function (torrent) { |
96 | expect(torrent.files).to.exist | |
97 | expect(torrent.files.length).to.equal(1) | |
98 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
99 | ||
b6c6f935 C |
100 | // We remove it because we'll add it again |
101 | webtorrent.remove(video.magnetUri, done) | |
9e5f3740 | 102 | }) |
2df82d42 C |
103 | }) |
104 | }) | |
105 | }) | |
106 | ||
107 | it('Should get the video', function (done) { | |
108 | // Yes, this could be long | |
109 | this.timeout(60000) | |
110 | ||
bc503c2a | 111 | utils.getVideo(server.url, videoId, function (err, res) { |
2df82d42 C |
112 | if (err) throw err |
113 | ||
114 | const video = res.body | |
115 | expect(video.name).to.equal('my super name') | |
116 | expect(video.description).to.equal('my super description') | |
68ce3ae0 | 117 | expect(video.podUrl).to.equal('localhost:9001') |
2df82d42 | 118 | expect(video.magnetUri).to.exist |
6d8ada5f C |
119 | expect(video.author).to.equal('root') |
120 | expect(video.isLocal).to.be.true | |
be587647 | 121 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) |
bb10240e | 122 | expect(utils.dateIsValid(video.createdDate)).to.be.true |
8c308c2b | 123 | |
36d56024 | 124 | utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { |
9e5f3740 C |
125 | if (err) throw err |
126 | expect(test).to.equal(true) | |
8c308c2b | 127 | |
9e5f3740 C |
128 | webtorrent.add(video.magnetUri, function (torrent) { |
129 | expect(torrent.files).to.exist | |
130 | expect(torrent.files.length).to.equal(1) | |
131 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
132 | ||
133 | done() | |
134 | }) | |
876d1bcf | 135 | }) |
8c308c2b | 136 | }) |
9f10b292 | 137 | }) |
8c308c2b | 138 | |
46246b5f | 139 | it('Should search the video by name by default', function (done) { |
0c1cbbfe | 140 | utils.searchVideo(server.url, 'my', function (err, res) { |
9f10b292 | 141 | if (err) throw err |
4d5f8138 | 142 | |
68ce3ae0 C |
143 | expect(res.body.total).to.equal(1) |
144 | expect(res.body.data).to.be.an('array') | |
145 | expect(res.body.data.length).to.equal(1) | |
4d5f8138 | 146 | |
68ce3ae0 | 147 | const video = res.body.data[0] |
9f10b292 C |
148 | expect(video.name).to.equal('my super name') |
149 | expect(video.description).to.equal('my super description') | |
68ce3ae0 | 150 | expect(video.podUrl).to.equal('localhost:9001') |
6d8ada5f C |
151 | expect(video.author).to.equal('root') |
152 | expect(video.isLocal).to.be.true | |
be587647 | 153 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) |
bb10240e | 154 | expect(utils.dateIsValid(video.createdDate)).to.be.true |
4d5f8138 | 155 | |
36d56024 | 156 | utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { |
9e5f3740 C |
157 | if (err) throw err |
158 | expect(test).to.equal(true) | |
159 | ||
160 | done() | |
161 | }) | |
4d5f8138 | 162 | }) |
9f10b292 | 163 | }) |
4d5f8138 | 164 | |
46246b5f C |
165 | it('Should search the video by podUrl', function (done) { |
166 | utils.searchVideo(server.url, '9001', 'podUrl', function (err, res) { | |
167 | if (err) throw err | |
168 | ||
169 | expect(res.body.total).to.equal(1) | |
170 | expect(res.body.data).to.be.an('array') | |
171 | expect(res.body.data.length).to.equal(1) | |
172 | ||
173 | const video = res.body.data[0] | |
174 | expect(video.name).to.equal('my super name') | |
175 | expect(video.description).to.equal('my super description') | |
176 | expect(video.podUrl).to.equal('localhost:9001') | |
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' ]) |
46246b5f C |
180 | expect(utils.dateIsValid(video.createdDate)).to.be.true |
181 | ||
182 | utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { | |
183 | if (err) throw err | |
184 | expect(test).to.equal(true) | |
185 | ||
186 | done() | |
187 | }) | |
188 | }) | |
189 | }) | |
190 | ||
8d199cb8 C |
191 | it('Should search the video by tag', function (done) { |
192 | utils.searchVideo(server.url, 'tag1', 'tags', function (err, res) { | |
193 | if (err) throw err | |
194 | ||
195 | expect(res.body.total).to.equal(1) | |
196 | expect(res.body.data).to.be.an('array') | |
197 | expect(res.body.data.length).to.equal(1) | |
198 | ||
199 | const video = res.body.data[0] | |
200 | expect(video.name).to.equal('my super name') | |
201 | expect(video.description).to.equal('my super description') | |
202 | expect(video.podUrl).to.equal('localhost:9001') | |
203 | expect(video.author).to.equal('root') | |
204 | expect(video.isLocal).to.be.true | |
205 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | |
206 | expect(utils.dateIsValid(video.createdDate)).to.be.true | |
207 | ||
208 | utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { | |
209 | if (err) throw err | |
210 | expect(test).to.equal(true) | |
211 | ||
212 | done() | |
213 | }) | |
214 | }) | |
215 | }) | |
216 | ||
46246b5f | 217 | it('Should not find a search by name by default', function (done) { |
0c1cbbfe | 218 | utils.searchVideo(server.url, 'hello', function (err, res) { |
9f10b292 | 219 | if (err) throw err |
4d5f8138 | 220 | |
68ce3ae0 C |
221 | expect(res.body.total).to.equal(0) |
222 | expect(res.body.data).to.be.an('array') | |
223 | expect(res.body.data.length).to.equal(0) | |
4d5f8138 | 224 | |
9f10b292 | 225 | done() |
4d5f8138 | 226 | }) |
9f10b292 | 227 | }) |
4d5f8138 | 228 | |
46246b5f C |
229 | it('Should not find a search by author', function (done) { |
230 | utils.searchVideo(server.url, 'hello', 'author', function (err, res) { | |
231 | if (err) throw err | |
232 | ||
233 | expect(res.body.total).to.equal(0) | |
234 | expect(res.body.data).to.be.an('array') | |
235 | expect(res.body.data.length).to.equal(0) | |
236 | ||
237 | done() | |
238 | }) | |
239 | }) | |
240 | ||
8d199cb8 C |
241 | it('Should not find a search by tag', function (done) { |
242 | utils.searchVideo(server.url, 'tag', 'tags', function (err, res) { | |
243 | if (err) throw err | |
244 | ||
245 | expect(res.body.total).to.equal(0) | |
246 | expect(res.body.data).to.be.an('array') | |
247 | expect(res.body.data.length).to.equal(0) | |
248 | ||
249 | done() | |
250 | }) | |
251 | }) | |
252 | ||
9f10b292 | 253 | it('Should remove the video', function (done) { |
bc503c2a | 254 | utils.removeVideo(server.url, server.accessToken, videoId, function (err) { |
9f10b292 | 255 | if (err) throw err |
f5a60a51 | 256 | |
3d446a26 | 257 | fs.readdir(pathUtils.join(__dirname, '../../../test1/uploads/'), function (err, files) { |
9f10b292 | 258 | if (err) throw err |
f5a60a51 | 259 | |
9f10b292 C |
260 | expect(files.length).to.equal(0) |
261 | done() | |
876d1bcf | 262 | }) |
8c308c2b | 263 | }) |
9f10b292 | 264 | }) |
8c308c2b | 265 | |
9f10b292 | 266 | it('Should not have videos', function (done) { |
0c1cbbfe | 267 | utils.getVideosList(server.url, function (err, res) { |
9f10b292 | 268 | if (err) throw err |
8c308c2b | 269 | |
68ce3ae0 C |
270 | expect(res.body.total).to.equal(0) |
271 | expect(res.body.data).to.be.an('array') | |
272 | expect(res.body.data.length).to.equal(0) | |
8c308c2b | 273 | |
9f10b292 | 274 | done() |
8c308c2b | 275 | }) |
9f10b292 | 276 | }) |
8c308c2b | 277 | |
3a8a8b51 C |
278 | it('Should upload 6 videos', function (done) { |
279 | this.timeout(25000) | |
280 | const videos = [ | |
281 | 'video_short.mp4', 'video_short.ogv', 'video_short.webm', | |
282 | 'video_short1.webm', 'video_short2.webm', 'video_short3.webm' | |
283 | ] | |
1a42c9e2 | 284 | each(videos, function (video, callbackEach) { |
be587647 C |
285 | const name = video + ' name' |
286 | const description = video + ' description' | |
287 | const tags = [ 'tag1', 'tag2', 'tag3' ] | |
288 | ||
289 | utils.uploadVideo(server.url, server.accessToken, name, description, tags, video, callbackEach) | |
3a8a8b51 C |
290 | }, done) |
291 | }) | |
292 | ||
293 | it('Should have the correct durations', function (done) { | |
294 | utils.getVideosList(server.url, function (err, res) { | |
295 | if (err) throw err | |
296 | ||
68ce3ae0 C |
297 | expect(res.body.total).to.equal(6) |
298 | const videos = res.body.data | |
3a8a8b51 C |
299 | expect(videos).to.be.an('array') |
300 | expect(videos.length).to.equal(6) | |
301 | ||
bc503c2a C |
302 | const videosByName = keyBy(videos, 'name') |
303 | expect(videosByName['video_short.mp4 name'].duration).to.equal(5) | |
304 | expect(videosByName['video_short.ogv name'].duration).to.equal(5) | |
305 | expect(videosByName['video_short.webm name'].duration).to.equal(5) | |
306 | expect(videosByName['video_short1.webm name'].duration).to.equal(10) | |
307 | expect(videosByName['video_short2.webm name'].duration).to.equal(5) | |
308 | expect(videosByName['video_short3.webm name'].duration).to.equal(5) | |
3a8a8b51 C |
309 | |
310 | done() | |
311 | }) | |
312 | }) | |
313 | ||
9e5f3740 C |
314 | it('Should have the correct thumbnails', function (done) { |
315 | utils.getVideosList(server.url, function (err, res) { | |
fbf1134e C |
316 | if (err) throw err |
317 | ||
68ce3ae0 | 318 | const videos = res.body.data |
fbf1134e C |
319 | // For the next test |
320 | videosListBase = videos | |
9e5f3740 | 321 | |
1a42c9e2 | 322 | each(videos, function (video, callbackEach) { |
9e5f3740 | 323 | if (err) throw err |
bc503c2a | 324 | const videoName = video.name.replace(' name', '') |
9e5f3740 | 325 | |
bc503c2a | 326 | utils.testImage(server.url, videoName, video.thumbnailPath, function (err, test) { |
9e5f3740 C |
327 | if (err) throw err |
328 | ||
329 | expect(test).to.equal(true) | |
bc503c2a | 330 | callbackEach() |
9e5f3740 C |
331 | }) |
332 | }, done) | |
333 | }) | |
334 | }) | |
335 | ||
fbf1134e C |
336 | it('Should list only the two first videos', function (done) { |
337 | utils.getVideosListPagination(server.url, 0, 2, function (err, res) { | |
338 | if (err) throw err | |
339 | ||
68ce3ae0 C |
340 | const videos = res.body.data |
341 | expect(res.body.total).to.equal(6) | |
fbf1134e C |
342 | expect(videos.length).to.equal(2) |
343 | expect(videos[0].name === videosListBase[0].name) | |
344 | expect(videos[1].name === videosListBase[1].name) | |
345 | ||
346 | done() | |
347 | }) | |
348 | }) | |
349 | ||
350 | it('Should list only the next three videos', function (done) { | |
351 | utils.getVideosListPagination(server.url, 2, 3, function (err, res) { | |
352 | if (err) throw err | |
353 | ||
68ce3ae0 C |
354 | const videos = res.body.data |
355 | expect(res.body.total).to.equal(6) | |
022856f8 | 356 | expect(videos.length).to.equal(3) |
fbf1134e C |
357 | expect(videos[0].name === videosListBase[2].name) |
358 | expect(videos[1].name === videosListBase[3].name) | |
359 | expect(videos[2].name === videosListBase[4].name) | |
360 | ||
361 | done() | |
362 | }) | |
363 | }) | |
364 | ||
365 | it('Should list the last video', function (done) { | |
366 | utils.getVideosListPagination(server.url, 5, 6, function (err, res) { | |
367 | if (err) throw err | |
368 | ||
68ce3ae0 C |
369 | const videos = res.body.data |
370 | expect(res.body.total).to.equal(6) | |
fbf1134e C |
371 | expect(videos.length).to.equal(1) |
372 | expect(videos[0].name === videosListBase[5].name) | |
373 | ||
374 | done() | |
375 | }) | |
376 | }) | |
377 | ||
378 | it('Should search the first video', function (done) { | |
46246b5f | 379 | utils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, function (err, res) { |
fbf1134e C |
380 | if (err) throw err |
381 | ||
68ce3ae0 C |
382 | const videos = res.body.data |
383 | expect(res.body.total).to.equal(4) | |
fbf1134e C |
384 | expect(videos.length).to.equal(1) |
385 | expect(videos[0].name === 'video_short.webm name') | |
386 | ||
387 | done() | |
388 | }) | |
389 | }) | |
390 | ||
391 | it('Should search the last two videos', function (done) { | |
46246b5f | 392 | utils.searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, function (err, res) { |
fbf1134e C |
393 | if (err) throw err |
394 | ||
68ce3ae0 C |
395 | const videos = res.body.data |
396 | expect(res.body.total).to.equal(4) | |
fbf1134e C |
397 | expect(videos.length).to.equal(2) |
398 | expect(videos[0].name === 'video_short2.webm name') | |
399 | expect(videos[1].name === 'video_short3.webm name') | |
400 | ||
401 | done() | |
402 | }) | |
403 | }) | |
404 | ||
46246b5f C |
405 | it('Should search all the webm videos', function (done) { |
406 | utils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 15, 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(4) | |
fbf1134e C |
411 | expect(videos.length).to.equal(4) |
412 | ||
413 | done() | |
414 | }) | |
415 | }) | |
416 | ||
46246b5f C |
417 | it('Should search all the root author videos', function (done) { |
418 | utils.searchVideoWithPagination(server.url, 'root', 'author', 0, 15, function (err, res) { | |
419 | if (err) throw err | |
420 | ||
421 | const videos = res.body.data | |
422 | expect(res.body.total).to.equal(6) | |
423 | expect(videos.length).to.equal(6) | |
424 | ||
425 | done() | |
426 | }) | |
427 | }) | |
428 | ||
429 | it('Should search all the 9001 port videos', function (done) { | |
430 | utils.searchVideoWithPagination(server.url, '9001', 'podUrl', 0, 15, function (err, res) { | |
431 | if (err) throw err | |
432 | ||
433 | const videos = res.body.data | |
434 | expect(res.body.total).to.equal(6) | |
435 | expect(videos.length).to.equal(6) | |
436 | ||
437 | done() | |
438 | }) | |
439 | }) | |
440 | ||
441 | it('Should search all the localhost videos', function (done) { | |
442 | utils.searchVideoWithPagination(server.url, 'localhost', 'podUrl', 0, 15, function (err, res) { | |
443 | if (err) throw err | |
444 | ||
445 | const videos = res.body.data | |
446 | expect(res.body.total).to.equal(6) | |
447 | expect(videos.length).to.equal(6) | |
448 | ||
449 | done() | |
450 | }) | |
451 | }) | |
452 | ||
453 | it('Should search the good magnetUri video', function (done) { | |
454 | const video = videosListBase[0] | |
455 | utils.searchVideoWithPagination(server.url, encodeURIComponent(video.magnetUri), 'magnetUri', 0, 15, function (err, res) { | |
456 | if (err) throw err | |
457 | ||
458 | const videos = res.body.data | |
459 | expect(res.body.total).to.equal(1) | |
460 | expect(videos.length).to.equal(1) | |
461 | expect(videos[0].name).to.equal(video.name) | |
462 | ||
463 | done() | |
464 | }) | |
465 | }) | |
466 | ||
a877d5ac C |
467 | it('Should list and sort by name in descending order', function (done) { |
468 | utils.getVideosListSort(server.url, '-name', function (err, res) { | |
469 | if (err) throw err | |
470 | ||
68ce3ae0 C |
471 | const videos = res.body.data |
472 | expect(res.body.total).to.equal(6) | |
a877d5ac C |
473 | expect(videos.length).to.equal(6) |
474 | expect(videos[5].name === 'video_short.mp4 name') | |
475 | expect(videos[4].name === 'video_short.ogv name') | |
476 | expect(videos[3].name === 'video_short.webm name') | |
477 | expect(videos[2].name === 'video_short1.webm name') | |
478 | expect(videos[1].name === 'video_short2.webm name') | |
479 | expect(videos[0].name === 'video_short3.webm name') | |
480 | ||
481 | done() | |
482 | }) | |
483 | }) | |
484 | ||
485 | it('Should search and sort by name in ascending order', function (done) { | |
486 | utils.searchVideoWithSort(server.url, 'webm', 'name', function (err, res) { | |
487 | if (err) throw err | |
488 | ||
68ce3ae0 C |
489 | const videos = res.body.data |
490 | expect(res.body.total).to.equal(4) | |
a877d5ac C |
491 | expect(videos.length).to.equal(4) |
492 | ||
493 | expect(videos[0].name === 'video_short.webm name') | |
494 | expect(videos[1].name === 'video_short1.webm name') | |
495 | expect(videos[2].name === 'video_short2.webm name') | |
496 | expect(videos[3].name === 'video_short3.webm name') | |
497 | ||
498 | done() | |
499 | }) | |
500 | }) | |
501 | ||
9f10b292 | 502 | after(function (done) { |
0c1cbbfe | 503 | process.kill(-server.app.pid) |
9f10b292 | 504 | process.kill(-webtorrent.app.pid) |
8c308c2b | 505 | |
9f10b292 C |
506 | // Keep the logs if the test failed |
507 | if (this.ok) { | |
508 | utils.flushTests(done) | |
509 | } else { | |
510 | done() | |
511 | } | |
8c308c2b | 512 | }) |
9f10b292 | 513 | }) |