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