users-multiple-servers.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
  2. import * as chai from 'chai'
  3. import 'mocha'
  4. import { Account } from '../../../../shared/models/actors'
  5. import {
  6. checkTmpIsEmpty,
  7. checkVideoFilesWereRemoved,
  8. cleanupTests,
  9. createUser,
  10. doubleFollow,
  11. flushAndRunMultipleServers,
  12. getAccountVideos,
  13. getVideoChannelsList,
  14. removeUser,
  15. updateMyUser,
  16. userLogin
  17. } from '../../../../shared/extra-utils'
  18. import { getMyUserInformation, ServerInfo, testImage, updateMyAvatar, uploadVideo } from '../../../../shared/extra-utils/index'
  19. import { checkActorFilesWereRemoved, getAccount, getAccountsList } from '../../../../shared/extra-utils/users/accounts'
  20. import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
  21. import { User } from '../../../../shared/models/users'
  22. import { VideoChannel } from '../../../../shared/models/videos'
  23. import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
  24. const expect = chai.expect
  25. describe('Test users with multiple servers', function () {
  26. let servers: ServerInfo[] = []
  27. let user: User
  28. let userId: number
  29. let videoUUID: string
  30. let userAccessToken: string
  31. let userAvatarFilename: string
  32. before(async function () {
  33. this.timeout(120000)
  34. servers = await flushAndRunMultipleServers(3)
  35. // Get the access tokens
  36. await setAccessTokensToServers(servers)
  37. // Server 1 and server 2 follow each other
  38. await doubleFollow(servers[0], servers[1])
  39. // Server 1 and server 3 follow each other
  40. await doubleFollow(servers[0], servers[2])
  41. // Server 2 and server 3 follow each other
  42. await doubleFollow(servers[1], servers[2])
  43. // The root user of server 1 is propagated to servers 2 and 3
  44. await uploadVideo(servers[0].url, servers[0].accessToken, {})
  45. {
  46. const user = {
  47. username: 'user1',
  48. password: 'password'
  49. }
  50. const res = await createUser({
  51. url: servers[0].url,
  52. accessToken: servers[0].accessToken,
  53. username: user.username,
  54. password: user.password
  55. })
  56. userId = res.body.user.id
  57. userAccessToken = await userLogin(servers[0], user)
  58. }
  59. {
  60. const resVideo = await uploadVideo(servers[0].url, userAccessToken, {})
  61. videoUUID = resVideo.body.video.uuid
  62. }
  63. await waitJobs(servers)
  64. })
  65. it('Should be able to update my display name', async function () {
  66. this.timeout(10000)
  67. await updateMyUser({
  68. url: servers[0].url,
  69. accessToken: servers[0].accessToken,
  70. displayName: 'my super display name'
  71. })
  72. const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
  73. user = res.body
  74. expect(user.account.displayName).to.equal('my super display name')
  75. await waitJobs(servers)
  76. })
  77. it('Should be able to update my description', async function () {
  78. this.timeout(10000)
  79. await updateMyUser({
  80. url: servers[0].url,
  81. accessToken: servers[0].accessToken,
  82. description: 'my super description updated'
  83. })
  84. const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
  85. user = res.body
  86. expect(user.account.displayName).to.equal('my super display name')
  87. expect(user.account.description).to.equal('my super description updated')
  88. await waitJobs(servers)
  89. })
  90. it('Should be able to update my avatar', async function () {
  91. this.timeout(10000)
  92. const fixture = 'avatar2.png'
  93. await updateMyAvatar({
  94. url: servers[0].url,
  95. accessToken: servers[0].accessToken,
  96. fixture
  97. })
  98. const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
  99. user = res.body
  100. userAvatarFilename = user.account.avatar.path
  101. await testImage(servers[0].url, 'avatar2-resized', userAvatarFilename, '.png')
  102. await waitJobs(servers)
  103. })
  104. it('Should have updated my profile on other servers too', async function () {
  105. for (const server of servers) {
  106. const resAccounts = await getAccountsList(server.url, '-createdAt')
  107. const rootServer1List = resAccounts.body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port) as Account
  108. expect(rootServer1List).not.to.be.undefined
  109. const resAccount = await getAccount(server.url, rootServer1List.name + '@' + rootServer1List.host)
  110. const rootServer1Get = resAccount.body as Account
  111. expect(rootServer1Get.name).to.equal('root')
  112. expect(rootServer1Get.host).to.equal('localhost:' + servers[0].port)
  113. expect(rootServer1Get.displayName).to.equal('my super display name')
  114. expect(rootServer1Get.description).to.equal('my super description updated')
  115. if (server.serverNumber === 1) {
  116. expect(rootServer1Get.userId).to.be.a('number')
  117. } else {
  118. expect(rootServer1Get.userId).to.be.undefined
  119. }
  120. await testImage(server.url, 'avatar2-resized', rootServer1Get.avatar.path, '.png')
  121. }
  122. })
  123. it('Should list account videos', async function () {
  124. for (const server of servers) {
  125. const res = await getAccountVideos(server.url, server.accessToken, 'user1@localhost:' + servers[0].port, 0, 5)
  126. expect(res.body.total).to.equal(1)
  127. expect(res.body.data).to.be.an('array')
  128. expect(res.body.data).to.have.lengthOf(1)
  129. expect(res.body.data[0].uuid).to.equal(videoUUID)
  130. }
  131. })
  132. it('Should remove the user', async function () {
  133. this.timeout(10000)
  134. for (const server of servers) {
  135. const resAccounts = await getAccountsList(server.url, '-createdAt')
  136. const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) as Account
  137. expect(accountDeleted).not.to.be.undefined
  138. const resVideoChannels = await getVideoChannelsList(server.url, 0, 10)
  139. const videoChannelDeleted = resVideoChannels.body.data.find(a => {
  140. return a.displayName === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port
  141. }) as VideoChannel
  142. expect(videoChannelDeleted).not.to.be.undefined
  143. }
  144. await removeUser(servers[0].url, userId, servers[0].accessToken)
  145. await waitJobs(servers)
  146. for (const server of servers) {
  147. const resAccounts = await getAccountsList(server.url, '-createdAt')
  148. const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) as Account
  149. expect(accountDeleted).to.be.undefined
  150. const resVideoChannels = await getVideoChannelsList(server.url, 0, 10)
  151. const videoChannelDeleted = resVideoChannels.body.data.find(a => {
  152. return a.name === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port
  153. }) as VideoChannel
  154. expect(videoChannelDeleted).to.be.undefined
  155. }
  156. })
  157. it('Should not have actor files', async () => {
  158. for (const server of servers) {
  159. await checkActorFilesWereRemoved(userAvatarFilename, server.internalServerNumber)
  160. }
  161. })
  162. it('Should not have video files', async () => {
  163. for (const server of servers) {
  164. await checkVideoFilesWereRemoved(videoUUID, server.internalServerNumber)
  165. }
  166. })
  167. it('Should have an empty tmp directory', async function () {
  168. for (const server of servers) {
  169. await checkTmpIsEmpty(server)
  170. }
  171. })
  172. after(async function () {
  173. await cleanupTests(servers)
  174. })
  175. })