1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
6 checkActorFilesWereRemoved,
8 checkVideoFilesWereRemoved,
12 flushAndRunMultipleServers,
18 setAccessTokensToServers,
25 } from '@shared/extra-utils'
26 import { User, VideoChannel } from '@shared/models'
28 const expect = chai.expect
30 describe('Test users with multiple servers', function () {
31 let servers: ServerInfo[] = []
35 let userAccessToken: string
36 let userAvatarFilename: string
38 before(async function () {
41 servers = await flushAndRunMultipleServers(3)
43 // Get the access tokens
44 await setAccessTokensToServers(servers)
46 // Server 1 and server 2 follow each other
47 await doubleFollow(servers[0], servers[1])
48 // Server 1 and server 3 follow each other
49 await doubleFollow(servers[0], servers[2])
50 // Server 2 and server 3 follow each other
51 await doubleFollow(servers[1], servers[2])
53 // The root user of server 1 is propagated to servers 2 and 3
54 await uploadVideo(servers[0].url, servers[0].accessToken, {})
61 const res = await createUser({
63 accessToken: servers[0].accessToken,
64 username: user.username,
65 password: user.password
67 userId = res.body.user.id
68 userAccessToken = await userLogin(servers[0], user)
72 const resVideo = await uploadVideo(servers[0].url, userAccessToken, {})
73 videoUUID = resVideo.body.video.uuid
76 await waitJobs(servers)
79 it('Should be able to update my display name', async function () {
84 accessToken: servers[0].accessToken,
85 displayName: 'my super display name'
88 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
91 expect(user.account.displayName).to.equal('my super display name')
93 await waitJobs(servers)
96 it('Should be able to update my description', async function () {
101 accessToken: servers[0].accessToken,
102 description: 'my super description updated'
105 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
107 expect(user.account.displayName).to.equal('my super display name')
108 expect(user.account.description).to.equal('my super description updated')
110 await waitJobs(servers)
113 it('Should be able to update my avatar', async function () {
116 const fixture = 'avatar2.png'
118 await updateMyAvatar({
120 accessToken: servers[0].accessToken,
124 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
127 userAvatarFilename = user.account.avatar.path
129 await testImage(servers[0].url, 'avatar2-resized', userAvatarFilename, '.png')
131 await waitJobs(servers)
134 it('Should have updated my profile on other servers too', async function () {
135 let createdAt: string | Date
137 for (const server of servers) {
138 const body = await server.accountsCommand.list({ sort: '-createdAt' })
140 const resList = body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port)
141 expect(resList).not.to.be.undefined
143 const account = await server.accountsCommand.get({ accountName: resList.name + '@' + resList.host })
145 if (!createdAt) createdAt = account.createdAt
147 expect(account.name).to.equal('root')
148 expect(account.host).to.equal('localhost:' + servers[0].port)
149 expect(account.displayName).to.equal('my super display name')
150 expect(account.description).to.equal('my super description updated')
151 expect(createdAt).to.equal(account.createdAt)
153 if (server.serverNumber === 1) {
154 expect(account.userId).to.be.a('number')
156 expect(account.userId).to.be.undefined
159 await testImage(server.url, 'avatar2-resized', account.avatar.path, '.png')
163 it('Should list account videos', async function () {
164 for (const server of servers) {
165 const res = await getAccountVideos(server.url, server.accessToken, 'user1@localhost:' + servers[0].port, 0, 5)
167 expect(res.body.total).to.equal(1)
168 expect(res.body.data).to.be.an('array')
169 expect(res.body.data).to.have.lengthOf(1)
170 expect(res.body.data[0].uuid).to.equal(videoUUID)
174 it('Should search through account videos', async function () {
177 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'Kami no chikara' })
179 await waitJobs(servers)
181 for (const server of servers) {
182 const res = await getAccountVideos(server.url, server.accessToken, 'user1@localhost:' + servers[0].port, 0, 5, undefined, {
186 expect(res.body.total).to.equal(1)
187 expect(res.body.data).to.be.an('array')
188 expect(res.body.data).to.have.lengthOf(1)
189 expect(res.body.data[0].uuid).to.equal(resVideo.body.video.uuid)
193 it('Should remove the user', async function () {
196 for (const server of servers) {
197 const body = await server.accountsCommand.list({ sort: '-createdAt' })
199 const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
200 expect(accountDeleted).not.to.be.undefined
202 const resVideoChannels = await getVideoChannelsList(server.url, 0, 10)
203 const videoChannelDeleted = resVideoChannels.body.data.find(a => {
204 return a.displayName === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port
206 expect(videoChannelDeleted).not.to.be.undefined
209 await removeUser(servers[0].url, userId, servers[0].accessToken)
211 await waitJobs(servers)
213 for (const server of servers) {
214 const body = await server.accountsCommand.list({ sort: '-createdAt' })
216 const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
217 expect(accountDeleted).to.be.undefined
219 const resVideoChannels = await getVideoChannelsList(server.url, 0, 10)
220 const videoChannelDeleted = resVideoChannels.body.data.find(a => {
221 return a.name === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port
223 expect(videoChannelDeleted).to.be.undefined
227 it('Should not have actor files', async () => {
228 for (const server of servers) {
229 await checkActorFilesWereRemoved(userAvatarFilename, server.internalServerNumber)
233 it('Should not have video files', async () => {
234 for (const server of servers) {
235 await checkVideoFilesWereRemoved(videoUUID, server.internalServerNumber)
239 it('Should have an empty tmp directory', async function () {
240 for (const server of servers) {
241 await checkTmpIsEmpty(server)
245 after(async function () {
246 await cleanupTests(servers)