]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/users/users-multiple-servers.ts
Add notifications in the client
[github/Chocobozzz/PeerTube.git] / server / tests / api / users / users-multiple-servers.ts
CommitLineData
265ba139
C
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import { Account } from '../../../../shared/models/actors'
2422c46b 6import {
6b738c7a
C
7 checkVideoFilesWereRemoved,
8 createUser,
9 doubleFollow,
10 flushAndRunMultipleServers,
11 getAccountVideos,
12 getVideoChannelsList,
13 removeUser,
14 updateMyUser,
8a19bee1 15 userLogin
9639bd17 16} from '../../../../shared/utils'
17import { getMyUserInformation, killallServers, ServerInfo, testImage, updateMyAvatar, uploadVideo } from '../../../../shared/utils/index'
18import { checkActorFilesWereRemoved, getAccount, getAccountsList } from '../../../../shared/utils/users/accounts'
19import { setAccessTokensToServers } from '../../../../shared/utils/users/login'
6b738c7a
C
20import { User } from '../../../../shared/models/users'
21import { VideoChannel } from '../../../../shared/models/videos'
9639bd17 22import { waitJobs } from '../../../../shared/utils/server/jobs'
265ba139
C
23
24const expect = chai.expect
25
26describe('Test users with multiple servers', function () {
27 let servers: ServerInfo[] = []
6b738c7a 28 let user: User
ad9e39fb 29 let userAccountName: string
240085d0 30 let userAccountUUID: string
6b738c7a
C
31 let userVideoChannelUUID: string
32 let userId: number
33 let videoUUID: string
34 let userAccessToken: string
265ba139
C
35
36 before(async function () {
37 this.timeout(120000)
38
39 servers = await flushAndRunMultipleServers(3)
40
41 // Get the access tokens
42 await setAccessTokensToServers(servers)
43
44 // Server 1 and server 2 follow each other
45 await doubleFollow(servers[0], servers[1])
46 // Server 1 and server 3 follow each other
47 await doubleFollow(servers[0], servers[2])
48 // Server 2 and server 3 follow each other
49 await doubleFollow(servers[1], servers[2])
50
51 // The root user of server 1 is propagated to servers 2 and 3
52 await uploadVideo(servers[0].url, servers[0].accessToken, {})
53
6b738c7a
C
54 {
55 const user = {
56 username: 'user1',
57 password: 'password'
58 }
59 const res = await createUser(servers[ 0 ].url, servers[ 0 ].accessToken, user.username, user.password)
6b738c7a 60 userId = res.body.user.id
6b738c7a
C
61 userAccessToken = await userLogin(servers[ 0 ], user)
62 }
63
ad9e39fb
C
64 {
65 const res = await getMyUserInformation(servers[0].url, userAccessToken)
240085d0
C
66 const account: Account = res.body.account
67 userAccountName = account.name + '@' + account.host
68 userAccountUUID = account.uuid
ad9e39fb
C
69 }
70
6b738c7a
C
71 {
72 const res = await getMyUserInformation(servers[ 0 ].url, servers[ 0 ].accessToken)
73 const user: User = res.body
74 userVideoChannelUUID = user.videoChannels[0].uuid
f05a1c30 75 }
f05a1c30 76
6b738c7a
C
77 {
78 const resVideo = await uploadVideo(servers[ 0 ].url, userAccessToken, {})
79 videoUUID = resVideo.body.video.uuid
80 }
f05a1c30 81
3cd0734f 82 await waitJobs(servers)
265ba139
C
83 })
84
ed56ad11
C
85 it('Should be able to update my display name', async function () {
86 this.timeout(10000)
87
88 await updateMyUser({
89 url: servers[0].url,
90 accessToken: servers[0].accessToken,
91 displayName: 'my super display name'
92 })
93
94 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
95 user = res.body
96 expect(user.account.displayName).to.equal('my super display name')
97
3cd0734f 98 await waitJobs(servers)
ed56ad11
C
99 })
100
2422c46b
C
101 it('Should be able to update my description', async function () {
102 this.timeout(10000)
103
104 await updateMyUser({
105 url: servers[0].url,
106 accessToken: servers[0].accessToken,
107 description: 'my super description updated'
108 })
109
110 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
111 user = res.body
ed56ad11 112 expect(user.account.displayName).to.equal('my super display name')
2422c46b
C
113 expect(user.account.description).to.equal('my super description updated')
114
3cd0734f 115 await waitJobs(servers)
2422c46b
C
116 })
117
265ba139
C
118 it('Should be able to update my avatar', async function () {
119 this.timeout(10000)
120
121 const fixture = 'avatar2.png'
122
123 await updateMyAvatar({
124 url: servers[0].url,
125 accessToken: servers[0].accessToken,
126 fixture
127 })
128
129 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
f05a1c30 130 user = res.body
265ba139 131
7b0956ec 132 await testImage(servers[0].url, 'avatar2-resized', user.account.avatar.path, '.png')
265ba139 133
3cd0734f 134 await waitJobs(servers)
265ba139
C
135 })
136
ed56ad11 137 it('Should have updated my profile on other servers too', async function () {
265ba139
C
138 for (const server of servers) {
139 const resAccounts = await getAccountsList(server.url, '-createdAt')
140
141 const rootServer1List = resAccounts.body.data.find(a => a.name === 'root' && a.host === 'localhost:9001') as Account
142 expect(rootServer1List).not.to.be.undefined
143
ad9e39fb 144 const resAccount = await getAccount(server.url, rootServer1List.name + '@' + rootServer1List.host)
265ba139
C
145 const rootServer1Get = resAccount.body as Account
146 expect(rootServer1Get.name).to.equal('root')
147 expect(rootServer1Get.host).to.equal('localhost:9001')
ed56ad11 148 expect(rootServer1Get.displayName).to.equal('my super display name')
2422c46b 149 expect(rootServer1Get.description).to.equal('my super description updated')
265ba139 150
79bd2632
C
151 if (server.serverNumber === 1) {
152 expect(rootServer1Get.userId).to.be.a('number')
153 } else {
154 expect(rootServer1Get.userId).to.be.undefined
155 }
156
7b0956ec 157 await testImage(server.url, 'avatar2-resized', rootServer1Get.avatar.path, '.png')
265ba139
C
158 }
159 })
160
6b738c7a
C
161 it('Should list account videos', async function () {
162 for (const server of servers) {
ad9e39fb 163 const res = await getAccountVideos(server.url, server.accessToken, userAccountName, 0, 5)
6b738c7a
C
164
165 expect(res.body.total).to.equal(1)
166 expect(res.body.data).to.be.an('array')
167 expect(res.body.data).to.have.lengthOf(1)
168 expect(res.body.data[0].uuid).to.equal(videoUUID)
169 }
170 })
171
f05a1c30
C
172 it('Should remove the user', async function () {
173 this.timeout(10000)
174
175 for (const server of servers) {
176 const resAccounts = await getAccountsList(server.url, '-createdAt')
177
6b738c7a
C
178 const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:9001') as Account
179 expect(accountDeleted).not.to.be.undefined
180
181 const resVideoChannels = await getVideoChannelsList(server.url, 0, 10)
182 const videoChannelDeleted = resVideoChannels.body.data.find(a => {
8a19bee1 183 return a.displayName === 'Main user1 channel' && a.host === 'localhost:9001'
6b738c7a
C
184 }) as VideoChannel
185 expect(videoChannelDeleted).not.to.be.undefined
f05a1c30
C
186 }
187
188 await removeUser(servers[0].url, userId, servers[0].accessToken)
189
3cd0734f 190 await waitJobs(servers)
f05a1c30
C
191
192 for (const server of servers) {
193 const resAccounts = await getAccountsList(server.url, '-createdAt')
194
6b738c7a
C
195 const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:9001') as Account
196 expect(accountDeleted).to.be.undefined
197
198 const resVideoChannels = await getVideoChannelsList(server.url, 0, 10)
199 const videoChannelDeleted = resVideoChannels.body.data.find(a => {
8a19bee1 200 return a.name === 'Main user1 channel' && a.host === 'localhost:9001'
6b738c7a
C
201 }) as VideoChannel
202 expect(videoChannelDeleted).to.be.undefined
f05a1c30
C
203 }
204 })
205
206 it('Should not have actor files', async () => {
207 for (const server of servers) {
240085d0 208 await checkActorFilesWereRemoved(userAccountUUID, server.serverNumber)
6b738c7a 209 await checkActorFilesWereRemoved(userVideoChannelUUID, server.serverNumber)
f05a1c30
C
210 }
211 })
212
213 it('Should not have video files', async () => {
214 for (const server of servers) {
215 await checkVideoFilesWereRemoved(videoUUID, server.serverNumber)
216 }
217 })
218
265ba139
C
219 after(async function () {
220 killallServers(servers)
265ba139
C
221 })
222})