2
1

peertube.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* tslint:disable:no-unused-expression */
  2. import 'mocha'
  3. import { expect } from 'chai'
  4. import {
  5. addVideoChannel,
  6. buildAbsoluteFixturePath,
  7. cleanupTests,
  8. createUser,
  9. execCLI,
  10. flushAndRunServer,
  11. getEnvCli,
  12. getVideo,
  13. getVideosList,
  14. getVideosListWithToken, removeVideo,
  15. ServerInfo,
  16. setAccessTokensToServers,
  17. userLogin,
  18. waitJobs
  19. } from '../../../shared/extra-utils'
  20. import { Video, VideoDetails } from '../../../shared'
  21. import { getYoutubeVideoUrl } from '../../../shared/extra-utils/videos/video-imports'
  22. describe('Test CLI wrapper', function () {
  23. let server: ServerInfo
  24. let userAccessToken: string
  25. const cmd = 'node ./dist/server/tools/peertube.js'
  26. before(async function () {
  27. this.timeout(30000)
  28. server = await flushAndRunServer(1)
  29. await setAccessTokensToServers([ server ])
  30. await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super_password' })
  31. userAccessToken = await userLogin(server, { username: 'user_1', password: 'super_password' })
  32. {
  33. const args = { name: 'user_channel', displayName: 'User channel', support: 'super support text' }
  34. await addVideoChannel(server.url, userAccessToken, args)
  35. }
  36. })
  37. it('Should display no selected instance', async function () {
  38. this.timeout(60000)
  39. const env = getEnvCli(server)
  40. const stdout = await execCLI(`${env} ${cmd} --help`)
  41. expect(stdout).to.contain('no instance selected')
  42. })
  43. it('Should add a user', async function () {
  44. this.timeout(60000)
  45. const env = getEnvCli(server)
  46. await execCLI(`${env} ${cmd} auth add -u ${server.url} -U user_1 -p super_password`)
  47. })
  48. it('Should default to this user', async function () {
  49. this.timeout(60000)
  50. const env = getEnvCli(server)
  51. const stdout = await execCLI(`${env} ${cmd} --help`)
  52. expect(stdout).to.contain(`instance ${server.url} selected`)
  53. })
  54. it('Should remember the user', async function () {
  55. this.timeout(60000)
  56. const env = getEnvCli(server)
  57. const stdout = await execCLI(`${env} ${cmd} auth list`)
  58. expect(stdout).to.contain(server.url)
  59. })
  60. it('Should upload a video', async function () {
  61. this.timeout(60000)
  62. const env = getEnvCli(server)
  63. const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4')
  64. const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'`
  65. await execCLI(`${env} ${cmd} upload ${params}`)
  66. })
  67. it('Should have the video uploaded', async function () {
  68. const res = await getVideosList(server.url)
  69. expect(res.body.total).to.equal(1)
  70. const videos: Video[] = res.body.data
  71. const video: VideoDetails = (await getVideo(server.url, videos[0].uuid)).body
  72. expect(video.name).to.equal('test upload')
  73. expect(video.support).to.equal('support_text')
  74. expect(video.channel.name).to.equal('user_channel')
  75. })
  76. it('Should import a video', async function () {
  77. this.timeout(60000)
  78. const env = getEnvCli(server)
  79. const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel`
  80. await execCLI(`${env} ${cmd} import ${params}`)
  81. })
  82. it('Should have imported the video', async function () {
  83. this.timeout(60000)
  84. await waitJobs([ server ])
  85. const res = await getVideosList(server.url)
  86. expect(res.body.total).to.equal(2)
  87. const videos: Video[] = res.body.data
  88. const video = videos.find(v => v.name === 'small video - youtube')
  89. expect(video).to.not.be.undefined
  90. const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
  91. expect(videoDetails.channel.name).to.equal('user_channel')
  92. expect(videoDetails.support).to.equal('super support text')
  93. expect(videoDetails.nsfw).to.be.false
  94. // So we can reimport it
  95. await removeVideo(server.url, userAccessToken, video.id)
  96. })
  97. it('Should import and override some imported attributes', async function () {
  98. this.timeout(60000)
  99. const env = getEnvCli(server)
  100. const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel --video-name toto --nsfw --support support`
  101. await execCLI(`${env} ${cmd} import ${params}`)
  102. await waitJobs([ server ])
  103. {
  104. const res = await getVideosList(server.url)
  105. expect(res.body.total).to.equal(2)
  106. const videos: Video[] = res.body.data
  107. const video = videos.find(v => v.name === 'toto')
  108. expect(video).to.not.be.undefined
  109. const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
  110. expect(videoDetails.channel.name).to.equal('user_channel')
  111. expect(videoDetails.support).to.equal('support')
  112. expect(videoDetails.nsfw).to.be.true
  113. expect(videoDetails.commentsEnabled).to.be.true
  114. }
  115. })
  116. it('Should remove the auth user', async function () {
  117. const env = getEnvCli(server)
  118. await execCLI(`${env} ${cmd} auth del ${server.url}`)
  119. const stdout = await execCLI(`${env} ${cmd} --help`)
  120. expect(stdout).to.contain('no instance selected')
  121. })
  122. after(async function () {
  123. this.timeout(10000)
  124. await cleanupTests([ server ])
  125. })
  126. })