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