update-host.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* tslint:disable:no-unused-expression */
  2. import 'mocha'
  3. import * as chai from 'chai'
  4. import { VideoDetails } from '../../../shared/models/videos'
  5. import { waitJobs } from '../../../shared/extra-utils/server/jobs'
  6. import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments'
  7. import {
  8. addVideoChannel,
  9. cleanupTests,
  10. createUser,
  11. execCLI,
  12. flushAndRunServer,
  13. getEnvCli,
  14. getVideo,
  15. getVideoChannelsList,
  16. getVideosList,
  17. killallServers,
  18. makeActivityPubGetRequest,
  19. parseTorrentVideo, reRunServer,
  20. ServerInfo,
  21. setAccessTokensToServers,
  22. uploadVideo
  23. } from '../../../shared/extra-utils'
  24. import { getAccountsList } from '../../../shared/extra-utils/users/accounts'
  25. const expect = chai.expect
  26. describe('Test update host scripts', function () {
  27. let server: ServerInfo
  28. before(async function () {
  29. this.timeout(60000)
  30. const overrideConfig = {
  31. webserver: {
  32. port: 9256
  33. }
  34. }
  35. // Run server 2 to have transcoding enabled
  36. server = await flushAndRunServer(2, overrideConfig)
  37. await setAccessTokensToServers([ server ])
  38. // Upload two videos for our needs
  39. const videoAttributes = {}
  40. const resVideo1 = await uploadVideo(server.url, server.accessToken, videoAttributes)
  41. const video1UUID = resVideo1.body.video.uuid
  42. await uploadVideo(server.url, server.accessToken, videoAttributes)
  43. // Create a user
  44. await createUser({ url: server.url, accessToken: server.accessToken, username: 'toto', password: 'coucou' })
  45. // Create channel
  46. const videoChannel = {
  47. name: 'second_channel',
  48. displayName: 'second video channel',
  49. description: 'super video channel description'
  50. }
  51. await addVideoChannel(server.url, server.accessToken, videoChannel)
  52. // Create comments
  53. const text = 'my super first comment'
  54. await addVideoCommentThread(server.url, server.accessToken, video1UUID, text)
  55. await waitJobs(server)
  56. })
  57. it('Should run update host', async function () {
  58. this.timeout(30000)
  59. killallServers([ server ])
  60. // Run server with standard configuration
  61. await reRunServer(server)
  62. const env = getEnvCli(server)
  63. await execCLI(`${env} npm run update-host`)
  64. })
  65. it('Should have updated videos url', async function () {
  66. const res = await getVideosList(server.url)
  67. expect(res.body.total).to.equal(2)
  68. for (const video of res.body.data) {
  69. const { body } = await makeActivityPubGetRequest(server.url, '/videos/watch/' + video.uuid)
  70. expect(body.id).to.equal('http://localhost:9002/videos/watch/' + video.uuid)
  71. const res = await getVideo(server.url, video.uuid)
  72. const videoDetails: VideoDetails = res.body
  73. expect(videoDetails.trackerUrls[0]).to.include(server.host)
  74. expect(videoDetails.streamingPlaylists[0].playlistUrl).to.include(server.host)
  75. expect(videoDetails.streamingPlaylists[0].segmentsSha256Url).to.include(server.host)
  76. }
  77. })
  78. it('Should have updated video channels url', async function () {
  79. const res = await getVideoChannelsList(server.url, 0, 5, '-name')
  80. expect(res.body.total).to.equal(3)
  81. for (const channel of res.body.data) {
  82. const { body } = await makeActivityPubGetRequest(server.url, '/video-channels/' + channel.name)
  83. expect(body.id).to.equal('http://localhost:9002/video-channels/' + channel.name)
  84. }
  85. })
  86. it('Should have updated accounts url', async function () {
  87. const res = await getAccountsList(server.url)
  88. expect(res.body.total).to.equal(3)
  89. for (const account of res.body.data) {
  90. const usernameWithDomain = account.name
  91. const { body } = await makeActivityPubGetRequest(server.url, '/accounts/' + usernameWithDomain)
  92. expect(body.id).to.equal('http://localhost:9002/accounts/' + usernameWithDomain)
  93. }
  94. })
  95. it('Should have updated torrent hosts', async function () {
  96. this.timeout(30000)
  97. const res = await getVideosList(server.url)
  98. const videos = res.body.data
  99. expect(videos).to.have.lengthOf(2)
  100. for (const video of videos) {
  101. const res2 = await getVideo(server.url, video.id)
  102. const videoDetails: VideoDetails = res2.body
  103. expect(videoDetails.files).to.have.lengthOf(4)
  104. for (const file of videoDetails.files) {
  105. expect(file.magnetUri).to.contain('localhost%3A9002%2Ftracker%2Fsocket')
  106. expect(file.magnetUri).to.contain('localhost%3A9002%2Fstatic%2Fwebseed%2F')
  107. const torrent = await parseTorrentVideo(server, videoDetails.uuid, file.resolution.id)
  108. const announceWS = torrent.announce.find(a => a === 'ws://localhost:9002/tracker/socket')
  109. expect(announceWS).to.not.be.undefined
  110. const announceHttp = torrent.announce.find(a => a === 'http://localhost:9002/tracker/announce')
  111. expect(announceHttp).to.not.be.undefined
  112. expect(torrent.urlList[0]).to.contain('http://localhost:9002/static/webseed')
  113. }
  114. }
  115. })
  116. after(async function () {
  117. await cleanupTests([ server ])
  118. })
  119. })