1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { Account } from '../../../../shared/models/actors'
7 checkVideoFilesWereRemoved, createUser, doubleFollow, flushAndRunMultipleServers, removeUser, updateMyUser, userLogin,
10 import { flushTests, getMyUserInformation, killallServers, ServerInfo, testImage, updateMyAvatar, uploadVideo } from '../../utils/index'
11 import { checkActorFilesWereRemoved, getAccount, getAccountsList } from '../../utils/users/accounts'
12 import { setAccessTokensToServers } from '../../utils/users/login'
14 const expect = chai.expect
16 describe('Test users with multiple servers', function () {
17 let servers: ServerInfo[] = []
24 before(async function () {
27 servers = await flushAndRunMultipleServers(3)
29 // Get the access tokens
30 await setAccessTokensToServers(servers)
32 // Server 1 and server 2 follow each other
33 await doubleFollow(servers[0], servers[1])
34 // Server 1 and server 3 follow each other
35 await doubleFollow(servers[0], servers[2])
36 // Server 2 and server 3 follow each other
37 await doubleFollow(servers[1], servers[2])
39 // The root user of server 1 is propagated to servers 2 and 3
40 await uploadVideo(servers[0].url, servers[0].accessToken, {})
46 const resUser = await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
47 userUUID = resUser.body.user.uuid
48 userId = resUser.body.user.id
49 userAccessToken = await userLogin(servers[0], user)
51 const resVideo = await uploadVideo(servers[0].url, userAccessToken, {})
52 videoUUID = resVideo.body.uuid
57 it('Should be able to update my description', async function () {
62 accessToken: servers[0].accessToken,
63 description: 'my super description updated'
66 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
68 expect(user.account.description).to.equal('my super description updated')
73 it('Should be able to update my avatar', async function () {
76 const fixture = 'avatar2.png'
78 await updateMyAvatar({
80 accessToken: servers[0].accessToken,
84 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
87 await testImage(servers[0].url, 'avatar2-resized', user.account.avatar.path, '.png')
92 it('Should have updated my avatar and my description on other servers too', async function () {
93 for (const server of servers) {
94 const resAccounts = await getAccountsList(server.url, '-createdAt')
96 const rootServer1List = resAccounts.body.data.find(a => a.name === 'root' && a.host === 'localhost:9001') as Account
97 expect(rootServer1List).not.to.be.undefined
99 const resAccount = await getAccount(server.url, rootServer1List.id)
100 const rootServer1Get = resAccount.body as Account
101 expect(rootServer1Get.name).to.equal('root')
102 expect(rootServer1Get.host).to.equal('localhost:9001')
103 expect(rootServer1Get.description).to.equal('my super description updated')
105 await testImage(server.url, 'avatar2-resized', rootServer1Get.avatar.path, '.png')
109 it('Should remove the user', async function () {
112 for (const server of servers) {
113 const resAccounts = await getAccountsList(server.url, '-createdAt')
115 const userServer1List = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:9001') as Account
116 expect(userServer1List).not.to.be.undefined
119 await removeUser(servers[0].url, userId, servers[0].accessToken)
123 for (const server of servers) {
124 const resAccounts = await getAccountsList(server.url, '-createdAt')
126 const userServer1List = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:9001') as Account
127 expect(userServer1List).to.be.undefined
131 it('Should not have actor files', async () => {
132 for (const server of servers) {
133 await checkActorFilesWereRemoved(userUUID, server.serverNumber)
137 it('Should not have video files', async () => {
138 for (const server of servers) {
139 await checkVideoFilesWereRemoved(videoUUID, server.serverNumber)
143 after(async function () {
144 killallServers(servers)
146 // Keep the logs if the test failed