1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
6 checkActorFilesWereRemoved,
8 checkVideoFilesWereRemoved,
12 flushAndRunMultipleServers,
17 setAccessTokensToServers,
24 } from '@shared/extra-utils'
25 import { User } from '@shared/models'
27 const expect = chai.expect
29 describe('Test users with multiple servers', function () {
30 let servers: ServerInfo[] = []
34 let userAccessToken: string
35 let userAvatarFilename: string
37 before(async function () {
40 servers = await flushAndRunMultipleServers(3)
42 // Get the access tokens
43 await setAccessTokensToServers(servers)
45 // Server 1 and server 2 follow each other
46 await doubleFollow(servers[0], servers[1])
47 // Server 1 and server 3 follow each other
48 await doubleFollow(servers[0], servers[2])
49 // Server 2 and server 3 follow each other
50 await doubleFollow(servers[1], servers[2])
52 // The root user of server 1 is propagated to servers 2 and 3
53 await uploadVideo(servers[0].url, servers[0].accessToken, {})
60 const res = await createUser({
62 accessToken: servers[0].accessToken,
63 username: user.username,
64 password: user.password
66 userId = res.body.user.id
67 userAccessToken = await userLogin(servers[0], user)
71 const resVideo = await uploadVideo(servers[0].url, userAccessToken, {})
72 videoUUID = resVideo.body.video.uuid
75 await waitJobs(servers)
78 it('Should be able to update my display name', async function () {
83 accessToken: servers[0].accessToken,
84 displayName: 'my super display name'
87 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
90 expect(user.account.displayName).to.equal('my super display name')
92 await waitJobs(servers)
95 it('Should be able to update my description', async function () {
100 accessToken: servers[0].accessToken,
101 description: 'my super description updated'
104 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
106 expect(user.account.displayName).to.equal('my super display name')
107 expect(user.account.description).to.equal('my super description updated')
109 await waitJobs(servers)
112 it('Should be able to update my avatar', async function () {
115 const fixture = 'avatar2.png'
117 await updateMyAvatar({
119 accessToken: servers[0].accessToken,
123 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
126 userAvatarFilename = user.account.avatar.path
128 await testImage(servers[0].url, 'avatar2-resized', userAvatarFilename, '.png')
130 await waitJobs(servers)
133 it('Should have updated my profile on other servers too', async function () {
134 let createdAt: string | Date
136 for (const server of servers) {
137 const body = await server.accountsCommand.list({ sort: '-createdAt' })
139 const resList = body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port)
140 expect(resList).not.to.be.undefined
142 const account = await server.accountsCommand.get({ accountName: resList.name + '@' + resList.host })
144 if (!createdAt) createdAt = account.createdAt
146 expect(account.name).to.equal('root')
147 expect(account.host).to.equal('localhost:' + servers[0].port)
148 expect(account.displayName).to.equal('my super display name')
149 expect(account.description).to.equal('my super description updated')
150 expect(createdAt).to.equal(account.createdAt)
152 if (server.serverNumber === 1) {
153 expect(account.userId).to.be.a('number')
155 expect(account.userId).to.be.undefined
158 await testImage(server.url, 'avatar2-resized', account.avatar.path, '.png')
162 it('Should list account videos', async function () {
163 for (const server of servers) {
164 const res = await getAccountVideos(server.url, server.accessToken, 'user1@localhost:' + servers[0].port, 0, 5)
166 expect(res.body.total).to.equal(1)
167 expect(res.body.data).to.be.an('array')
168 expect(res.body.data).to.have.lengthOf(1)
169 expect(res.body.data[0].uuid).to.equal(videoUUID)
173 it('Should search through account videos', async function () {
176 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'Kami no chikara' })
178 await waitJobs(servers)
180 for (const server of servers) {
181 const res = await getAccountVideos(server.url, server.accessToken, 'user1@localhost:' + servers[0].port, 0, 5, undefined, {
185 expect(res.body.total).to.equal(1)
186 expect(res.body.data).to.be.an('array')
187 expect(res.body.data).to.have.lengthOf(1)
188 expect(res.body.data[0].uuid).to.equal(resVideo.body.video.uuid)
192 it('Should remove the user', async function () {
195 for (const server of servers) {
196 const body = await server.accountsCommand.list({ sort: '-createdAt' })
198 const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
199 expect(accountDeleted).not.to.be.undefined
201 const { data } = await server.channelsCommand.list()
202 const videoChannelDeleted = data.find(a => a.displayName === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port)
203 expect(videoChannelDeleted).not.to.be.undefined
206 await removeUser(servers[0].url, userId, servers[0].accessToken)
208 await waitJobs(servers)
210 for (const server of servers) {
211 const body = await server.accountsCommand.list({ sort: '-createdAt' })
213 const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
214 expect(accountDeleted).to.be.undefined
216 const { data } = await server.channelsCommand.list()
217 const videoChannelDeleted = data.find(a => a.name === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port)
218 expect(videoChannelDeleted).to.be.undefined
222 it('Should not have actor files', async () => {
223 for (const server of servers) {
224 await checkActorFilesWereRemoved(userAvatarFilename, server.internalServerNumber)
228 it('Should not have video files', async () => {
229 for (const server of servers) {
230 await checkVideoFilesWereRemoved(videoUUID, server.internalServerNumber)
234 it('Should have an empty tmp directory', async function () {
235 for (const server of servers) {
236 await checkTmpIsEmpty(server)
240 after(async function () {
241 await cleanupTests(servers)