1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { Account } from '../../../../shared/models/actors'
7 checkVideoFilesWereRemoved,
10 flushAndRunMultipleServers,
17 import { getMyUserInformation, killallServers, ServerInfo, testImage, updateMyAvatar, uploadVideo } from '../../utils/index'
18 import { checkActorFilesWereRemoved, getAccount, getAccountsList } from '../../utils/users/accounts'
19 import { setAccessTokensToServers } from '../../utils/users/login'
20 import { User } from '../../../../shared/models/users'
21 import { VideoChannel } from '../../../../shared/models/videos'
22 import { waitJobs } from '../../utils/server/jobs'
24 const expect = chai.expect
26 describe('Test users with multiple servers', function () {
27 let servers: ServerInfo[] = []
29 let userAccountName: string
30 let userVideoChannelUUID: string
33 let userAccessToken: string
35 before(async function () {
38 servers = await flushAndRunMultipleServers(3)
40 // Get the access tokens
41 await setAccessTokensToServers(servers)
43 // Server 1 and server 2 follow each other
44 await doubleFollow(servers[0], servers[1])
45 // Server 1 and server 3 follow each other
46 await doubleFollow(servers[0], servers[2])
47 // Server 2 and server 3 follow each other
48 await doubleFollow(servers[1], servers[2])
50 // The root user of server 1 is propagated to servers 2 and 3
51 await uploadVideo(servers[0].url, servers[0].accessToken, {})
58 const res = await createUser(servers[ 0 ].url, servers[ 0 ].accessToken, user.username, user.password)
59 userId = res.body.user.id
60 userAccessToken = await userLogin(servers[ 0 ], user)
64 const res = await getMyUserInformation(servers[0].url, userAccessToken)
65 userAccountName = res.body.account.name + '@' + res.body.account.host
69 const res = await getMyUserInformation(servers[ 0 ].url, servers[ 0 ].accessToken)
70 const user: User = res.body
71 userVideoChannelUUID = user.videoChannels[0].uuid
75 const resVideo = await uploadVideo(servers[ 0 ].url, userAccessToken, {})
76 videoUUID = resVideo.body.video.uuid
79 await waitJobs(servers)
82 it('Should be able to update my display name', async function () {
87 accessToken: servers[0].accessToken,
88 displayName: 'my super display name'
91 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
93 expect(user.account.displayName).to.equal('my super display name')
95 await waitJobs(servers)
98 it('Should be able to update my description', async function () {
103 accessToken: servers[0].accessToken,
104 description: 'my super description updated'
107 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
109 expect(user.account.displayName).to.equal('my super display name')
110 expect(user.account.description).to.equal('my super description updated')
112 await waitJobs(servers)
115 it('Should be able to update my avatar', async function () {
118 const fixture = 'avatar2.png'
120 await updateMyAvatar({
122 accessToken: servers[0].accessToken,
126 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
129 await testImage(servers[0].url, 'avatar2-resized', user.account.avatar.path, '.png')
131 await waitJobs(servers)
134 it('Should have updated my profile on other servers too', async function () {
135 for (const server of servers) {
136 const resAccounts = await getAccountsList(server.url, '-createdAt')
138 const rootServer1List = resAccounts.body.data.find(a => a.name === 'root' && a.host === 'localhost:9001') as Account
139 expect(rootServer1List).not.to.be.undefined
141 const resAccount = await getAccount(server.url, rootServer1List.name + '@' + rootServer1List.host)
142 const rootServer1Get = resAccount.body as Account
143 expect(rootServer1Get.name).to.equal('root')
144 expect(rootServer1Get.host).to.equal('localhost:9001')
145 expect(rootServer1Get.displayName).to.equal('my super display name')
146 expect(rootServer1Get.description).to.equal('my super description updated')
148 await testImage(server.url, 'avatar2-resized', rootServer1Get.avatar.path, '.png')
152 it('Should list account videos', async function () {
153 for (const server of servers) {
154 const res = await getAccountVideos(server.url, server.accessToken, userAccountName, 0, 5)
156 expect(res.body.total).to.equal(1)
157 expect(res.body.data).to.be.an('array')
158 expect(res.body.data).to.have.lengthOf(1)
159 expect(res.body.data[0].uuid).to.equal(videoUUID)
163 it('Should remove the user', async function () {
166 for (const server of servers) {
167 const resAccounts = await getAccountsList(server.url, '-createdAt')
169 const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:9001') as Account
170 expect(accountDeleted).not.to.be.undefined
172 const resVideoChannels = await getVideoChannelsList(server.url, 0, 10)
173 const videoChannelDeleted = resVideoChannels.body.data.find(a => {
174 return a.displayName === 'Main user1 channel' && a.host === 'localhost:9001'
176 expect(videoChannelDeleted).not.to.be.undefined
179 await removeUser(servers[0].url, userId, servers[0].accessToken)
181 await waitJobs(servers)
183 for (const server of servers) {
184 const resAccounts = await getAccountsList(server.url, '-createdAt')
186 const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:9001') as Account
187 expect(accountDeleted).to.be.undefined
189 const resVideoChannels = await getVideoChannelsList(server.url, 0, 10)
190 const videoChannelDeleted = resVideoChannels.body.data.find(a => {
191 return a.name === 'Main user1 channel' && a.host === 'localhost:9001'
193 expect(videoChannelDeleted).to.be.undefined
197 it('Should not have actor files', async () => {
198 for (const server of servers) {
199 await checkActorFilesWereRemoved(userAccountName, server.serverNumber)
200 await checkActorFilesWereRemoved(userVideoChannelUUID, server.serverNumber)
204 it('Should not have video files', async () => {
205 for (const server of servers) {
206 await checkVideoFilesWereRemoved(videoUUID, server.serverNumber)
210 after(async function () {
211 killallServers(servers)