aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/singlePod.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-08-07 22:09:59 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-08-07 22:09:59 +0200
commit8d30905858245f12a42fc327d2d57cbfe062d548 (patch)
tree9bd590872fbb753782f2ebbb9516db0414022d70 /server/tests/api/singlePod.js
parent58b2ba55a90f05f24661e664b1fb0a3486f037e8 (diff)
downloadPeerTube-8d30905858245f12a42fc327d2d57cbfe062d548.tar.gz
PeerTube-8d30905858245f12a42fc327d2d57cbfe062d548.tar.zst
PeerTube-8d30905858245f12a42fc327d2d57cbfe062d548.zip
Server: split tests utils in multiple files
Diffstat (limited to 'server/tests/api/singlePod.js')
-rw-r--r--server/tests/api/singlePod.js90
1 files changed, 46 insertions, 44 deletions
diff --git a/server/tests/api/singlePod.js b/server/tests/api/singlePod.js
index 6ed719f87..573eaa3a8 100644
--- a/server/tests/api/singlePod.js
+++ b/server/tests/api/singlePod.js
@@ -8,11 +8,13 @@ const keyBy = require('lodash/keyBy')
8const pathUtils = require('path') 8const pathUtils = require('path')
9const series = require('async/series') 9const series = require('async/series')
10 10
11const loginUtils = require('../utils/login')
12const miscsUtils = require('../utils/miscs')
13const serversUtils = require('../utils/servers')
14const videosUtils = require('../utils/videos')
11const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent')) 15const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent'))
12webtorrent.silent = true 16webtorrent.silent = true
13 17
14const utils = require('./utils')
15
16describe('Test a single pod', function () { 18describe('Test a single pod', function () {
17 let server = null 19 let server = null
18 let videoId = -1 20 let videoId = -1
@@ -23,16 +25,16 @@ describe('Test a single pod', function () {
23 25
24 series([ 26 series([
25 function (next) { 27 function (next) {
26 utils.flushTests(next) 28 serversUtils.flushTests(next)
27 }, 29 },
28 function (next) { 30 function (next) {
29 utils.runServer(1, function (server1) { 31 serversUtils.runServer(1, function (server1) {
30 server = server1 32 server = server1
31 next() 33 next()
32 }) 34 })
33 }, 35 },
34 function (next) { 36 function (next) {
35 utils.loginAndGetAccessToken(server, function (err, token) { 37 loginUtils.loginAndGetAccessToken(server, function (err, token) {
36 if (err) throw err 38 if (err) throw err
37 server.accessToken = token 39 server.accessToken = token
38 next() 40 next()
@@ -45,7 +47,7 @@ describe('Test a single pod', function () {
45 }) 47 })
46 48
47 it('Should not have videos', function (done) { 49 it('Should not have videos', function (done) {
48 utils.getVideosList(server.url, function (err, res) { 50 videosUtils.getVideosList(server.url, function (err, res) {
49 if (err) throw err 51 if (err) throw err
50 52
51 expect(res.body.total).to.equal(0) 53 expect(res.body.total).to.equal(0)
@@ -62,14 +64,14 @@ describe('Test a single pod', function () {
62 const description = 'my super description' 64 const description = 'my super description'
63 const tags = [ 'tag1', 'tag2', 'tag3' ] 65 const tags = [ 'tag1', 'tag2', 'tag3' ]
64 const file = 'video_short.webm' 66 const file = 'video_short.webm'
65 utils.uploadVideo(server.url, server.accessToken, name, description, tags, file, done) 67 videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, file, done)
66 }) 68 })
67 69
68 it('Should seed the uploaded video', function (done) { 70 it('Should seed the uploaded video', function (done) {
69 // Yes, this could be long 71 // Yes, this could be long
70 this.timeout(60000) 72 this.timeout(60000)
71 73
72 utils.getVideosList(server.url, function (err, res) { 74 videosUtils.getVideosList(server.url, function (err, res) {
73 if (err) throw err 75 if (err) throw err
74 76
75 expect(res.body.total).to.equal(1) 77 expect(res.body.total).to.equal(1)
@@ -84,9 +86,9 @@ describe('Test a single pod', function () {
84 expect(video.author).to.equal('root') 86 expect(video.author).to.equal('root')
85 expect(video.isLocal).to.be.true 87 expect(video.isLocal).to.be.true
86 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) 88 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
87 expect(utils.dateIsValid(video.createdDate)).to.be.true 89 expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true
88 90
89 utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { 91 videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
90 if (err) throw err 92 if (err) throw err
91 expect(test).to.equal(true) 93 expect(test).to.equal(true)
92 94
@@ -108,7 +110,7 @@ describe('Test a single pod', function () {
108 // Yes, this could be long 110 // Yes, this could be long
109 this.timeout(60000) 111 this.timeout(60000)
110 112
111 utils.getVideo(server.url, videoId, function (err, res) { 113 videosUtils.getVideo(server.url, videoId, function (err, res) {
112 if (err) throw err 114 if (err) throw err
113 115
114 const video = res.body 116 const video = res.body
@@ -119,9 +121,9 @@ describe('Test a single pod', function () {
119 expect(video.author).to.equal('root') 121 expect(video.author).to.equal('root')
120 expect(video.isLocal).to.be.true 122 expect(video.isLocal).to.be.true
121 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) 123 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
122 expect(utils.dateIsValid(video.createdDate)).to.be.true 124 expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true
123 125
124 utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { 126 videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
125 if (err) throw err 127 if (err) throw err
126 expect(test).to.equal(true) 128 expect(test).to.equal(true)
127 129
@@ -137,7 +139,7 @@ describe('Test a single pod', function () {
137 }) 139 })
138 140
139 it('Should search the video by name by default', function (done) { 141 it('Should search the video by name by default', function (done) {
140 utils.searchVideo(server.url, 'my', function (err, res) { 142 videosUtils.searchVideo(server.url, 'my', function (err, res) {
141 if (err) throw err 143 if (err) throw err
142 144
143 expect(res.body.total).to.equal(1) 145 expect(res.body.total).to.equal(1)
@@ -151,9 +153,9 @@ describe('Test a single pod', function () {
151 expect(video.author).to.equal('root') 153 expect(video.author).to.equal('root')
152 expect(video.isLocal).to.be.true 154 expect(video.isLocal).to.be.true
153 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) 155 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
154 expect(utils.dateIsValid(video.createdDate)).to.be.true 156 expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true
155 157
156 utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { 158 videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
157 if (err) throw err 159 if (err) throw err
158 expect(test).to.equal(true) 160 expect(test).to.equal(true)
159 161
@@ -163,7 +165,7 @@ describe('Test a single pod', function () {
163 }) 165 })
164 166
165 it('Should search the video by podUrl', function (done) { 167 it('Should search the video by podUrl', function (done) {
166 utils.searchVideo(server.url, '9001', 'podUrl', function (err, res) { 168 videosUtils.searchVideo(server.url, '9001', 'podUrl', function (err, res) {
167 if (err) throw err 169 if (err) throw err
168 170
169 expect(res.body.total).to.equal(1) 171 expect(res.body.total).to.equal(1)
@@ -177,9 +179,9 @@ describe('Test a single pod', function () {
177 expect(video.author).to.equal('root') 179 expect(video.author).to.equal('root')
178 expect(video.isLocal).to.be.true 180 expect(video.isLocal).to.be.true
179 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) 181 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
180 expect(utils.dateIsValid(video.createdDate)).to.be.true 182 expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true
181 183
182 utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { 184 videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
183 if (err) throw err 185 if (err) throw err
184 expect(test).to.equal(true) 186 expect(test).to.equal(true)
185 187
@@ -189,7 +191,7 @@ describe('Test a single pod', function () {
189 }) 191 })
190 192
191 it('Should search the video by tag', function (done) { 193 it('Should search the video by tag', function (done) {
192 utils.searchVideo(server.url, 'tag1', 'tags', function (err, res) { 194 videosUtils.searchVideo(server.url, 'tag1', 'tags', function (err, res) {
193 if (err) throw err 195 if (err) throw err
194 196
195 expect(res.body.total).to.equal(1) 197 expect(res.body.total).to.equal(1)
@@ -203,9 +205,9 @@ describe('Test a single pod', function () {
203 expect(video.author).to.equal('root') 205 expect(video.author).to.equal('root')
204 expect(video.isLocal).to.be.true 206 expect(video.isLocal).to.be.true
205 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) 207 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
206 expect(utils.dateIsValid(video.createdDate)).to.be.true 208 expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true
207 209
208 utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { 210 videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
209 if (err) throw err 211 if (err) throw err
210 expect(test).to.equal(true) 212 expect(test).to.equal(true)
211 213
@@ -215,7 +217,7 @@ describe('Test a single pod', function () {
215 }) 217 })
216 218
217 it('Should not find a search by name by default', function (done) { 219 it('Should not find a search by name by default', function (done) {
218 utils.searchVideo(server.url, 'hello', function (err, res) { 220 videosUtils.searchVideo(server.url, 'hello', function (err, res) {
219 if (err) throw err 221 if (err) throw err
220 222
221 expect(res.body.total).to.equal(0) 223 expect(res.body.total).to.equal(0)
@@ -227,7 +229,7 @@ describe('Test a single pod', function () {
227 }) 229 })
228 230
229 it('Should not find a search by author', function (done) { 231 it('Should not find a search by author', function (done) {
230 utils.searchVideo(server.url, 'hello', 'author', function (err, res) { 232 videosUtils.searchVideo(server.url, 'hello', 'author', function (err, res) {
231 if (err) throw err 233 if (err) throw err
232 234
233 expect(res.body.total).to.equal(0) 235 expect(res.body.total).to.equal(0)
@@ -239,7 +241,7 @@ describe('Test a single pod', function () {
239 }) 241 })
240 242
241 it('Should not find a search by tag', function (done) { 243 it('Should not find a search by tag', function (done) {
242 utils.searchVideo(server.url, 'tag', 'tags', function (err, res) { 244 videosUtils.searchVideo(server.url, 'tag', 'tags', function (err, res) {
243 if (err) throw err 245 if (err) throw err
244 246
245 expect(res.body.total).to.equal(0) 247 expect(res.body.total).to.equal(0)
@@ -251,7 +253,7 @@ describe('Test a single pod', function () {
251 }) 253 })
252 254
253 it('Should remove the video', function (done) { 255 it('Should remove the video', function (done) {
254 utils.removeVideo(server.url, server.accessToken, videoId, function (err) { 256 videosUtils.removeVideo(server.url, server.accessToken, videoId, function (err) {
255 if (err) throw err 257 if (err) throw err
256 258
257 fs.readdir(pathUtils.join(__dirname, '../../../test1/uploads/'), function (err, files) { 259 fs.readdir(pathUtils.join(__dirname, '../../../test1/uploads/'), function (err, files) {
@@ -264,7 +266,7 @@ describe('Test a single pod', function () {
264 }) 266 })
265 267
266 it('Should not have videos', function (done) { 268 it('Should not have videos', function (done) {
267 utils.getVideosList(server.url, function (err, res) { 269 videosUtils.getVideosList(server.url, function (err, res) {
268 if (err) throw err 270 if (err) throw err
269 271
270 expect(res.body.total).to.equal(0) 272 expect(res.body.total).to.equal(0)
@@ -286,12 +288,12 @@ describe('Test a single pod', function () {
286 const description = video + ' description' 288 const description = video + ' description'
287 const tags = [ 'tag1', 'tag2', 'tag3' ] 289 const tags = [ 'tag1', 'tag2', 'tag3' ]
288 290
289 utils.uploadVideo(server.url, server.accessToken, name, description, tags, video, callbackEach) 291 videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, video, callbackEach)
290 }, done) 292 }, done)
291 }) 293 })
292 294
293 it('Should have the correct durations', function (done) { 295 it('Should have the correct durations', function (done) {
294 utils.getVideosList(server.url, function (err, res) { 296 videosUtils.getVideosList(server.url, function (err, res) {
295 if (err) throw err 297 if (err) throw err
296 298
297 expect(res.body.total).to.equal(6) 299 expect(res.body.total).to.equal(6)
@@ -312,7 +314,7 @@ describe('Test a single pod', function () {
312 }) 314 })
313 315
314 it('Should have the correct thumbnails', function (done) { 316 it('Should have the correct thumbnails', function (done) {
315 utils.getVideosList(server.url, function (err, res) { 317 videosUtils.getVideosList(server.url, function (err, res) {
316 if (err) throw err 318 if (err) throw err
317 319
318 const videos = res.body.data 320 const videos = res.body.data
@@ -323,7 +325,7 @@ describe('Test a single pod', function () {
323 if (err) throw err 325 if (err) throw err
324 const videoName = video.name.replace(' name', '') 326 const videoName = video.name.replace(' name', '')
325 327
326 utils.testImage(server.url, videoName, video.thumbnailPath, function (err, test) { 328 videosUtils.testVideoImage(server.url, videoName, video.thumbnailPath, function (err, test) {
327 if (err) throw err 329 if (err) throw err
328 330
329 expect(test).to.equal(true) 331 expect(test).to.equal(true)
@@ -334,7 +336,7 @@ describe('Test a single pod', function () {
334 }) 336 })
335 337
336 it('Should list only the two first videos', function (done) { 338 it('Should list only the two first videos', function (done) {
337 utils.getVideosListPagination(server.url, 0, 2, function (err, res) { 339 videosUtils.getVideosListPagination(server.url, 0, 2, function (err, res) {
338 if (err) throw err 340 if (err) throw err
339 341
340 const videos = res.body.data 342 const videos = res.body.data
@@ -348,7 +350,7 @@ describe('Test a single pod', function () {
348 }) 350 })
349 351
350 it('Should list only the next three videos', function (done) { 352 it('Should list only the next three videos', function (done) {
351 utils.getVideosListPagination(server.url, 2, 3, function (err, res) { 353 videosUtils.getVideosListPagination(server.url, 2, 3, function (err, res) {
352 if (err) throw err 354 if (err) throw err
353 355
354 const videos = res.body.data 356 const videos = res.body.data
@@ -363,7 +365,7 @@ describe('Test a single pod', function () {
363 }) 365 })
364 366
365 it('Should list the last video', function (done) { 367 it('Should list the last video', function (done) {
366 utils.getVideosListPagination(server.url, 5, 6, function (err, res) { 368 videosUtils.getVideosListPagination(server.url, 5, 6, function (err, res) {
367 if (err) throw err 369 if (err) throw err
368 370
369 const videos = res.body.data 371 const videos = res.body.data
@@ -376,7 +378,7 @@ describe('Test a single pod', function () {
376 }) 378 })
377 379
378 it('Should search the first video', function (done) { 380 it('Should search the first video', function (done) {
379 utils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, function (err, res) { 381 videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, function (err, res) {
380 if (err) throw err 382 if (err) throw err
381 383
382 const videos = res.body.data 384 const videos = res.body.data
@@ -389,7 +391,7 @@ describe('Test a single pod', function () {
389 }) 391 })
390 392
391 it('Should search the last two videos', function (done) { 393 it('Should search the last two videos', function (done) {
392 utils.searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, function (err, res) { 394 videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, function (err, res) {
393 if (err) throw err 395 if (err) throw err
394 396
395 const videos = res.body.data 397 const videos = res.body.data
@@ -403,7 +405,7 @@ describe('Test a single pod', function () {
403 }) 405 })
404 406
405 it('Should search all the webm videos', function (done) { 407 it('Should search all the webm videos', function (done) {
406 utils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 15, function (err, res) { 408 videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 15, function (err, res) {
407 if (err) throw err 409 if (err) throw err
408 410
409 const videos = res.body.data 411 const videos = res.body.data
@@ -415,7 +417,7 @@ describe('Test a single pod', function () {
415 }) 417 })
416 418
417 it('Should search all the root author videos', function (done) { 419 it('Should search all the root author videos', function (done) {
418 utils.searchVideoWithPagination(server.url, 'root', 'author', 0, 15, function (err, res) { 420 videosUtils.searchVideoWithPagination(server.url, 'root', 'author', 0, 15, function (err, res) {
419 if (err) throw err 421 if (err) throw err
420 422
421 const videos = res.body.data 423 const videos = res.body.data
@@ -427,7 +429,7 @@ describe('Test a single pod', function () {
427 }) 429 })
428 430
429 it('Should search all the 9001 port videos', function (done) { 431 it('Should search all the 9001 port videos', function (done) {
430 utils.searchVideoWithPagination(server.url, '9001', 'podUrl', 0, 15, function (err, res) { 432 videosUtils.searchVideoWithPagination(server.url, '9001', 'podUrl', 0, 15, function (err, res) {
431 if (err) throw err 433 if (err) throw err
432 434
433 const videos = res.body.data 435 const videos = res.body.data
@@ -439,7 +441,7 @@ describe('Test a single pod', function () {
439 }) 441 })
440 442
441 it('Should search all the localhost videos', function (done) { 443 it('Should search all the localhost videos', function (done) {
442 utils.searchVideoWithPagination(server.url, 'localhost', 'podUrl', 0, 15, function (err, res) { 444 videosUtils.searchVideoWithPagination(server.url, 'localhost', 'podUrl', 0, 15, function (err, res) {
443 if (err) throw err 445 if (err) throw err
444 446
445 const videos = res.body.data 447 const videos = res.body.data
@@ -452,7 +454,7 @@ describe('Test a single pod', function () {
452 454
453 it('Should search the good magnetUri video', function (done) { 455 it('Should search the good magnetUri video', function (done) {
454 const video = videosListBase[0] 456 const video = videosListBase[0]
455 utils.searchVideoWithPagination(server.url, encodeURIComponent(video.magnetUri), 'magnetUri', 0, 15, function (err, res) { 457 videosUtils.searchVideoWithPagination(server.url, encodeURIComponent(video.magnetUri), 'magnetUri', 0, 15, function (err, res) {
456 if (err) throw err 458 if (err) throw err
457 459
458 const videos = res.body.data 460 const videos = res.body.data
@@ -465,7 +467,7 @@ describe('Test a single pod', function () {
465 }) 467 })
466 468
467 it('Should list and sort by name in descending order', function (done) { 469 it('Should list and sort by name in descending order', function (done) {
468 utils.getVideosListSort(server.url, '-name', function (err, res) { 470 videosUtils.getVideosListSort(server.url, '-name', function (err, res) {
469 if (err) throw err 471 if (err) throw err
470 472
471 const videos = res.body.data 473 const videos = res.body.data
@@ -483,7 +485,7 @@ describe('Test a single pod', function () {
483 }) 485 })
484 486
485 it('Should search and sort by name in ascending order', function (done) { 487 it('Should search and sort by name in ascending order', function (done) {
486 utils.searchVideoWithSort(server.url, 'webm', 'name', function (err, res) { 488 videosUtils.searchVideoWithSort(server.url, 'webm', 'name', function (err, res) {
487 if (err) throw err 489 if (err) throw err
488 490
489 const videos = res.body.data 491 const videos = res.body.data
@@ -505,7 +507,7 @@ describe('Test a single pod', function () {
505 507
506 // Keep the logs if the test failed 508 // Keep the logs if the test failed
507 if (this.ok) { 509 if (this.ok) {
508 utils.flushTests(done) 510 serversUtils.flushTests(done)
509 } else { 511 } else {
510 done() 512 done()
511 } 513 }