]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/users/users-multiple-servers.ts
Fix nsfw filter
[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
2422c46b 16} from '../../utils'
8a19bee1 17import { getMyUserInformation, killallServers, ServerInfo, testImage, updateMyAvatar, uploadVideo } from '../../utils/index'
f05a1c30 18import { checkActorFilesWereRemoved, getAccount, getAccountsList } from '../../utils/users/accounts'
265ba139 19import { setAccessTokensToServers } from '../../utils/users/login'
6b738c7a
C
20import { User } from '../../../../shared/models/users'
21import { VideoChannel } from '../../../../shared/models/videos'
3cd0734f 22import { waitJobs } from '../../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
7b0956ec 151 await testImage(server.url, 'avatar2-resized', rootServer1Get.avatar.path, '.png')
265ba139
C
152 }
153 })
154
6b738c7a
C
155 it('Should list account videos', async function () {
156 for (const server of servers) {
ad9e39fb 157 const res = await getAccountVideos(server.url, server.accessToken, userAccountName, 0, 5)
6b738c7a
C
158
159 expect(res.body.total).to.equal(1)
160 expect(res.body.data).to.be.an('array')
161 expect(res.body.data).to.have.lengthOf(1)
162 expect(res.body.data[0].uuid).to.equal(videoUUID)
163 }
164 })
165
f05a1c30
C
166 it('Should remove the user', async function () {
167 this.timeout(10000)
168
169 for (const server of servers) {
170 const resAccounts = await getAccountsList(server.url, '-createdAt')
171
6b738c7a
C
172 const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:9001') as Account
173 expect(accountDeleted).not.to.be.undefined
174
175 const resVideoChannels = await getVideoChannelsList(server.url, 0, 10)
176 const videoChannelDeleted = resVideoChannels.body.data.find(a => {
8a19bee1 177 return a.displayName === 'Main user1 channel' && a.host === 'localhost:9001'
6b738c7a
C
178 }) as VideoChannel
179 expect(videoChannelDeleted).not.to.be.undefined
f05a1c30
C
180 }
181
182 await removeUser(servers[0].url, userId, servers[0].accessToken)
183
3cd0734f 184 await waitJobs(servers)
f05a1c30
C
185
186 for (const server of servers) {
187 const resAccounts = await getAccountsList(server.url, '-createdAt')
188
6b738c7a
C
189 const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:9001') as Account
190 expect(accountDeleted).to.be.undefined
191
192 const resVideoChannels = await getVideoChannelsList(server.url, 0, 10)
193 const videoChannelDeleted = resVideoChannels.body.data.find(a => {
8a19bee1 194 return a.name === 'Main user1 channel' && a.host === 'localhost:9001'
6b738c7a
C
195 }) as VideoChannel
196 expect(videoChannelDeleted).to.be.undefined
f05a1c30
C
197 }
198 })
199
200 it('Should not have actor files', async () => {
201 for (const server of servers) {
240085d0 202 await checkActorFilesWereRemoved(userAccountUUID, server.serverNumber)
6b738c7a 203 await checkActorFilesWereRemoved(userVideoChannelUUID, server.serverNumber)
f05a1c30
C
204 }
205 })
206
207 it('Should not have video files', async () => {
208 for (const server of servers) {
209 await checkVideoFilesWereRemoved(videoUUID, server.serverNumber)
210 }
211 })
212
265ba139
C
213 after(async function () {
214 killallServers(servers)
265ba139
C
215 })
216})