]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/users/users-multiple-servers.ts
Move typescript utils in its own directory
[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 createMultipleServers,
11 doubleFollow,
12 PeerTubeServer,
13 saveVideoInServers,
14 setAccessTokensToServers,
15 testImage,
16 waitJobs
17 } from '@shared/extra-utils'
18 import { MyUser } from '@shared/models'
19
20 const expect = chai.expect
21
22 describe('Test users with multiple servers', function () {
23 let servers: PeerTubeServer[] = []
24
25 let user: MyUser
26 let userId: number
27
28 let videoUUID: string
29 let userAccessToken: string
30 let userAvatarFilename: string
31
32 before(async function () {
33 this.timeout(120_000)
34
35 servers = await createMultipleServers(3)
36
37 // Get the access tokens
38 await setAccessTokensToServers(servers)
39
40 // Server 1 and server 2 follow each other
41 await doubleFollow(servers[0], servers[1])
42 // Server 1 and server 3 follow each other
43 await doubleFollow(servers[0], servers[2])
44 // Server 2 and server 3 follow each other
45 await doubleFollow(servers[1], servers[2])
46
47 // The root user of server 1 is propagated to servers 2 and 3
48 await servers[0].videos.upload()
49
50 {
51 const username = 'user1'
52 const created = await servers[0].users.create({ username })
53 userId = created.id
54 userAccessToken = await servers[0].login.getAccessToken(username)
55 }
56
57 {
58 const { uuid } = await servers[0].videos.upload({ token: userAccessToken })
59 videoUUID = uuid
60
61 await waitJobs(servers)
62
63 await saveVideoInServers(servers, videoUUID)
64 }
65 })
66
67 it('Should be able to update my display name', async function () {
68 this.timeout(10000)
69
70 await servers[0].users.updateMe({ displayName: 'my super display name' })
71
72 user = await servers[0].users.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].users.updateMe({ description: 'my super description updated' })
82
83 user = await servers[0].users.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].users.updateMyAvatar({ fixture })
96
97 user = await servers[0].users.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.accounts.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.accounts.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 { total, data } = await server.videos.listByAccount({ handle: 'user1@localhost:' + servers[0].port })
137
138 expect(total).to.equal(1)
139 expect(data).to.be.an('array')
140 expect(data).to.have.lengthOf(1)
141 expect(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 created = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: 'Kami no chikara' } })
149
150 await waitJobs(servers)
151
152 for (const server of servers) {
153 const { total, data } = await server.videos.listByAccount({ handle: 'user1@localhost:' + servers[0].port, search: 'Kami' })
154
155 expect(total).to.equal(1)
156 expect(data).to.be.an('array')
157 expect(data).to.have.lengthOf(1)
158 expect(data[0].uuid).to.equal(created.uuid)
159 }
160 })
161
162 it('Should remove the user', async function () {
163 this.timeout(10_000)
164
165 for (const server of servers) {
166 const body = await server.accounts.list({ sort: '-createdAt' })
167
168 const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
169 expect(accountDeleted).not.to.be.undefined
170
171 const { data } = await server.channels.list()
172 const videoChannelDeleted = data.find(a => a.displayName === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port)
173 expect(videoChannelDeleted).not.to.be.undefined
174 }
175
176 await servers[0].users.remove({ userId })
177
178 await waitJobs(servers)
179
180 for (const server of servers) {
181 const body = await server.accounts.list({ sort: '-createdAt' })
182
183 const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
184 expect(accountDeleted).to.be.undefined
185
186 const { data } = await server.channels.list()
187 const videoChannelDeleted = data.find(a => a.name === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port)
188 expect(videoChannelDeleted).to.be.undefined
189 }
190 })
191
192 it('Should not have actor files', async () => {
193 for (const server of servers) {
194 await checkActorFilesWereRemoved(userAvatarFilename, server.internalServerNumber)
195 }
196 })
197
198 it('Should not have video files', async () => {
199 for (const server of servers) {
200 await checkVideoFilesWereRemoved({ server, video: server.store.videoDetails })
201 }
202 })
203
204 it('Should have an empty tmp directory', async function () {
205 for (const server of servers) {
206 await checkTmpIsEmpty(server)
207 }
208 })
209
210 after(async function () {
211 await cleanupTests(servers)
212 })
213 })