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