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