1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } 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 describe('Test users with multiple servers', function () {
23 let servers: PeerTubeServer[] = []
29 let userAccessToken: string
30 let userAvatarFilenames: string[]
32 before(async function () {
35 servers = await createMultipleServers(3)
37 // Get the access tokens
38 await setAccessTokensToServers(servers)
39 await setDefaultChannelAvatar(servers)
41 // Server 1 and server 2 follow each other
42 await doubleFollow(servers[0], servers[1])
43 // Server 1 and server 3 follow each other
44 await doubleFollow(servers[0], servers[2])
45 // Server 2 and server 3 follow each other
46 await doubleFollow(servers[1], servers[2])
48 // The root user of server 1 is propagated to servers 2 and 3
49 await servers[0].videos.upload()
52 const username = 'user1'
53 const created = await servers[0].users.create({ username })
55 userAccessToken = await servers[0].login.getAccessToken(username)
59 const { uuid } = await servers[0].videos.upload({ token: userAccessToken })
62 await waitJobs(servers)
64 await saveVideoInServers(servers, videoUUID)
68 it('Should be able to update my display name', async function () {
71 await servers[0].users.updateMe({ displayName: 'my super display name' })
73 user = await servers[0].users.getMyInfo()
74 expect(user.account.displayName).to.equal('my super display name')
76 await waitJobs(servers)
79 it('Should be able to update my description', async function () {
82 await servers[0].users.updateMe({ description: 'my super description updated' })
84 user = await servers[0].users.getMyInfo()
85 expect(user.account.displayName).to.equal('my super display name')
86 expect(user.account.description).to.equal('my super description updated')
88 await waitJobs(servers)
91 it('Should be able to update my avatar', async function () {
94 const fixture = 'avatar2.png'
96 await servers[0].users.updateMyAvatar({ fixture })
98 user = await servers[0].users.getMyInfo()
99 userAvatarFilenames = user.account.avatars.map(({ path }) => path)
101 for (const avatar of user.account.avatars) {
102 await testImage(servers[0].url, `avatar2-resized-${avatar.width}x${avatar.width}`, avatar.path, '.png')
105 await waitJobs(servers)
108 it('Should have updated my profile on other servers too', async function () {
109 let createdAt: string | Date
111 for (const server of servers) {
112 const body = await server.accounts.list({ sort: '-createdAt' })
114 const resList = body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port)
115 expect(resList).not.to.be.undefined
117 const account = await server.accounts.get({ accountName: resList.name + '@' + resList.host })
119 if (!createdAt) createdAt = account.createdAt
121 expect(account.name).to.equal('root')
122 expect(account.host).to.equal('localhost:' + servers[0].port)
123 expect(account.displayName).to.equal('my super display name')
124 expect(account.description).to.equal('my super description updated')
125 expect(createdAt).to.equal(account.createdAt)
127 if (server.serverNumber === 1) {
128 expect(account.userId).to.be.a('number')
130 expect(account.userId).to.be.undefined
133 for (const avatar of account.avatars) {
134 await testImage(server.url, `avatar2-resized-${avatar.width}x${avatar.width}`, avatar.path, '.png')
139 it('Should list account videos', async function () {
140 for (const server of servers) {
141 const { total, data } = await server.videos.listByAccount({ handle: 'user1@localhost:' + servers[0].port })
143 expect(total).to.equal(1)
144 expect(data).to.be.an('array')
145 expect(data).to.have.lengthOf(1)
146 expect(data[0].uuid).to.equal(videoUUID)
150 it('Should search through account videos', async function () {
153 const created = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: 'Kami no chikara' } })
155 await waitJobs(servers)
157 for (const server of servers) {
158 const { total, data } = await server.videos.listByAccount({ handle: 'user1@localhost:' + servers[0].port, search: 'Kami' })
160 expect(total).to.equal(1)
161 expect(data).to.be.an('array')
162 expect(data).to.have.lengthOf(1)
163 expect(data[0].uuid).to.equal(created.uuid)
167 it('Should remove the user', async function () {
170 for (const server of servers) {
171 const body = await server.accounts.list({ sort: '-createdAt' })
173 const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
174 expect(accountDeleted).not.to.be.undefined
176 const { data } = await server.channels.list()
177 const videoChannelDeleted = data.find(a => a.displayName === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port)
178 expect(videoChannelDeleted).not.to.be.undefined
181 await servers[0].users.remove({ userId })
183 await waitJobs(servers)
185 for (const server of servers) {
186 const body = await server.accounts.list({ sort: '-createdAt' })
188 const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
189 expect(accountDeleted).to.be.undefined
191 const { data } = await server.channels.list()
192 const videoChannelDeleted = data.find(a => a.name === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port)
193 expect(videoChannelDeleted).to.be.undefined
197 it('Should not have actor files', async () => {
198 for (const server of servers) {
199 for (const userAvatarFilename of userAvatarFilenames) {
200 await checkActorFilesWereRemoved(userAvatarFilename, server.internalServerNumber)
205 it('Should not have video files', async () => {
206 for (const server of servers) {
207 await checkVideoFilesWereRemoved({ server, video: server.store.videoDetails })
211 it('Should have an empty tmp directory', async function () {
212 for (const server of servers) {
213 await checkTmpIsEmpty(server)
217 after(async function () {
218 await cleanupTests(servers)