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