1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { Account } from '../../../../shared/models/actors'
8 checkVideoFilesWereRemoved,
12 flushAndRunMultipleServers,
18 } from '../../../../shared/extra-utils'
19 import { getMyUserInformation, ServerInfo, testImage, updateMyAvatar, uploadVideo } from '../../../../shared/extra-utils/index'
20 import { checkActorFilesWereRemoved, getAccount, getAccountsList } from '../../../../shared/extra-utils/users/accounts'
21 import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
22 import { User } from '../../../../shared/models/users'
23 import { VideoChannel } from '../../../../shared/models/videos'
24 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
26 const expect = chai.expect
28 describe('Test users with multiple servers', function () {
29 let servers: ServerInfo[] = []
33 let userAccessToken: string
34 let userAvatarFilename: string
36 before(async function () {
39 servers = await flushAndRunMultipleServers(3)
41 // Get the access tokens
42 await setAccessTokensToServers(servers)
44 // Server 1 and server 2 follow each other
45 await doubleFollow(servers[0], servers[1])
46 // Server 1 and server 3 follow each other
47 await doubleFollow(servers[0], servers[2])
48 // Server 2 and server 3 follow each other
49 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, {})
59 const res = await createUser({
60 url: servers[ 0 ].url,
61 accessToken: servers[ 0 ].accessToken,
62 username: user.username,
63 password: user.password
65 userId = res.body.user.id
66 userAccessToken = await userLogin(servers[ 0 ], user)
70 const resVideo = await uploadVideo(servers[ 0 ].url, userAccessToken, {})
71 videoUUID = resVideo.body.video.uuid
74 await waitJobs(servers)
77 it('Should be able to update my display name', async function () {
82 accessToken: servers[0].accessToken,
83 displayName: 'my super display name'
86 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
89 const account: Account = user.account
90 expect(user.account.displayName).to.equal('my super display name')
92 await waitJobs(servers)
95 it('Should be able to update my description', async function () {
100 accessToken: servers[0].accessToken,
101 description: 'my super description updated'
104 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
106 expect(user.account.displayName).to.equal('my super display name')
107 expect(user.account.description).to.equal('my super description updated')
109 await waitJobs(servers)
112 it('Should be able to update my avatar', async function () {
115 const fixture = 'avatar2.png'
117 await updateMyAvatar({
119 accessToken: servers[0].accessToken,
123 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
126 userAvatarFilename = user.account.avatar.path
128 await testImage(servers[0].url, 'avatar2-resized', userAvatarFilename, '.png')
130 await waitJobs(servers)
133 it('Should have updated my profile on other servers too', async function () {
134 for (const server of servers) {
135 const resAccounts = await getAccountsList(server.url, '-createdAt')
137 const rootServer1List = resAccounts.body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port) as Account
138 expect(rootServer1List).not.to.be.undefined
140 const resAccount = await getAccount(server.url, rootServer1List.name + '@' + rootServer1List.host)
141 const rootServer1Get = resAccount.body as Account
142 expect(rootServer1Get.name).to.equal('root')
143 expect(rootServer1Get.host).to.equal('localhost:' + servers[0].port)
144 expect(rootServer1Get.displayName).to.equal('my super display name')
145 expect(rootServer1Get.description).to.equal('my super description updated')
147 if (server.serverNumber === 1) {
148 expect(rootServer1Get.userId).to.be.a('number')
150 expect(rootServer1Get.userId).to.be.undefined
153 await testImage(server.url, 'avatar2-resized', rootServer1Get.avatar.path, '.png')
157 it('Should list account videos', async function () {
158 for (const server of servers) {
159 const res = await getAccountVideos(server.url, server.accessToken, 'user1@localhost:' + servers[0].port, 0, 5)
161 expect(res.body.total).to.equal(1)
162 expect(res.body.data).to.be.an('array')
163 expect(res.body.data).to.have.lengthOf(1)
164 expect(res.body.data[0].uuid).to.equal(videoUUID)
168 it('Should remove the user', async function () {
171 for (const server of servers) {
172 const resAccounts = await getAccountsList(server.url, '-createdAt')
174 const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) as Account
175 expect(accountDeleted).not.to.be.undefined
177 const resVideoChannels = await getVideoChannelsList(server.url, 0, 10)
178 const videoChannelDeleted = resVideoChannels.body.data.find(a => {
179 return a.displayName === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port
181 expect(videoChannelDeleted).not.to.be.undefined
184 await removeUser(servers[0].url, userId, servers[0].accessToken)
186 await waitJobs(servers)
188 for (const server of servers) {
189 const resAccounts = await getAccountsList(server.url, '-createdAt')
191 const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) as Account
192 expect(accountDeleted).to.be.undefined
194 const resVideoChannels = await getVideoChannelsList(server.url, 0, 10)
195 const videoChannelDeleted = resVideoChannels.body.data.find(a => {
196 return a.name === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port
198 expect(videoChannelDeleted).to.be.undefined
202 it('Should not have actor files', async () => {
203 for (const server of servers) {
204 await checkActorFilesWereRemoved(userAvatarFilename, server.internalServerNumber)
208 it('Should not have video files', async () => {
209 for (const server of servers) {
210 await checkVideoFilesWereRemoved(videoUUID, server.internalServerNumber)
214 it('Should have an empty tmp directory', async function () {
215 for (const server of servers) {
216 await checkTmpIsEmpty(server)
220 after(async function () {
221 await cleanupTests(servers)