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