]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/users/users-multiple-servers.ts
Introduce change ownership command
[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 'mocha'
4 import * as chai from 'chai'
5 import {
6 checkActorFilesWereRemoved,
7 checkTmpIsEmpty,
8 checkVideoFilesWereRemoved,
9 cleanupTests,
10 createUser,
11 doubleFollow,
12 flushAndRunMultipleServers,
13 getAccountVideos,
14 getMyUserInformation,
15 getVideoChannelsList,
16 removeUser,
17 ServerInfo,
18 setAccessTokensToServers,
19 testImage,
20 updateMyAvatar,
21 updateMyUser,
22 uploadVideo,
23 userLogin,
24 waitJobs
25 } from '@shared/extra-utils'
26 import { User, VideoChannel } from '@shared/models'
27
28 const expect = chai.expect
29
30 describe('Test users with multiple servers', function () {
31 let servers: ServerInfo[] = []
32 let user: User
33 let userId: number
34 let videoUUID: string
35 let userAccessToken: string
36 let userAvatarFilename: string
37
38 before(async function () {
39 this.timeout(120_000)
40
41 servers = await flushAndRunMultipleServers(3)
42
43 // Get the access tokens
44 await setAccessTokensToServers(servers)
45
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])
52
53 // The root user of server 1 is propagated to servers 2 and 3
54 await uploadVideo(servers[0].url, servers[0].accessToken, {})
55
56 {
57 const user = {
58 username: 'user1',
59 password: 'password'
60 }
61 const res = await createUser({
62 url: servers[0].url,
63 accessToken: servers[0].accessToken,
64 username: user.username,
65 password: user.password
66 })
67 userId = res.body.user.id
68 userAccessToken = await userLogin(servers[0], user)
69 }
70
71 {
72 const resVideo = await uploadVideo(servers[0].url, userAccessToken, {})
73 videoUUID = resVideo.body.video.uuid
74 }
75
76 await waitJobs(servers)
77 })
78
79 it('Should be able to update my display name', async function () {
80 this.timeout(10000)
81
82 await updateMyUser({
83 url: servers[0].url,
84 accessToken: servers[0].accessToken,
85 displayName: 'my super display name'
86 })
87
88 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
89 user = res.body
90
91 expect(user.account.displayName).to.equal('my super display name')
92
93 await waitJobs(servers)
94 })
95
96 it('Should be able to update my description', async function () {
97 this.timeout(10_000)
98
99 await updateMyUser({
100 url: servers[0].url,
101 accessToken: servers[0].accessToken,
102 description: 'my super description updated'
103 })
104
105 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
106 user = res.body
107 expect(user.account.displayName).to.equal('my super display name')
108 expect(user.account.description).to.equal('my super description updated')
109
110 await waitJobs(servers)
111 })
112
113 it('Should be able to update my avatar', async function () {
114 this.timeout(10_000)
115
116 const fixture = 'avatar2.png'
117
118 await updateMyAvatar({
119 url: servers[0].url,
120 accessToken: servers[0].accessToken,
121 fixture
122 })
123
124 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
125 user = res.body
126
127 userAvatarFilename = user.account.avatar.path
128
129 await testImage(servers[0].url, 'avatar2-resized', userAvatarFilename, '.png')
130
131 await waitJobs(servers)
132 })
133
134 it('Should have updated my profile on other servers too', async function () {
135 let createdAt: string | Date
136
137 for (const server of servers) {
138 const body = await server.accountsCommand.list({ sort: '-createdAt' })
139
140 const resList = body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port)
141 expect(resList).not.to.be.undefined
142
143 const account = await server.accountsCommand.get({ accountName: resList.name + '@' + resList.host })
144
145 if (!createdAt) createdAt = account.createdAt
146
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)
152
153 if (server.serverNumber === 1) {
154 expect(account.userId).to.be.a('number')
155 } else {
156 expect(account.userId).to.be.undefined
157 }
158
159 await testImage(server.url, 'avatar2-resized', account.avatar.path, '.png')
160 }
161 })
162
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)
166
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)
171 }
172 })
173
174 it('Should search through account videos', async function () {
175 this.timeout(10_000)
176
177 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'Kami no chikara' })
178
179 await waitJobs(servers)
180
181 for (const server of servers) {
182 const res = await getAccountVideos(server.url, server.accessToken, 'user1@localhost:' + servers[0].port, 0, 5, undefined, {
183 search: 'Kami'
184 })
185
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)
190 }
191 })
192
193 it('Should remove the user', async function () {
194 this.timeout(10_000)
195
196 for (const server of servers) {
197 const body = await server.accountsCommand.list({ sort: '-createdAt' })
198
199 const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
200 expect(accountDeleted).not.to.be.undefined
201
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
205 }) as VideoChannel
206 expect(videoChannelDeleted).not.to.be.undefined
207 }
208
209 await removeUser(servers[0].url, userId, servers[0].accessToken)
210
211 await waitJobs(servers)
212
213 for (const server of servers) {
214 const body = await server.accountsCommand.list({ sort: '-createdAt' })
215
216 const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
217 expect(accountDeleted).to.be.undefined
218
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
222 }) as VideoChannel
223 expect(videoChannelDeleted).to.be.undefined
224 }
225 })
226
227 it('Should not have actor files', async () => {
228 for (const server of servers) {
229 await checkActorFilesWereRemoved(userAvatarFilename, server.internalServerNumber)
230 }
231 })
232
233 it('Should not have video files', async () => {
234 for (const server of servers) {
235 await checkVideoFilesWereRemoved(videoUUID, server.internalServerNumber)
236 }
237 })
238
239 it('Should have an empty tmp directory', async function () {
240 for (const server of servers) {
241 await checkTmpIsEmpty(server)
242 }
243 })
244
245 after(async function () {
246 await cleanupTests(servers)
247 })
248 })