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