]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/users/users-multiple-servers.ts
Move test functions outside extra-utils
[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 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 userAvatarFilename: 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
42 // Server 1 and server 2 follow each other
43 await doubleFollow(servers[0], servers[1])
44 // Server 1 and server 3 follow each other
45 await doubleFollow(servers[0], servers[2])
46 // Server 2 and server 3 follow each other
47 await doubleFollow(servers[1], servers[2])
48
49 // The root user of server 1 is propagated to servers 2 and 3
50 await servers[0].videos.upload()
51
52 {
53 const username = 'user1'
54 const created = await servers[0].users.create({ username })
55 userId = created.id
56 userAccessToken = await servers[0].login.getAccessToken(username)
57 }
58
59 {
60 const { uuid } = await servers[0].videos.upload({ token: userAccessToken })
61 videoUUID = uuid
62
63 await waitJobs(servers)
64
65 await saveVideoInServers(servers, videoUUID)
66 }
67 })
68
69 it('Should be able to update my display name', async function () {
70 this.timeout(10000)
71
72 await servers[0].users.updateMe({ displayName: 'my super display name' })
73
74 user = await servers[0].users.getMyInfo()
75 expect(user.account.displayName).to.equal('my super display name')
76
77 await waitJobs(servers)
78 })
79
80 it('Should be able to update my description', async function () {
81 this.timeout(10_000)
82
83 await servers[0].users.updateMe({ description: 'my super description updated' })
84
85 user = await servers[0].users.getMyInfo()
86 expect(user.account.displayName).to.equal('my super display name')
87 expect(user.account.description).to.equal('my super description updated')
88
89 await waitJobs(servers)
90 })
91
92 it('Should be able to update my avatar', async function () {
93 this.timeout(10_000)
94
95 const fixture = 'avatar2.png'
96
97 await servers[0].users.updateMyAvatar({ fixture })
98
99 user = await servers[0].users.getMyInfo()
100 userAvatarFilename = user.account.avatar.path
101
102 await testImage(servers[0].url, 'avatar2-resized', userAvatarFilename, '.png')
103
104 await waitJobs(servers)
105 })
106
107 it('Should have updated my profile on other servers too', async function () {
108 let createdAt: string | Date
109
110 for (const server of servers) {
111 const body = await server.accounts.list({ sort: '-createdAt' })
112
113 const resList = body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port)
114 expect(resList).not.to.be.undefined
115
116 const account = await server.accounts.get({ accountName: resList.name + '@' + resList.host })
117
118 if (!createdAt) createdAt = account.createdAt
119
120 expect(account.name).to.equal('root')
121 expect(account.host).to.equal('localhost:' + servers[0].port)
122 expect(account.displayName).to.equal('my super display name')
123 expect(account.description).to.equal('my super description updated')
124 expect(createdAt).to.equal(account.createdAt)
125
126 if (server.serverNumber === 1) {
127 expect(account.userId).to.be.a('number')
128 } else {
129 expect(account.userId).to.be.undefined
130 }
131
132 await testImage(server.url, 'avatar2-resized', account.avatar.path, '.png')
133 }
134 })
135
136 it('Should list account videos', async function () {
137 for (const server of servers) {
138 const { total, data } = await server.videos.listByAccount({ handle: 'user1@localhost:' + servers[0].port })
139
140 expect(total).to.equal(1)
141 expect(data).to.be.an('array')
142 expect(data).to.have.lengthOf(1)
143 expect(data[0].uuid).to.equal(videoUUID)
144 }
145 })
146
147 it('Should search through account videos', async function () {
148 this.timeout(10_000)
149
150 const created = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: 'Kami no chikara' } })
151
152 await waitJobs(servers)
153
154 for (const server of servers) {
155 const { total, data } = await server.videos.listByAccount({ handle: 'user1@localhost:' + servers[0].port, search: 'Kami' })
156
157 expect(total).to.equal(1)
158 expect(data).to.be.an('array')
159 expect(data).to.have.lengthOf(1)
160 expect(data[0].uuid).to.equal(created.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.accounts.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.channels.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].users.remove({ userId })
179
180 await waitJobs(servers)
181
182 for (const server of servers) {
183 const body = await server.accounts.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.channels.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({ server, video: server.store.videoDetails })
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 })