1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
6 checkActorFilesWereRemoved,
8 checkVideoFilesWereRemoved,
10 createMultipleServers,
14 setAccessTokensToServers,
17 } from '@shared/extra-utils'
18 import { MyUser } from '@shared/models'
20 const expect = chai.expect
22 describe('Test users with multiple servers', function () {
23 let servers: PeerTubeServer[] = []
29 let userAccessToken: string
30 let userAvatarFilename: string
32 before(async function () {
35 servers = await createMultipleServers(3)
37 // Get the access tokens
38 await setAccessTokensToServers(servers)
40 // Server 1 and server 2 follow each other
41 await doubleFollow(servers[0], servers[1])
42 // Server 1 and server 3 follow each other
43 await doubleFollow(servers[0], servers[2])
44 // Server 2 and server 3 follow each other
45 await doubleFollow(servers[1], servers[2])
47 // The root user of server 1 is propagated to servers 2 and 3
48 await servers[0].videos.upload()
51 const username = 'user1'
52 const created = await servers[0].users.create({ username })
54 userAccessToken = await servers[0].login.getAccessToken(username)
58 const { uuid } = await servers[0].videos.upload({ token: userAccessToken })
61 await waitJobs(servers)
63 await saveVideoInServers(servers, videoUUID)
67 it('Should be able to update my display name', async function () {
70 await servers[0].users.updateMe({ displayName: 'my super display name' })
72 user = await servers[0].users.getMyInfo()
73 expect(user.account.displayName).to.equal('my super display name')
75 await waitJobs(servers)
78 it('Should be able to update my description', async function () {
81 await servers[0].users.updateMe({ description: 'my super description updated' })
83 user = await servers[0].users.getMyInfo()
84 expect(user.account.displayName).to.equal('my super display name')
85 expect(user.account.description).to.equal('my super description updated')
87 await waitJobs(servers)
90 it('Should be able to update my avatar', async function () {
93 const fixture = 'avatar2.png'
95 await servers[0].users.updateMyAvatar({ fixture })
97 user = await servers[0].users.getMyInfo()
98 userAvatarFilename = user.account.avatar.path
100 await testImage(servers[0].url, 'avatar2-resized', userAvatarFilename, '.png')
102 await waitJobs(servers)
105 it('Should have updated my profile on other servers too', async function () {
106 let createdAt: string | Date
108 for (const server of servers) {
109 const body = await server.accounts.list({ sort: '-createdAt' })
111 const resList = body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port)
112 expect(resList).not.to.be.undefined
114 const account = await server.accounts.get({ accountName: resList.name + '@' + resList.host })
116 if (!createdAt) createdAt = account.createdAt
118 expect(account.name).to.equal('root')
119 expect(account.host).to.equal('localhost:' + servers[0].port)
120 expect(account.displayName).to.equal('my super display name')
121 expect(account.description).to.equal('my super description updated')
122 expect(createdAt).to.equal(account.createdAt)
124 if (server.serverNumber === 1) {
125 expect(account.userId).to.be.a('number')
127 expect(account.userId).to.be.undefined
130 await testImage(server.url, 'avatar2-resized', account.avatar.path, '.png')
134 it('Should list account videos', async function () {
135 for (const server of servers) {
136 const { total, data } = await server.videos.listByAccount({ handle: 'user1@localhost:' + servers[0].port })
138 expect(total).to.equal(1)
139 expect(data).to.be.an('array')
140 expect(data).to.have.lengthOf(1)
141 expect(data[0].uuid).to.equal(videoUUID)
145 it('Should search through account videos', async function () {
148 const created = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: 'Kami no chikara' } })
150 await waitJobs(servers)
152 for (const server of servers) {
153 const { total, data } = await server.videos.listByAccount({ handle: 'user1@localhost:' + servers[0].port, search: 'Kami' })
155 expect(total).to.equal(1)
156 expect(data).to.be.an('array')
157 expect(data).to.have.lengthOf(1)
158 expect(data[0].uuid).to.equal(created.uuid)
162 it('Should remove the user', async function () {
165 for (const server of servers) {
166 const body = await server.accounts.list({ sort: '-createdAt' })
168 const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
169 expect(accountDeleted).not.to.be.undefined
171 const { data } = await server.channels.list()
172 const videoChannelDeleted = data.find(a => a.displayName === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port)
173 expect(videoChannelDeleted).not.to.be.undefined
176 await servers[0].users.remove({ userId })
178 await waitJobs(servers)
180 for (const server of servers) {
181 const body = await server.accounts.list({ sort: '-createdAt' })
183 const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
184 expect(accountDeleted).to.be.undefined
186 const { data } = await server.channels.list()
187 const videoChannelDeleted = data.find(a => a.name === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port)
188 expect(videoChannelDeleted).to.be.undefined
192 it('Should not have actor files', async () => {
193 for (const server of servers) {
194 await checkActorFilesWereRemoved(userAvatarFilename, server.internalServerNumber)
198 it('Should not have video files', async () => {
199 for (const server of servers) {
200 await checkVideoFilesWereRemoved({ server, video: server.store.videoDetails })
204 it('Should have an empty tmp directory', async function () {
205 for (const server of servers) {
206 await checkTmpIsEmpty(server)
210 after(async function () {
211 await cleanupTests(servers)