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