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