]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/users/users-multiple-servers.ts
We don't need to import mocha
[github/Chocobozzz/PeerTube.git] / server / tests / api / users / users-multiple-servers.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import * as chai from 'chai'
4 import {
5 checkActorFilesWereRemoved,
6 checkTmpIsEmpty,
7 checkVideoFilesWereRemoved,
8 saveVideoInServers,
9 testImage
10 } from '@server/tests/shared'
11 import { MyUser } from '@shared/models'
12 import {
13 cleanupTests,
14 createMultipleServers,
15 doubleFollow,
16 PeerTubeServer,
17 setAccessTokensToServers,
18 setDefaultChannelAvatar,
19 waitJobs
20 } from '@shared/server-commands'
21
22 const expect = chai.expect
23
24 describe('Test users with multiple servers', function () {
25 let servers: PeerTubeServer[] = []
26
27 let user: MyUser
28 let userId: number
29
30 let videoUUID: string
31 let userAccessToken: string
32 let userAvatarFilenames: string[]
33
34 before(async function () {
35 this.timeout(120_000)
36
37 servers = await createMultipleServers(3)
38
39 // Get the access tokens
40 await setAccessTokensToServers(servers)
41 await setDefaultChannelAvatar(servers)
42
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])
49
50 // The root user of server 1 is propagated to servers 2 and 3
51 await servers[0].videos.upload()
52
53 {
54 const username = 'user1'
55 const created = await servers[0].users.create({ username })
56 userId = created.id
57 userAccessToken = await servers[0].login.getAccessToken(username)
58 }
59
60 {
61 const { uuid } = await servers[0].videos.upload({ token: userAccessToken })
62 videoUUID = uuid
63
64 await waitJobs(servers)
65
66 await saveVideoInServers(servers, videoUUID)
67 }
68 })
69
70 it('Should be able to update my display name', async function () {
71 this.timeout(10000)
72
73 await servers[0].users.updateMe({ displayName: 'my super display name' })
74
75 user = await servers[0].users.getMyInfo()
76 expect(user.account.displayName).to.equal('my super display name')
77
78 await waitJobs(servers)
79 })
80
81 it('Should be able to update my description', async function () {
82 this.timeout(10_000)
83
84 await servers[0].users.updateMe({ description: 'my super description updated' })
85
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')
89
90 await waitJobs(servers)
91 })
92
93 it('Should be able to update my avatar', async function () {
94 this.timeout(10_000)
95
96 const fixture = 'avatar2.png'
97
98 await servers[0].users.updateMyAvatar({ fixture })
99
100 user = await servers[0].users.getMyInfo()
101 userAvatarFilenames = user.account.avatars.map(({ path }) => path)
102
103 for (const avatar of user.account.avatars) {
104 await testImage(servers[0].url, `avatar2-resized-${avatar.width}x${avatar.width}`, avatar.path, '.png')
105 }
106
107 await waitJobs(servers)
108 })
109
110 it('Should have updated my profile on other servers too', async function () {
111 let createdAt: string | Date
112
113 for (const server of servers) {
114 const body = await server.accounts.list({ sort: '-createdAt' })
115
116 const resList = body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port)
117 expect(resList).not.to.be.undefined
118
119 const account = await server.accounts.get({ accountName: resList.name + '@' + resList.host })
120
121 if (!createdAt) createdAt = account.createdAt
122
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)
128
129 if (server.serverNumber === 1) {
130 expect(account.userId).to.be.a('number')
131 } else {
132 expect(account.userId).to.be.undefined
133 }
134
135 for (const avatar of account.avatars) {
136 await testImage(server.url, `avatar2-resized-${avatar.width}x${avatar.width}`, avatar.path, '.png')
137 }
138 }
139 })
140
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 })
144
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)
149 }
150 })
151
152 it('Should search through account videos', async function () {
153 this.timeout(10_000)
154
155 const created = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: 'Kami no chikara' } })
156
157 await waitJobs(servers)
158
159 for (const server of servers) {
160 const { total, data } = await server.videos.listByAccount({ handle: 'user1@localhost:' + servers[0].port, search: 'Kami' })
161
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)
166 }
167 })
168
169 it('Should remove the user', async function () {
170 this.timeout(10_000)
171
172 for (const server of servers) {
173 const body = await server.accounts.list({ sort: '-createdAt' })
174
175 const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
176 expect(accountDeleted).not.to.be.undefined
177
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
181 }
182
183 await servers[0].users.remove({ userId })
184
185 await waitJobs(servers)
186
187 for (const server of servers) {
188 const body = await server.accounts.list({ sort: '-createdAt' })
189
190 const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
191 expect(accountDeleted).to.be.undefined
192
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
196 }
197 })
198
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)
203 }
204 }
205 })
206
207 it('Should not have video files', async () => {
208 for (const server of servers) {
209 await checkVideoFilesWereRemoved({ server, video: server.store.videoDetails })
210 }
211 })
212
213 it('Should have an empty tmp directory', async function () {
214 for (const server of servers) {
215 await checkTmpIsEmpty(server)
216 }
217 })
218
219 after(async function () {
220 await cleanupTests(servers)
221 })
222 })