1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { Account } from '../../../../shared/models/actors'
7 checkVideoFilesWereRemoved,
10 flushAndRunMultipleServers,
18 import { flushTests, getMyUserInformation, killallServers, ServerInfo, testImage, updateMyAvatar, uploadVideo } from '../../utils/index'
19 import { checkActorFilesWereRemoved, getAccount, getAccountsList } from '../../utils/users/accounts'
20 import { setAccessTokensToServers } from '../../utils/users/login'
21 import { User } from '../../../../shared/models/users'
22 import { VideoChannel } from '../../../../shared/models/videos'
24 const expect = chai.expect
26 describe('Test users with multiple servers', function () {
27 let servers: ServerInfo[] = []
29 let userAccountUUID: 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 userAccountUUID = res.body.user.account.uuid
60 userId = res.body.user.id
62 userAccessToken = await userLogin(servers[ 0 ], user)
66 const res = await getMyUserInformation(servers[ 0 ].url, servers[ 0 ].accessToken)
67 const user: User = res.body
68 userVideoChannelUUID = user.videoChannels[0].uuid
72 const resVideo = await uploadVideo(servers[ 0 ].url, userAccessToken, {})
73 videoUUID = resVideo.body.video.uuid
79 it('Should be able to update my description', async function () {
84 accessToken: servers[0].accessToken,
85 description: 'my super description updated'
88 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
90 expect(user.account.description).to.equal('my super description updated')
95 it('Should be able to update my avatar', async function () {
98 const fixture = 'avatar2.png'
100 await updateMyAvatar({
102 accessToken: servers[0].accessToken,
106 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
109 await testImage(servers[0].url, 'avatar2-resized', user.account.avatar.path, '.png')
114 it('Should have updated my avatar and my description on other servers too', async function () {
115 for (const server of servers) {
116 const resAccounts = await getAccountsList(server.url, '-createdAt')
118 const rootServer1List = resAccounts.body.data.find(a => a.name === 'root' && a.host === 'localhost:9001') as Account
119 expect(rootServer1List).not.to.be.undefined
121 const resAccount = await getAccount(server.url, rootServer1List.id)
122 const rootServer1Get = resAccount.body as Account
123 expect(rootServer1Get.name).to.equal('root')
124 expect(rootServer1Get.host).to.equal('localhost:9001')
125 expect(rootServer1Get.description).to.equal('my super description updated')
127 await testImage(server.url, 'avatar2-resized', rootServer1Get.avatar.path, '.png')
131 it('Should list account videos', async function () {
132 for (const server of servers) {
133 const res = await getAccountVideos(server.url, server.accessToken, userAccountUUID, 0, 5)
135 expect(res.body.total).to.equal(1)
136 expect(res.body.data).to.be.an('array')
137 expect(res.body.data).to.have.lengthOf(1)
138 expect(res.body.data[0].uuid).to.equal(videoUUID)
142 it('Should remove the user', async function () {
145 for (const server of servers) {
146 const resAccounts = await getAccountsList(server.url, '-createdAt')
148 const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:9001') as Account
149 expect(accountDeleted).not.to.be.undefined
151 const resVideoChannels = await getVideoChannelsList(server.url, 0, 10)
152 const videoChannelDeleted = resVideoChannels.body.data.find(a => {
153 return a.displayName === 'Default user1 channel' && a.host === 'localhost:9001'
155 expect(videoChannelDeleted).not.to.be.undefined
158 await removeUser(servers[0].url, userId, servers[0].accessToken)
162 for (const server of servers) {
163 const resAccounts = await getAccountsList(server.url, '-createdAt')
165 const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:9001') as Account
166 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 === 'Default user1 channel' && a.host === 'localhost:9001'
172 expect(videoChannelDeleted).to.be.undefined
176 it('Should not have actor files', async () => {
177 for (const server of servers) {
178 await checkActorFilesWereRemoved(userAccountUUID, server.serverNumber)
179 await checkActorFilesWereRemoved(userVideoChannelUUID, server.serverNumber)
183 it('Should not have video files', async () => {
184 for (const server of servers) {
185 await checkVideoFilesWereRemoved(videoUUID, server.serverNumber)
189 after(async function () {
190 killallServers(servers)
192 // Keep the logs if the test failed