update-host.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
  2. import { expect } from 'chai'
  3. import { getAllFiles } from '@shared/core-utils'
  4. import {
  5. cleanupTests,
  6. createSingleServer,
  7. killallServers,
  8. makeActivityPubGetRequest,
  9. parseTorrentVideo,
  10. PeerTubeServer,
  11. setAccessTokensToServers,
  12. waitJobs
  13. } from '@shared/server-commands'
  14. describe('Test update host scripts', function () {
  15. let server: PeerTubeServer
  16. before(async function () {
  17. this.timeout(60000)
  18. const overrideConfig = {
  19. webserver: {
  20. port: 9256
  21. }
  22. }
  23. // Run server 2 to have transcoding enabled
  24. server = await createSingleServer(2, overrideConfig)
  25. await setAccessTokensToServers([ server ])
  26. // Upload two videos for our needs
  27. const { uuid: video1UUID } = await server.videos.upload()
  28. await server.videos.upload()
  29. // Create a user
  30. await server.users.create({ username: 'toto', password: 'coucou' })
  31. // Create channel
  32. const videoChannel = {
  33. name: 'second_channel',
  34. displayName: 'second video channel',
  35. description: 'super video channel description'
  36. }
  37. await server.channels.create({ attributes: videoChannel })
  38. // Create comments
  39. const text = 'my super first comment'
  40. await server.comments.createThread({ videoId: video1UUID, text })
  41. await waitJobs(server)
  42. })
  43. it('Should run update host', async function () {
  44. this.timeout(30000)
  45. await killallServers([ server ])
  46. // Run server with standard configuration
  47. await server.run()
  48. await server.cli.execWithEnv(`npm run update-host`)
  49. })
  50. it('Should have updated videos url', async function () {
  51. const { total, data } = await server.videos.list()
  52. expect(total).to.equal(2)
  53. for (const video of data) {
  54. const { body } = await makeActivityPubGetRequest(server.url, '/videos/watch/' + video.uuid)
  55. expect(body.id).to.equal('http://localhost:9002/videos/watch/' + video.uuid)
  56. const videoDetails = await server.videos.get({ id: video.uuid })
  57. expect(videoDetails.trackerUrls[0]).to.include(server.host)
  58. expect(videoDetails.streamingPlaylists[0].playlistUrl).to.include(server.host)
  59. expect(videoDetails.streamingPlaylists[0].segmentsSha256Url).to.include(server.host)
  60. }
  61. })
  62. it('Should have updated video channels url', async function () {
  63. const { data, total } = await server.channels.list({ sort: '-name' })
  64. expect(total).to.equal(3)
  65. for (const channel of data) {
  66. const { body } = await makeActivityPubGetRequest(server.url, '/video-channels/' + channel.name)
  67. expect(body.id).to.equal('http://localhost:9002/video-channels/' + channel.name)
  68. }
  69. })
  70. it('Should have updated accounts url', async function () {
  71. const body = await server.accounts.list()
  72. expect(body.total).to.equal(3)
  73. for (const account of body.data) {
  74. const usernameWithDomain = account.name
  75. const { body } = await makeActivityPubGetRequest(server.url, '/accounts/' + usernameWithDomain)
  76. expect(body.id).to.equal('http://localhost:9002/accounts/' + usernameWithDomain)
  77. }
  78. })
  79. it('Should have updated torrent hosts', async function () {
  80. this.timeout(30000)
  81. const { data } = await server.videos.list()
  82. expect(data).to.have.lengthOf(2)
  83. for (const video of data) {
  84. const videoDetails = await server.videos.get({ id: video.id })
  85. const files = getAllFiles(videoDetails)
  86. expect(files).to.have.lengthOf(8)
  87. for (const file of files) {
  88. expect(file.magnetUri).to.contain('localhost%3A9002%2Ftracker%2Fsocket')
  89. expect(file.magnetUri).to.contain('localhost%3A9002%2Fstatic%2F')
  90. const torrent = await parseTorrentVideo(server, file)
  91. const announceWS = torrent.announce.find(a => a === 'ws://localhost:9002/tracker/socket')
  92. expect(announceWS).to.not.be.undefined
  93. const announceHttp = torrent.announce.find(a => a === 'http://localhost:9002/tracker/announce')
  94. expect(announceHttp).to.not.be.undefined
  95. expect(torrent.urlList[0]).to.contain('http://localhost:9002/static/')
  96. }
  97. }
  98. })
  99. after(async function () {
  100. await cleanupTests([ server ])
  101. })
  102. })