aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/single-server.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/single-server.ts')
-rw-r--r--server/tests/api/single-server.ts185
1 files changed, 95 insertions, 90 deletions
diff --git a/server/tests/api/single-server.ts b/server/tests/api/single-server.ts
index 041d13225..174fb480d 100644
--- a/server/tests/api/single-server.ts
+++ b/server/tests/api/single-server.ts
@@ -1,40 +1,40 @@
1/* tslint:disable:no-unused-expression */ 1/* tslint:disable:no-unused-expression */
2 2
3import * as chai from 'chai'
3import { keyBy } from 'lodash' 4import { keyBy } from 'lodash'
4import { join } from 'path'
5import 'mocha' 5import 'mocha'
6import * as chai from 'chai' 6import { join } from 'path'
7const expect = chai.expect
8
9import { 7import {
10 ServerInfo,
11 flushTests,
12 runServer,
13 uploadVideo,
14 getVideosList,
15 rateVideo,
16 removeVideo,
17 wait,
18 setAccessTokensToServers,
19 searchVideo,
20 killallServers,
21 dateIsValid, 8 dateIsValid,
9 flushTests,
10 getVideo,
22 getVideoCategories, 11 getVideoCategories,
23 getVideoLicences,
24 getVideoLanguages, 12 getVideoLanguages,
13 getVideoLicences,
25 getVideoPrivacies, 14 getVideoPrivacies,
26 testVideoImage, 15 getVideosList,
27 webtorrentAdd,
28 getVideo,
29 readdirPromise,
30 getVideosListPagination, 16 getVideosListPagination,
31 searchVideoWithPagination,
32 getVideosListSort, 17 getVideosListSort,
18 killallServers,
19 rateVideo,
20 readdirPromise,
21 removeVideo,
22 runServer,
23 searchVideo,
24 searchVideoWithPagination,
33 searchVideoWithSort, 25 searchVideoWithSort,
34 updateVideo 26 ServerInfo,
27 setAccessTokensToServers,
28 testVideoImage,
29 updateVideo,
30 uploadVideo,
31 wait,
32 webtorrentAdd
35} from '../utils' 33} from '../utils'
36import { viewVideo } from '../utils/videos' 34import { viewVideo } from '../utils/videos'
37 35
36const expect = chai.expect
37
38describe('Test a single server', function () { 38describe('Test a single server', function () {
39 let server: ServerInfo = null 39 let server: ServerInfo = null
40 let videoId = -1 40 let videoId = -1
@@ -103,7 +103,10 @@ describe('Test a single server', function () {
103 licence: 6, 103 licence: 6,
104 tags: [ 'tag1', 'tag2', 'tag3' ] 104 tags: [ 'tag1', 'tag2', 'tag3' ]
105 } 105 }
106 await uploadVideo(server.url, server.accessToken, videoAttributes) 106 const res = await uploadVideo(server.url, server.accessToken, videoAttributes)
107 expect(res.body.video).to.not.be.undefined
108 expect(res.body.video.id).to.equal(1)
109 expect(res.body.video.uuid).to.have.length.above(5)
107 }) 110 })
108 111
109 it('Should seed the uploaded video', async function () { 112 it('Should seed the uploaded video', async function () {
@@ -127,7 +130,7 @@ describe('Test a single server', function () {
127 expect(video.nsfw).to.be.ok 130 expect(video.nsfw).to.be.ok
128 expect(video.description).to.equal('my super description') 131 expect(video.description).to.equal('my super description')
129 expect(video.serverHost).to.equal('localhost:9001') 132 expect(video.serverHost).to.equal('localhost:9001')
130 expect(video.account).to.equal('root') 133 expect(video.accountName).to.equal('root')
131 expect(video.isLocal).to.be.true 134 expect(video.isLocal).to.be.true
132 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) 135 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
133 expect(dateIsValid(video.createdAt)).to.be.true 136 expect(dateIsValid(video.createdAt)).to.be.true
@@ -176,7 +179,7 @@ describe('Test a single server', function () {
176 expect(video.nsfw).to.be.ok 179 expect(video.nsfw).to.be.ok
177 expect(video.description).to.equal('my super description') 180 expect(video.description).to.equal('my super description')
178 expect(video.serverHost).to.equal('localhost:9001') 181 expect(video.serverHost).to.equal('localhost:9001')
179 expect(video.account).to.equal('root') 182 expect(video.accountName).to.equal('root')
180 expect(video.isLocal).to.be.true 183 expect(video.isLocal).to.be.true
181 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) 184 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
182 expect(dateIsValid(video.createdAt)).to.be.true 185 expect(dateIsValid(video.createdAt)).to.be.true
@@ -225,7 +228,7 @@ describe('Test a single server', function () {
225 expect(video.views).to.equal(3) 228 expect(video.views).to.equal(3)
226 }) 229 })
227 230
228 it('Should search the video by name by default', async function () { 231 it('Should search the video by name', async function () {
229 const res = await searchVideo(server.url, 'my') 232 const res = await searchVideo(server.url, 'my')
230 233
231 expect(res.body.total).to.equal(1) 234 expect(res.body.total).to.equal(1)
@@ -243,7 +246,7 @@ describe('Test a single server', function () {
243 expect(video.nsfw).to.be.ok 246 expect(video.nsfw).to.be.ok
244 expect(video.description).to.equal('my super description') 247 expect(video.description).to.equal('my super description')
245 expect(video.serverHost).to.equal('localhost:9001') 248 expect(video.serverHost).to.equal('localhost:9001')
246 expect(video.account).to.equal('root') 249 expect(video.accountName).to.equal('root')
247 expect(video.isLocal).to.be.true 250 expect(video.isLocal).to.be.true
248 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) 251 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
249 expect(dateIsValid(video.createdAt)).to.be.true 252 expect(dateIsValid(video.createdAt)).to.be.true
@@ -279,35 +282,36 @@ describe('Test a single server', function () {
279 // }) 282 // })
280 // }) 283 // })
281 284
282 it('Should search the video by tag', async function () { 285 // Not implemented yet
283 const res = await searchVideo(server.url, 'tag1', 'tags') 286 // it('Should search the video by tag', async function () {
284 287 // const res = await searchVideo(server.url, 'tag1')
285 expect(res.body.total).to.equal(1) 288 //
286 expect(res.body.data).to.be.an('array') 289 // expect(res.body.total).to.equal(1)
287 expect(res.body.data.length).to.equal(1) 290 // expect(res.body.data).to.be.an('array')
288 291 // expect(res.body.data.length).to.equal(1)
289 const video = res.body.data[0] 292 //
290 expect(video.name).to.equal('my super name') 293 // const video = res.body.data[0]
291 expect(video.category).to.equal(2) 294 // expect(video.name).to.equal('my super name')
292 expect(video.categoryLabel).to.equal('Films') 295 // expect(video.category).to.equal(2)
293 expect(video.licence).to.equal(6) 296 // expect(video.categoryLabel).to.equal('Films')
294 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') 297 // expect(video.licence).to.equal(6)
295 expect(video.language).to.equal(3) 298 // expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
296 expect(video.languageLabel).to.equal('Mandarin') 299 // expect(video.language).to.equal(3)
297 expect(video.nsfw).to.be.ok 300 // expect(video.languageLabel).to.equal('Mandarin')
298 expect(video.description).to.equal('my super description') 301 // expect(video.nsfw).to.be.ok
299 expect(video.serverHost).to.equal('localhost:9001') 302 // expect(video.description).to.equal('my super description')
300 expect(video.account).to.equal('root') 303 // expect(video.serverHost).to.equal('localhost:9001')
301 expect(video.isLocal).to.be.true 304 // expect(video.accountName).to.equal('root')
302 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) 305 // expect(video.isLocal).to.be.true
303 expect(dateIsValid(video.createdAt)).to.be.true 306 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
304 expect(dateIsValid(video.updatedAt)).to.be.true 307 // expect(dateIsValid(video.createdAt)).to.be.true
305 308 // expect(dateIsValid(video.updatedAt)).to.be.true
306 const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath) 309 //
307 expect(test).to.equal(true) 310 // const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
308 }) 311 // expect(test).to.equal(true)
312 // })
309 313
310 it('Should not find a search by name by default', async function () { 314 it('Should not find a search by name', async function () {
311 const res = await searchVideo(server.url, 'hello') 315 const res = await searchVideo(server.url, 'hello')
312 316
313 expect(res.body.total).to.equal(0) 317 expect(res.body.total).to.equal(0)
@@ -315,21 +319,23 @@ describe('Test a single server', function () {
315 expect(res.body.data.length).to.equal(0) 319 expect(res.body.data.length).to.equal(0)
316 }) 320 })
317 321
318 it('Should not find a search by author', async function () { 322 // Not implemented yet
319 const res = await searchVideo(server.url, 'hello', 'account') 323 // it('Should not find a search by author', async function () {
320 324 // const res = await searchVideo(server.url, 'hello')
321 expect(res.body.total).to.equal(0) 325 //
322 expect(res.body.data).to.be.an('array') 326 // expect(res.body.total).to.equal(0)
323 expect(res.body.data.length).to.equal(0) 327 // expect(res.body.data).to.be.an('array')
324 }) 328 // expect(res.body.data.length).to.equal(0)
325 329 // })
326 it('Should not find a search by tag', async function () { 330 //
327 const res = await searchVideo(server.url, 'hello', 'tags') 331 // Not implemented yet
328 332 // it('Should not find a search by tag', async function () {
329 expect(res.body.total).to.equal(0) 333 // const res = await searchVideo(server.url, 'hello')
330 expect(res.body.data).to.be.an('array') 334 //
331 expect(res.body.data.length).to.equal(0) 335 // expect(res.body.total).to.equal(0)
332 }) 336 // expect(res.body.data).to.be.an('array')
337 // expect(res.body.data.length).to.equal(0)
338 // })
333 339
334 it('Should remove the video', async function () { 340 it('Should remove the video', async function () {
335 await removeVideo(server.url, server.accessToken, videoId) 341 await removeVideo(server.url, server.accessToken, videoId)
@@ -357,7 +363,7 @@ describe('Test a single server', function () {
357 'video_short1.webm', 'video_short2.webm', 'video_short3.webm' 363 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
358 ] 364 ]
359 365
360 // const tasks: Promise<any>[] = [] 366 const tasks: Promise<any>[] = []
361 for (const video of videos) { 367 for (const video of videos) {
362 const videoAttributes = { 368 const videoAttributes = {
363 name: video + ' name', 369 name: video + ' name',
@@ -371,13 +377,10 @@ describe('Test a single server', function () {
371 } 377 }
372 378
373 const p = uploadVideo(server.url, server.accessToken, videoAttributes) 379 const p = uploadVideo(server.url, server.accessToken, videoAttributes)
374 await p 380 tasks.push(p)
375 } 381 }
376 // FIXME: concurrent uploads does not work :( 382
377 // tasks.push(p) 383 await Promise.all(tasks)
378 // }
379 //
380 // await Promise.all(tasks)
381 }) 384 })
382 385
383 it('Should have the correct durations', async function () { 386 it('Should have the correct durations', async function () {
@@ -443,7 +446,7 @@ describe('Test a single server', function () {
443 }) 446 })
444 447
445 it('Should search the first video', async function () { 448 it('Should search the first video', async function () {
446 const res = await searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, 'name') 449 const res = await searchVideoWithPagination(server.url, 'webm', 0, 1, 'name')
447 450
448 const videos = res.body.data 451 const videos = res.body.data
449 expect(res.body.total).to.equal(4) 452 expect(res.body.total).to.equal(4)
@@ -452,7 +455,7 @@ describe('Test a single server', function () {
452 }) 455 })
453 456
454 it('Should search the last two videos', async function () { 457 it('Should search the last two videos', async function () {
455 const res = await searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, 'name') 458 const res = await searchVideoWithPagination(server.url, 'webm', 2, 2, 'name')
456 459
457 const videos = res.body.data 460 const videos = res.body.data
458 expect(res.body.total).to.equal(4) 461 expect(res.body.total).to.equal(4)
@@ -462,20 +465,21 @@ describe('Test a single server', function () {
462 }) 465 })
463 466
464 it('Should search all the webm videos', async function () { 467 it('Should search all the webm videos', async function () {
465 const res = await searchVideoWithPagination(server.url, 'webm', 'name', 0, 15) 468 const res = await searchVideoWithPagination(server.url, 'webm', 0, 15)
466 469
467 const videos = res.body.data 470 const videos = res.body.data
468 expect(res.body.total).to.equal(4) 471 expect(res.body.total).to.equal(4)
469 expect(videos.length).to.equal(4) 472 expect(videos.length).to.equal(4)
470 }) 473 })
471 474
472 it('Should search all the root author videos', async function () { 475 // Not implemented yet
473 const res = await searchVideoWithPagination(server.url, 'root', 'account', 0, 15) 476 // it('Should search all the root author videos', async function () {
474 477 // const res = await searchVideoWithPagination(server.url, 'root', 0, 15)
475 const videos = res.body.data 478 //
476 expect(res.body.total).to.equal(6) 479 // const videos = res.body.data
477 expect(videos.length).to.equal(6) 480 // expect(res.body.total).to.equal(6)
478 }) 481 // expect(videos.length).to.equal(6)
482 // })
479 483
480 // Not implemented yet 484 // Not implemented yet
481 // it('Should search all the 9001 port videos', async function () { 485 // it('Should search all the 9001 port videos', async function () {
@@ -559,7 +563,8 @@ describe('Test a single server', function () {
559 expect(video.nsfw).to.be.ok 563 expect(video.nsfw).to.be.ok
560 expect(video.description).to.equal('my super description updated') 564 expect(video.description).to.equal('my super description updated')
561 expect(video.serverHost).to.equal('localhost:9001') 565 expect(video.serverHost).to.equal('localhost:9001')
562 expect(video.account).to.equal('root') 566 expect(video.accountName).to.equal('root')
567 expect(video.account.name).to.equal('root')
563 expect(video.isLocal).to.be.true 568 expect(video.isLocal).to.be.true
564 expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ]) 569 expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
565 expect(dateIsValid(video.createdAt)).to.be.true 570 expect(dateIsValid(video.createdAt)).to.be.true
@@ -608,7 +613,7 @@ describe('Test a single server', function () {
608 expect(video.nsfw).to.be.ok 613 expect(video.nsfw).to.be.ok
609 expect(video.description).to.equal('my super description updated') 614 expect(video.description).to.equal('my super description updated')
610 expect(video.serverHost).to.equal('localhost:9001') 615 expect(video.serverHost).to.equal('localhost:9001')
611 expect(video.account).to.equal('root') 616 expect(video.accountName).to.equal('root')
612 expect(video.isLocal).to.be.true 617 expect(video.isLocal).to.be.true
613 expect(video.tags).to.deep.equal([ 'supertag', 'tag1', 'tag2' ]) 618 expect(video.tags).to.deep.equal([ 'supertag', 'tag1', 'tag2' ])
614 expect(dateIsValid(video.createdAt)).to.be.true 619 expect(dateIsValid(video.createdAt)).to.be.true
@@ -648,7 +653,7 @@ describe('Test a single server', function () {
648 expect(video.nsfw).to.be.ok 653 expect(video.nsfw).to.be.ok
649 expect(video.description).to.equal('hello everybody') 654 expect(video.description).to.equal('hello everybody')
650 expect(video.serverHost).to.equal('localhost:9001') 655 expect(video.serverHost).to.equal('localhost:9001')
651 expect(video.account).to.equal('root') 656 expect(video.accountName).to.equal('root')
652 expect(video.isLocal).to.be.true 657 expect(video.isLocal).to.be.true
653 expect(video.tags).to.deep.equal([ 'supertag', 'tag1', 'tag2' ]) 658 expect(video.tags).to.deep.equal([ 'supertag', 'tag1', 'tag2' ])
654 expect(dateIsValid(video.createdAt)).to.be.true 659 expect(dateIsValid(video.createdAt)).to.be.true