1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
5 checkActorFilesWereRemoved,
7 checkVideoFilesWereRemoved,
10 } from '@server/tests/shared'
11 import { MyUser } from '@shared/models'
14 createMultipleServers,
17 setAccessTokensToServers,
18 setDefaultChannelAvatar,
20 } from '@shared/server-commands'
22 const expect = chai.expect
24 describe('Test users with multiple servers', function () {
25 let servers: PeerTubeServer[] = []
31 let userAccessToken: string
32 let userAvatarFilenames: string[]
34 before(async function () {
37 servers = await createMultipleServers(3)
39 // Get the access tokens
40 await setAccessTokensToServers(servers)
41 await setDefaultChannelAvatar(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 servers[0].videos.upload()
54 const username = 'user1'
55 const created = await servers[0].users.create({ username })
57 userAccessToken = await servers[0].login.getAccessToken(username)
61 const { uuid } = await servers[0].videos.upload({ token: userAccessToken })
64 await waitJobs(servers)
66 await saveVideoInServers(servers, videoUUID)
70 it('Should be able to update my display name', async function () {
73 await servers[0].users.updateMe({ displayName: 'my super display name' })
75 user = await servers[0].users.getMyInfo()
76 expect(user.account.displayName).to.equal('my super display name')
78 await waitJobs(servers)
81 it('Should be able to update my description', async function () {
84 await servers[0].users.updateMe({ description: 'my super description updated' })
86 user = await servers[0].users.getMyInfo()
87 expect(user.account.displayName).to.equal('my super display name')
88 expect(user.account.description).to.equal('my super description updated')
90 await waitJobs(servers)
93 it('Should be able to update my avatar', async function () {
96 const fixture = 'avatar2.png'
98 await servers[0].users.updateMyAvatar({ fixture })
100 user = await servers[0].users.getMyInfo()
101 userAvatarFilenames = user.account.avatars.map(({ path }) => path)
103 for (const avatar of user.account.avatars) {
104 await testImage(servers[0].url, `avatar2-resized-${avatar.width}x${avatar.width}`, avatar.path, '.png')
107 await waitJobs(servers)
110 it('Should have updated my profile on other servers too', async function () {
111 let createdAt: string | Date
113 for (const server of servers) {
114 const body = await server.accounts.list({ sort: '-createdAt' })
116 const resList = body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port)
117 expect(resList).not.to.be.undefined
119 const account = await server.accounts.get({ accountName: resList.name + '@' + resList.host })
121 if (!createdAt) createdAt = account.createdAt
123 expect(account.name).to.equal('root')
124 expect(account.host).to.equal('localhost:' + servers[0].port)
125 expect(account.displayName).to.equal('my super display name')
126 expect(account.description).to.equal('my super description updated')
127 expect(createdAt).to.equal(account.createdAt)
129 if (server.serverNumber === 1) {
130 expect(account.userId).to.be.a('number')
132 expect(account.userId).to.be.undefined
135 for (const avatar of account.avatars) {
136 await testImage(server.url, `avatar2-resized-${avatar.width}x${avatar.width}`, avatar.path, '.png')
141 it('Should list account videos', async function () {
142 for (const server of servers) {
143 const { total, data } = await server.videos.listByAccount({ handle: 'user1@localhost:' + servers[0].port })
145 expect(total).to.equal(1)
146 expect(data).to.be.an('array')
147 expect(data).to.have.lengthOf(1)
148 expect(data[0].uuid).to.equal(videoUUID)
152 it('Should search through account videos', async function () {
155 const created = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: 'Kami no chikara' } })
157 await waitJobs(servers)
159 for (const server of servers) {
160 const { total, data } = await server.videos.listByAccount({ handle: 'user1@localhost:' + servers[0].port, search: 'Kami' })
162 expect(total).to.equal(1)
163 expect(data).to.be.an('array')
164 expect(data).to.have.lengthOf(1)
165 expect(data[0].uuid).to.equal(created.uuid)
169 it('Should remove the user', async function () {
172 for (const server of servers) {
173 const body = await server.accounts.list({ sort: '-createdAt' })
175 const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
176 expect(accountDeleted).not.to.be.undefined
178 const { data } = await server.channels.list()
179 const videoChannelDeleted = data.find(a => a.displayName === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port)
180 expect(videoChannelDeleted).not.to.be.undefined
183 await servers[0].users.remove({ userId })
185 await waitJobs(servers)
187 for (const server of servers) {
188 const body = await server.accounts.list({ sort: '-createdAt' })
190 const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
191 expect(accountDeleted).to.be.undefined
193 const { data } = await server.channels.list()
194 const videoChannelDeleted = data.find(a => a.name === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port)
195 expect(videoChannelDeleted).to.be.undefined
199 it('Should not have actor files', async () => {
200 for (const server of servers) {
201 for (const userAvatarFilename of userAvatarFilenames) {
202 await checkActorFilesWereRemoved(userAvatarFilename, server.internalServerNumber)
207 it('Should not have video files', async () => {
208 for (const server of servers) {
209 await checkVideoFilesWereRemoved({ server, video: server.store.videoDetails })
213 it('Should have an empty tmp directory', async function () {
214 for (const server of servers) {
215 await checkTmpIsEmpty(server)
219 after(async function () {
220 await cleanupTests(servers)