1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
6 checkActorFilesWereRemoved,
8 checkVideoFilesWereRemoved,
11 createMultipleServers,
13 setAccessTokensToServers,
16 } from '@shared/extra-utils'
17 import { User } from '@shared/models'
19 const expect = chai.expect
21 describe('Test users with multiple servers', function () {
22 let servers: PeerTubeServer[] = []
26 let userAccessToken: string
27 let userAvatarFilename: string
29 before(async function () {
32 servers = await createMultipleServers(3)
34 // Get the access tokens
35 await setAccessTokensToServers(servers)
37 // Server 1 and server 2 follow each other
38 await doubleFollow(servers[0], servers[1])
39 // Server 1 and server 3 follow each other
40 await doubleFollow(servers[0], servers[2])
41 // Server 2 and server 3 follow each other
42 await doubleFollow(servers[1], servers[2])
44 // The root user of server 1 is propagated to servers 2 and 3
45 await servers[0].videos.upload()
52 const created = await servers[0].users.create(user)
54 userAccessToken = await servers[0].login.getAccessToken(user)
58 const { uuid } = await servers[0].videos.upload({ token: userAccessToken })
62 await waitJobs(servers)
65 it('Should be able to update my display name', async function () {
68 await servers[0].users.updateMe({ displayName: 'my super display name' })
70 user = await servers[0].users.getMyInfo()
71 expect(user.account.displayName).to.equal('my super display name')
73 await waitJobs(servers)
76 it('Should be able to update my description', async function () {
79 await servers[0].users.updateMe({ description: 'my super description updated' })
81 user = await servers[0].users.getMyInfo()
82 expect(user.account.displayName).to.equal('my super display name')
83 expect(user.account.description).to.equal('my super description updated')
85 await waitJobs(servers)
88 it('Should be able to update my avatar', async function () {
91 const fixture = 'avatar2.png'
93 await servers[0].users.updateMyAvatar({ fixture })
95 user = await servers[0].users.getMyInfo()
96 userAvatarFilename = user.account.avatar.path
98 await testImage(servers[0].url, 'avatar2-resized', userAvatarFilename, '.png')
100 await waitJobs(servers)
103 it('Should have updated my profile on other servers too', async function () {
104 let createdAt: string | Date
106 for (const server of servers) {
107 const body = await server.accounts.list({ sort: '-createdAt' })
109 const resList = body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port)
110 expect(resList).not.to.be.undefined
112 const account = await server.accounts.get({ accountName: resList.name + '@' + resList.host })
114 if (!createdAt) createdAt = account.createdAt
116 expect(account.name).to.equal('root')
117 expect(account.host).to.equal('localhost:' + servers[0].port)
118 expect(account.displayName).to.equal('my super display name')
119 expect(account.description).to.equal('my super description updated')
120 expect(createdAt).to.equal(account.createdAt)
122 if (server.serverNumber === 1) {
123 expect(account.userId).to.be.a('number')
125 expect(account.userId).to.be.undefined
128 await testImage(server.url, 'avatar2-resized', account.avatar.path, '.png')
132 it('Should list account videos', async function () {
133 for (const server of servers) {
134 const { total, data } = await server.videos.listByAccount({ handle: 'user1@localhost:' + servers[0].port })
136 expect(total).to.equal(1)
137 expect(data).to.be.an('array')
138 expect(data).to.have.lengthOf(1)
139 expect(data[0].uuid).to.equal(videoUUID)
143 it('Should search through account videos', async function () {
146 const created = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: 'Kami no chikara' } })
148 await waitJobs(servers)
150 for (const server of servers) {
151 const { total, data } = await server.videos.listByAccount({ handle: 'user1@localhost:' + servers[0].port, search: 'Kami' })
153 expect(total).to.equal(1)
154 expect(data).to.be.an('array')
155 expect(data).to.have.lengthOf(1)
156 expect(data[0].uuid).to.equal(created.uuid)
160 it('Should remove the user', async function () {
163 for (const server of servers) {
164 const body = await server.accounts.list({ sort: '-createdAt' })
166 const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
167 expect(accountDeleted).not.to.be.undefined
169 const { data } = await server.channels.list()
170 const videoChannelDeleted = data.find(a => a.displayName === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port)
171 expect(videoChannelDeleted).not.to.be.undefined
174 await servers[0].users.remove({ userId })
176 await waitJobs(servers)
178 for (const server of servers) {
179 const body = await server.accounts.list({ sort: '-createdAt' })
181 const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
182 expect(accountDeleted).to.be.undefined
184 const { data } = await server.channels.list()
185 const videoChannelDeleted = data.find(a => a.name === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port)
186 expect(videoChannelDeleted).to.be.undefined
190 it('Should not have actor files', async () => {
191 for (const server of servers) {
192 await checkActorFilesWereRemoved(userAvatarFilename, server.internalServerNumber)
196 it('Should not have video files', async () => {
197 for (const server of servers) {
198 await checkVideoFilesWereRemoved(videoUUID, server)
202 it('Should have an empty tmp directory', async function () {
203 for (const server of servers) {
204 await checkTmpIsEmpty(server)
208 after(async function () {
209 await cleanupTests(servers)