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 () {
69 await servers[0].users.updateMe({ displayName: 'my super display name' })
71 user = await servers[0].users.getMyInfo()
72 expect(user.account.displayName).to.equal('my super display name')
74 await waitJobs(servers)
77 it('Should be able to update my description', async function () {
80 await servers[0].users.updateMe({ description: 'my super description updated' })
82 user = await servers[0].users.getMyInfo()
83 expect(user.account.displayName).to.equal('my super display name')
84 expect(user.account.description).to.equal('my super description updated')
86 await waitJobs(servers)
89 it('Should be able to update my avatar', async function () {
92 const fixture = 'avatar2.png'
94 await servers[0].users.updateMyAvatar({ fixture })
96 user = await servers[0].users.getMyInfo()
97 userAvatarFilenames = user.account.avatars.map(({ path }) => path)
99 for (const avatar of user.account.avatars) {
100 await testImage(servers[0].url, `avatar2-resized-${avatar.width}x${avatar.width}`, avatar.path, '.png')
103 await waitJobs(servers)
106 it('Should have updated my profile on other servers too', async function () {
107 let createdAt: string | Date
109 for (const server of servers) {
110 const body = await server.accounts.list({ sort: '-createdAt' })
112 const resList = body.data.find(a => a.name === 'root' && a.host === servers[0].host)
113 expect(resList).not.to.be.undefined
115 const account = await server.accounts.get({ accountName: resList.name + '@' + resList.host })
117 if (!createdAt) createdAt = account.createdAt
119 expect(account.name).to.equal('root')
120 expect(account.host).to.equal(servers[0].host)
121 expect(account.displayName).to.equal('my super display name')
122 expect(account.description).to.equal('my super description updated')
123 expect(createdAt).to.equal(account.createdAt)
125 if (server.serverNumber === 1) {
126 expect(account.userId).to.be.a('number')
128 expect(account.userId).to.be.undefined
131 for (const avatar of account.avatars) {
132 await testImage(server.url, `avatar2-resized-${avatar.width}x${avatar.width}`, avatar.path, '.png')
137 it('Should list account videos', async function () {
138 for (const server of servers) {
139 const { total, data } = await server.videos.listByAccount({ handle: 'user1@' + servers[0].host })
141 expect(total).to.equal(1)
142 expect(data).to.be.an('array')
143 expect(data).to.have.lengthOf(1)
144 expect(data[0].uuid).to.equal(videoUUID)
148 it('Should search through account videos', async function () {
149 const created = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: 'Kami no chikara' } })
151 await waitJobs(servers)
153 for (const server of servers) {
154 const { total, data } = await server.videos.listByAccount({ handle: 'user1@' + servers[0].host, search: 'Kami' })
156 expect(total).to.equal(1)
157 expect(data).to.be.an('array')
158 expect(data).to.have.lengthOf(1)
159 expect(data[0].uuid).to.equal(created.uuid)
163 it('Should remove the user', async function () {
166 for (const server of servers) {
167 const body = await server.accounts.list({ sort: '-createdAt' })
169 const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === servers[0].host)
170 expect(accountDeleted).not.to.be.undefined
172 const { data } = await server.channels.list()
173 const videoChannelDeleted = data.find(a => a.displayName === 'Main user1 channel' && a.host === servers[0].host)
174 expect(videoChannelDeleted).not.to.be.undefined
177 await servers[0].users.remove({ userId })
179 await waitJobs(servers)
181 for (const server of servers) {
182 const body = await server.accounts.list({ sort: '-createdAt' })
184 const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === servers[0].host)
185 expect(accountDeleted).to.be.undefined
187 const { data } = await server.channels.list()
188 const videoChannelDeleted = data.find(a => a.name === 'Main user1 channel' && a.host === servers[0].host)
189 expect(videoChannelDeleted).to.be.undefined
193 it('Should not have actor files', async () => {
194 for (const server of servers) {
195 for (const userAvatarFilename of userAvatarFilenames) {
196 await checkActorFilesWereRemoved(userAvatarFilename, server)
201 it('Should not have video files', async () => {
202 for (const server of servers) {
203 await checkVideoFilesWereRemoved({ server, video: server.store.videoDetails })
207 it('Should have an empty tmp directory', async function () {
208 for (const server of servers) {
209 await checkTmpIsEmpty(server)
213 after(async function () {
214 await cleanupTests(servers)