]>
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 | |
46246b5f | 132 | it('Should search the video by name by default', function (done) { |
8d309058 | 133 | videosUtils.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') | |
a4254ea1 | 143 | expect(video.podHost).to.equal('localhost:9001') |
6d8ada5f C |
144 | expect(video.author).to.equal('root') |
145 | expect(video.isLocal).to.be.true | |
be587647 | 146 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) |
feb4bdfd | 147 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true |
79066fdf | 148 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true |
4d5f8138 | 149 | |
8d309058 | 150 | videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { |
9e5f3740 C |
151 | if (err) throw err |
152 | expect(test).to.equal(true) | |
153 | ||
154 | done() | |
155 | }) | |
4d5f8138 | 156 | }) |
9f10b292 | 157 | }) |
4d5f8138 | 158 | |
7920c273 C |
159 | // Not implemented yet |
160 | // it('Should search the video by podHost', function (done) { | |
161 | // videosUtils.searchVideo(server.url, '9001', 'host', function (err, res) { | |
162 | // if (err) throw err | |
163 | ||
164 | // expect(res.body.total).to.equal(1) | |
165 | // expect(res.body.data).to.be.an('array') | |
166 | // expect(res.body.data.length).to.equal(1) | |
167 | ||
168 | // const video = res.body.data[0] | |
169 | // expect(video.name).to.equal('my super name') | |
170 | // expect(video.description).to.equal('my super description') | |
171 | // expect(video.podHost).to.equal('localhost:9001') | |
172 | // expect(video.author).to.equal('root') | |
173 | // expect(video.isLocal).to.be.true | |
174 | // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | |
175 | // expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | |
79066fdf | 176 | // expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true |
7920c273 C |
177 | |
178 | // videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { | |
179 | // if (err) throw err | |
180 | // expect(test).to.equal(true) | |
181 | ||
182 | // done() | |
183 | // }) | |
184 | // }) | |
185 | // }) | |
46246b5f | 186 | |
8d199cb8 | 187 | it('Should search the video by tag', function (done) { |
8d309058 | 188 | videosUtils.searchVideo(server.url, 'tag1', 'tags', function (err, res) { |
8d199cb8 C |
189 | if (err) throw err |
190 | ||
191 | expect(res.body.total).to.equal(1) | |
192 | expect(res.body.data).to.be.an('array') | |
193 | expect(res.body.data.length).to.equal(1) | |
194 | ||
195 | const video = res.body.data[0] | |
196 | expect(video.name).to.equal('my super name') | |
197 | expect(video.description).to.equal('my super description') | |
a4254ea1 | 198 | expect(video.podHost).to.equal('localhost:9001') |
8d199cb8 C |
199 | expect(video.author).to.equal('root') |
200 | expect(video.isLocal).to.be.true | |
201 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | |
feb4bdfd | 202 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true |
79066fdf | 203 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true |
8d199cb8 | 204 | |
8d309058 | 205 | videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { |
8d199cb8 C |
206 | if (err) throw err |
207 | expect(test).to.equal(true) | |
208 | ||
209 | done() | |
210 | }) | |
211 | }) | |
212 | }) | |
213 | ||
46246b5f | 214 | it('Should not find a search by name by default', function (done) { |
8d309058 | 215 | videosUtils.searchVideo(server.url, 'hello', function (err, res) { |
9f10b292 | 216 | if (err) throw err |
4d5f8138 | 217 | |
68ce3ae0 C |
218 | expect(res.body.total).to.equal(0) |
219 | expect(res.body.data).to.be.an('array') | |
220 | expect(res.body.data.length).to.equal(0) | |
4d5f8138 | 221 | |
9f10b292 | 222 | done() |
4d5f8138 | 223 | }) |
9f10b292 | 224 | }) |
4d5f8138 | 225 | |
46246b5f | 226 | it('Should not find a search by author', function (done) { |
8d309058 | 227 | videosUtils.searchVideo(server.url, 'hello', 'author', function (err, res) { |
46246b5f C |
228 | if (err) throw err |
229 | ||
230 | expect(res.body.total).to.equal(0) | |
231 | expect(res.body.data).to.be.an('array') | |
232 | expect(res.body.data.length).to.equal(0) | |
233 | ||
234 | done() | |
235 | }) | |
236 | }) | |
237 | ||
8d199cb8 | 238 | it('Should not find a search by tag', function (done) { |
7920c273 | 239 | videosUtils.searchVideo(server.url, 'hello', 'tags', function (err, res) { |
8d199cb8 C |
240 | if (err) throw err |
241 | ||
242 | expect(res.body.total).to.equal(0) | |
243 | expect(res.body.data).to.be.an('array') | |
244 | expect(res.body.data.length).to.equal(0) | |
245 | ||
246 | done() | |
247 | }) | |
248 | }) | |
249 | ||
9f10b292 | 250 | it('Should remove the video', function (done) { |
8d309058 | 251 | videosUtils.removeVideo(server.url, server.accessToken, videoId, function (err) { |
9f10b292 | 252 | if (err) throw err |
f5a60a51 | 253 | |
15103f11 | 254 | fs.readdir(pathUtils.join(__dirname, '..', '..', '..', 'test1/videos/'), function (err, files) { |
9f10b292 | 255 | if (err) throw err |
f5a60a51 | 256 | |
9f10b292 | 257 | expect(files.length).to.equal(0) |
b3d92510 | 258 | |
15103f11 | 259 | fs.readdir(pathUtils.join(__dirname, '..', '..', '..', 'test1/thumbnails/'), function (err, files) { |
b3d92510 C |
260 | if (err) throw err |
261 | ||
262 | expect(files.length).to.equal(0) | |
263 | ||
264 | done() | |
265 | }) | |
876d1bcf | 266 | }) |
8c308c2b | 267 | }) |
9f10b292 | 268 | }) |
8c308c2b | 269 | |
9f10b292 | 270 | it('Should not have videos', function (done) { |
8d309058 | 271 | videosUtils.getVideosList(server.url, function (err, res) { |
9f10b292 | 272 | if (err) throw err |
8c308c2b | 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) | |
8c308c2b | 277 | |
9f10b292 | 278 | done() |
8c308c2b | 279 | }) |
9f10b292 | 280 | }) |
8c308c2b | 281 | |
3a8a8b51 C |
282 | it('Should upload 6 videos', function (done) { |
283 | this.timeout(25000) | |
284 | const videos = [ | |
285 | 'video_short.mp4', 'video_short.ogv', 'video_short.webm', | |
286 | 'video_short1.webm', 'video_short2.webm', 'video_short3.webm' | |
287 | ] | |
1a42c9e2 | 288 | each(videos, function (video, callbackEach) { |
be587647 C |
289 | const name = video + ' name' |
290 | const description = video + ' description' | |
291 | const tags = [ 'tag1', 'tag2', 'tag3' ] | |
292 | ||
8d309058 | 293 | videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, video, callbackEach) |
3a8a8b51 C |
294 | }, done) |
295 | }) | |
296 | ||
297 | it('Should have the correct durations', function (done) { | |
8d309058 | 298 | videosUtils.getVideosList(server.url, function (err, res) { |
3a8a8b51 C |
299 | if (err) throw err |
300 | ||
68ce3ae0 C |
301 | expect(res.body.total).to.equal(6) |
302 | const videos = res.body.data | |
3a8a8b51 C |
303 | expect(videos).to.be.an('array') |
304 | expect(videos.length).to.equal(6) | |
305 | ||
bc503c2a C |
306 | const videosByName = keyBy(videos, 'name') |
307 | expect(videosByName['video_short.mp4 name'].duration).to.equal(5) | |
308 | expect(videosByName['video_short.ogv name'].duration).to.equal(5) | |
309 | expect(videosByName['video_short.webm name'].duration).to.equal(5) | |
310 | expect(videosByName['video_short1.webm name'].duration).to.equal(10) | |
311 | expect(videosByName['video_short2.webm name'].duration).to.equal(5) | |
312 | expect(videosByName['video_short3.webm name'].duration).to.equal(5) | |
3a8a8b51 C |
313 | |
314 | done() | |
315 | }) | |
316 | }) | |
317 | ||
9e5f3740 | 318 | it('Should have the correct thumbnails', function (done) { |
8d309058 | 319 | videosUtils.getVideosList(server.url, function (err, res) { |
fbf1134e C |
320 | if (err) throw err |
321 | ||
68ce3ae0 | 322 | const videos = res.body.data |
fbf1134e C |
323 | // For the next test |
324 | videosListBase = videos | |
9e5f3740 | 325 | |
1a42c9e2 | 326 | each(videos, function (video, callbackEach) { |
9e5f3740 | 327 | if (err) throw err |
bc503c2a | 328 | const videoName = video.name.replace(' name', '') |
9e5f3740 | 329 | |
8d309058 | 330 | videosUtils.testVideoImage(server.url, videoName, video.thumbnailPath, function (err, test) { |
9e5f3740 C |
331 | if (err) throw err |
332 | ||
333 | expect(test).to.equal(true) | |
bc503c2a | 334 | callbackEach() |
9e5f3740 C |
335 | }) |
336 | }, done) | |
337 | }) | |
338 | }) | |
339 | ||
fbf1134e | 340 | it('Should list only the two first videos', function (done) { |
91cc839a | 341 | videosUtils.getVideosListPagination(server.url, 0, 2, 'name', 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(6) | |
fbf1134e | 346 | expect(videos.length).to.equal(2) |
91cc839a C |
347 | expect(videos[0].name).to.equal(videosListBase[0].name) |
348 | expect(videos[1].name).to.equal(videosListBase[1].name) | |
fbf1134e C |
349 | |
350 | done() | |
351 | }) | |
352 | }) | |
353 | ||
354 | it('Should list only the next three videos', function (done) { | |
91cc839a | 355 | videosUtils.getVideosListPagination(server.url, 2, 3, 'name', 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(6) | |
022856f8 | 360 | expect(videos.length).to.equal(3) |
91cc839a C |
361 | expect(videos[0].name).to.equal(videosListBase[2].name) |
362 | expect(videos[1].name).to.equal(videosListBase[3].name) | |
363 | expect(videos[2].name).to.equal(videosListBase[4].name) | |
fbf1134e C |
364 | |
365 | done() | |
366 | }) | |
367 | }) | |
368 | ||
369 | it('Should list the last video', function (done) { | |
91cc839a | 370 | videosUtils.getVideosListPagination(server.url, 5, 6, 'name', function (err, res) { |
fbf1134e C |
371 | if (err) throw err |
372 | ||
68ce3ae0 C |
373 | const videos = res.body.data |
374 | expect(res.body.total).to.equal(6) | |
fbf1134e | 375 | expect(videos.length).to.equal(1) |
91cc839a | 376 | expect(videos[0].name).to.equal(videosListBase[5].name) |
fbf1134e C |
377 | |
378 | done() | |
379 | }) | |
380 | }) | |
381 | ||
382 | it('Should search the first video', function (done) { | |
91cc839a | 383 | videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, 'name', function (err, res) { |
fbf1134e C |
384 | if (err) throw err |
385 | ||
68ce3ae0 C |
386 | const videos = res.body.data |
387 | expect(res.body.total).to.equal(4) | |
fbf1134e | 388 | expect(videos.length).to.equal(1) |
91cc839a | 389 | expect(videos[0].name).to.equal('video_short1.webm name') |
fbf1134e C |
390 | |
391 | done() | |
392 | }) | |
393 | }) | |
394 | ||
395 | it('Should search the last two videos', function (done) { | |
91cc839a | 396 | videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, 'name', function (err, res) { |
fbf1134e C |
397 | if (err) throw err |
398 | ||
68ce3ae0 C |
399 | const videos = res.body.data |
400 | expect(res.body.total).to.equal(4) | |
fbf1134e | 401 | expect(videos.length).to.equal(2) |
91cc839a C |
402 | expect(videos[0].name).to.equal('video_short3.webm name') |
403 | expect(videos[1].name).to.equal('video_short.webm name') | |
fbf1134e C |
404 | |
405 | done() | |
406 | }) | |
407 | }) | |
408 | ||
46246b5f | 409 | it('Should search all the webm videos', function (done) { |
8d309058 | 410 | videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 15, function (err, res) { |
fbf1134e C |
411 | if (err) throw err |
412 | ||
68ce3ae0 C |
413 | const videos = res.body.data |
414 | expect(res.body.total).to.equal(4) | |
fbf1134e C |
415 | expect(videos.length).to.equal(4) |
416 | ||
417 | done() | |
418 | }) | |
419 | }) | |
420 | ||
46246b5f | 421 | it('Should search all the root author videos', function (done) { |
8d309058 | 422 | videosUtils.searchVideoWithPagination(server.url, 'root', 'author', 0, 15, function (err, res) { |
46246b5f C |
423 | if (err) throw err |
424 | ||
425 | const videos = res.body.data | |
426 | expect(res.body.total).to.equal(6) | |
427 | expect(videos.length).to.equal(6) | |
428 | ||
429 | done() | |
430 | }) | |
431 | }) | |
432 | ||
7920c273 C |
433 | // Not implemented yet |
434 | // it('Should search all the 9001 port videos', function (done) { | |
435 | // videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15, function (err, res) { | |
436 | // if (err) throw err | |
46246b5f | 437 | |
7920c273 C |
438 | // const videos = res.body.data |
439 | // expect(res.body.total).to.equal(6) | |
440 | // expect(videos.length).to.equal(6) | |
46246b5f | 441 | |
7920c273 C |
442 | // done() |
443 | // }) | |
444 | // }) | |
46246b5f | 445 | |
7920c273 C |
446 | // it('Should search all the localhost videos', function (done) { |
447 | // videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15, function (err, res) { | |
448 | // if (err) throw err | |
46246b5f | 449 | |
7920c273 C |
450 | // const videos = res.body.data |
451 | // expect(res.body.total).to.equal(6) | |
452 | // expect(videos.length).to.equal(6) | |
46246b5f | 453 | |
7920c273 C |
454 | // done() |
455 | // }) | |
456 | // }) | |
46246b5f C |
457 | |
458 | it('Should search the good magnetUri video', function (done) { | |
459 | const video = videosListBase[0] | |
8d309058 | 460 | videosUtils.searchVideoWithPagination(server.url, encodeURIComponent(video.magnetUri), 'magnetUri', 0, 15, function (err, res) { |
46246b5f C |
461 | if (err) throw err |
462 | ||
463 | const videos = res.body.data | |
464 | expect(res.body.total).to.equal(1) | |
465 | expect(videos.length).to.equal(1) | |
466 | expect(videos[0].name).to.equal(video.name) | |
467 | ||
468 | done() | |
469 | }) | |
470 | }) | |
471 | ||
a877d5ac | 472 | it('Should list and sort by name in descending order', function (done) { |
8d309058 | 473 | videosUtils.getVideosListSort(server.url, '-name', function (err, res) { |
a877d5ac C |
474 | if (err) throw err |
475 | ||
68ce3ae0 C |
476 | const videos = res.body.data |
477 | expect(res.body.total).to.equal(6) | |
a877d5ac | 478 | expect(videos.length).to.equal(6) |
91cc839a C |
479 | expect(videos[0].name).to.equal('video_short.webm name') |
480 | expect(videos[1].name).to.equal('video_short.ogv name') | |
481 | expect(videos[2].name).to.equal('video_short.mp4 name') | |
482 | expect(videos[3].name).to.equal('video_short3.webm name') | |
483 | expect(videos[4].name).to.equal('video_short2.webm name') | |
484 | expect(videos[5].name).to.equal('video_short1.webm name') | |
a877d5ac C |
485 | |
486 | done() | |
487 | }) | |
488 | }) | |
489 | ||
490 | it('Should search and sort by name in ascending order', function (done) { | |
8d309058 | 491 | videosUtils.searchVideoWithSort(server.url, 'webm', 'name', function (err, res) { |
a877d5ac C |
492 | if (err) throw err |
493 | ||
68ce3ae0 C |
494 | const videos = res.body.data |
495 | expect(res.body.total).to.equal(4) | |
a877d5ac C |
496 | expect(videos.length).to.equal(4) |
497 | ||
91cc839a C |
498 | expect(videos[0].name).to.equal('video_short1.webm name') |
499 | expect(videos[1].name).to.equal('video_short2.webm name') | |
500 | expect(videos[2].name).to.equal('video_short3.webm name') | |
501 | expect(videos[3].name).to.equal('video_short.webm name') | |
a877d5ac | 502 | |
91cc839a | 503 | videoId = videos[2].id |
7b1f49de | 504 | |
a877d5ac C |
505 | done() |
506 | }) | |
507 | }) | |
508 | ||
7b1f49de C |
509 | it('Should update a video', function (done) { |
510 | const name = 'my super video updated' | |
511 | const description = 'my super description updated' | |
512 | const tags = [ 'tagup1', 'tagup2' ] | |
513 | ||
514 | videosUtils.updateVideo(server.url, server.accessToken, videoId, name, description, tags, done) | |
515 | }) | |
516 | ||
517 | it('Should have the video updated', function (done) { | |
7f4e7c36 C |
518 | this.timeout(60000) |
519 | ||
7b1f49de C |
520 | videosUtils.getVideo(server.url, videoId, function (err, res) { |
521 | if (err) throw err | |
522 | ||
523 | const video = res.body | |
524 | ||
525 | expect(video.name).to.equal('my super video updated') | |
526 | expect(video.description).to.equal('my super description updated') | |
527 | expect(video.podHost).to.equal('localhost:9001') | |
528 | expect(video.author).to.equal('root') | |
529 | expect(video.isLocal).to.be.true | |
530 | expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ]) | |
531 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | |
79066fdf | 532 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true |
7b1f49de | 533 | |
7f4e7c36 C |
534 | videosUtils.testVideoImage(server.url, 'video_short3.webm', video.thumbnailPath, function (err, test) { |
535 | if (err) throw err | |
536 | expect(test).to.equal(true) | |
537 | ||
7f4e7c36 C |
538 | webtorrent.add(video.magnetUri, function (torrent) { |
539 | expect(torrent.files).to.exist | |
540 | expect(torrent.files.length).to.equal(1) | |
541 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
542 | ||
543 | done() | |
544 | }) | |
545 | }) | |
7b1f49de C |
546 | }) |
547 | }) | |
548 | ||
549 | it('Should update only the tags of a video', function (done) { | |
550 | const tags = [ 'tag1', 'tag2', 'supertag' ] | |
551 | ||
552 | videosUtils.updateVideo(server.url, server.accessToken, videoId, null, null, tags, function (err) { | |
553 | if (err) throw err | |
554 | ||
555 | videosUtils.getVideo(server.url, videoId, function (err, res) { | |
556 | if (err) throw err | |
557 | ||
558 | const video = res.body | |
559 | ||
560 | expect(video.name).to.equal('my super video updated') | |
561 | expect(video.description).to.equal('my super description updated') | |
562 | expect(video.podHost).to.equal('localhost:9001') | |
563 | expect(video.author).to.equal('root') | |
564 | expect(video.isLocal).to.be.true | |
565 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ]) | |
566 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | |
79066fdf | 567 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true |
7b1f49de C |
568 | |
569 | done() | |
570 | }) | |
571 | }) | |
572 | }) | |
573 | ||
574 | it('Should update only the description of a video', function (done) { | |
575 | const description = 'hello everybody' | |
576 | ||
577 | videosUtils.updateVideo(server.url, server.accessToken, videoId, null, description, null, function (err) { | |
578 | if (err) throw err | |
579 | ||
580 | videosUtils.getVideo(server.url, videoId, function (err, res) { | |
581 | if (err) throw err | |
582 | ||
583 | const video = res.body | |
584 | ||
585 | expect(video.name).to.equal('my super video updated') | |
586 | expect(video.description).to.equal('hello everybody') | |
587 | expect(video.podHost).to.equal('localhost:9001') | |
588 | expect(video.author).to.equal('root') | |
589 | expect(video.isLocal).to.be.true | |
590 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ]) | |
591 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | |
79066fdf | 592 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true |
7b1f49de C |
593 | |
594 | done() | |
595 | }) | |
596 | }) | |
597 | }) | |
598 | ||
9f10b292 | 599 | after(function (done) { |
0c1cbbfe | 600 | process.kill(-server.app.pid) |
8c308c2b | 601 | |
9f10b292 C |
602 | // Keep the logs if the test failed |
603 | if (this.ok) { | |
8d309058 | 604 | serversUtils.flushTests(done) |
9f10b292 C |
605 | } else { |
606 | done() | |
607 | } | |
8c308c2b | 608 | }) |
9f10b292 | 609 | }) |