1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
6 checkActorFilesWereRemoved,
8 checkVideoFilesWereRemoved,
11 } from '@server/tests/shared'
12 import { MyUser } from '@shared/models'
15 createMultipleServers,
18 setAccessTokensToServers,
19 setDefaultChannelAvatar,
21 } from '@shared/server-commands'
23 const expect = chai.expect
25 describe('Test users with multiple servers', function () {
26 let servers: PeerTubeServer[] = []
32 let userAccessToken: string
33 let userAvatarFilenames: string[]
35 before(async function () {
38 servers = await createMultipleServers(3)
40 // Get the access tokens
41 await setAccessTokensToServers(servers)
42 await setDefaultChannelAvatar(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 servers[0].videos.upload()
55 const username = 'user1'
56 const created = await servers[0].users.create({ username })
58 userAccessToken = await servers[0].login.getAccessToken(username)
62 const { uuid } = await servers[0].videos.upload({ token: userAccessToken })
65 await waitJobs(servers)
67 await saveVideoInServers(servers, videoUUID)
71 it('Should be able to update my display name', async function () {
74 await servers[0].users.updateMe({ displayName: 'my super display name' })
76 user = await servers[0].users.getMyInfo()
77 expect(user.account.displayName).to.equal('my super display name')
79 await waitJobs(servers)
82 it('Should be able to update my description', async function () {
85 await servers[0].users.updateMe({ description: 'my super description updated' })
87 user = await servers[0].users.getMyInfo()
88 expect(user.account.displayName).to.equal('my super display name')
89 expect(user.account.description).to.equal('my super description updated')
91 await waitJobs(servers)
94 it('Should be able to update my avatar', async function () {
97 const fixture = 'avatar2.png'
99 await servers[0].users.updateMyAvatar({ fixture })
101 user = await servers[0].users.getMyInfo()
102 userAvatarFilenames = user.account.avatars.map(({ path }) => path)
104 for (const avatar of user.account.avatars) {
105 await testImage(servers[0].url, `avatar2-resized-${avatar.width}x${avatar.width}`, avatar.path, '.png')
108 await waitJobs(servers)
111 it('Should have updated my profile on other servers too', async function () {
112 let createdAt: string | Date
114 for (const server of servers) {
115 const body = await server.accounts.list({ sort: '-createdAt' })
117 const resList = body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port)
118 expect(resList).not.to.be.undefined
120 const account = await server.accounts.get({ accountName: resList.name + '@' + resList.host })
122 if (!createdAt) createdAt = account.createdAt
124 expect(account.name).to.equal('root')
125 expect(account.host).to.equal('localhost:' + servers[0].port)
126 expect(account.displayName).to.equal('my super display name')
127 expect(account.description).to.equal('my super description updated')
128 expect(createdAt).to.equal(account.createdAt)
130 if (server.serverNumber === 1) {
131 expect(account.userId).to.be.a('number')
133 expect(account.userId).to.be.undefined
136 for (const avatar of account.avatars) {
137 await testImage(server.url, `avatar2-resized-${avatar.width}x${avatar.width}`, avatar.path, '.png')
142 it('Should list account videos', async function () {
143 for (const server of servers) {
144 const { total, data } = await server.videos.listByAccount({ handle: 'user1@localhost:' + servers[0].port })
146 expect(total).to.equal(1)
147 expect(data).to.be.an('array')
148 expect(data).to.have.lengthOf(1)
149 expect(data[0].uuid).to.equal(videoUUID)
153 it('Should search through account videos', async function () {
156 const created = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: 'Kami no chikara' } })
158 await waitJobs(servers)
160 for (const server of servers) {
161 const { total, data } = await server.videos.listByAccount({ handle: 'user1@localhost:' + servers[0].port, search: 'Kami' })
163 expect(total).to.equal(1)
164 expect(data).to.be.an('array')
165 expect(data).to.have.lengthOf(1)
166 expect(data[0].uuid).to.equal(created.uuid)
170 it('Should remove the user', async function () {
173 for (const server of servers) {
174 const body = await server.accounts.list({ sort: '-createdAt' })
176 const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
177 expect(accountDeleted).not.to.be.undefined
179 const { data } = await server.channels.list()
180 const videoChannelDeleted = data.find(a => a.displayName === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port)
181 expect(videoChannelDeleted).not.to.be.undefined
184 await servers[0].users.remove({ userId })
186 await waitJobs(servers)
188 for (const server of servers) {
189 const body = await server.accounts.list({ sort: '-createdAt' })
191 const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
192 expect(accountDeleted).to.be.undefined
194 const { data } = await server.channels.list()
195 const videoChannelDeleted = data.find(a => a.name === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port)
196 expect(videoChannelDeleted).to.be.undefined
200 it('Should not have actor files', async () => {
201 for (const server of servers) {
202 for (const userAvatarFilename of userAvatarFilenames) {
203 await checkActorFilesWereRemoved(userAvatarFilename, server.internalServerNumber)
208 it('Should not have video files', async () => {
209 for (const server of servers) {
210 await checkVideoFilesWereRemoved({ server, video: server.store.videoDetails })
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)