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