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