users-multiple-servers.ts 7.6 KB

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