]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
265ba139 | 2 | |
265ba139 | 3 | import 'mocha' |
9fff08cf | 4 | import * as chai from 'chai' |
2422c46b | 5 | import { |
9fff08cf | 6 | checkActorFilesWereRemoved, |
f4800714 | 7 | checkTmpIsEmpty, |
57cfff78 C |
8 | checkVideoFilesWereRemoved, |
9 | cleanupTests, | |
6b738c7a C |
10 | createUser, |
11 | doubleFollow, | |
12 | flushAndRunMultipleServers, | |
13 | getAccountVideos, | |
9fff08cf | 14 | getMyUserInformation, |
6b738c7a | 15 | removeUser, |
9fff08cf C |
16 | ServerInfo, |
17 | setAccessTokensToServers, | |
18 | testImage, | |
19 | updateMyAvatar, | |
6b738c7a | 20 | updateMyUser, |
9fff08cf C |
21 | uploadVideo, |
22 | userLogin, | |
23 | waitJobs | |
24 | } from '@shared/extra-utils' | |
a5461888 | 25 | import { User } from '@shared/models' |
265ba139 C |
26 | |
27 | const expect = chai.expect | |
28 | ||
29 | describe('Test users with multiple servers', function () { | |
30 | let servers: ServerInfo[] = [] | |
6b738c7a | 31 | let user: User |
6b738c7a C |
32 | let userId: number |
33 | let videoUUID: string | |
34 | let userAccessToken: string | |
57cfff78 | 35 | let userAvatarFilename: string |
265ba139 C |
36 | |
37 | before(async function () { | |
37024082 | 38 | this.timeout(120_000) |
265ba139 C |
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 | } | |
1eddc9a7 | 60 | const res = await createUser({ |
a1587156 C |
61 | url: servers[0].url, |
62 | accessToken: servers[0].accessToken, | |
1eddc9a7 C |
63 | username: user.username, |
64 | password: user.password | |
65 | }) | |
6b738c7a | 66 | userId = res.body.user.id |
a1587156 | 67 | userAccessToken = await userLogin(servers[0], user) |
6b738c7a C |
68 | } |
69 | ||
6b738c7a | 70 | { |
a1587156 | 71 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, {}) |
6b738c7a C |
72 | videoUUID = resVideo.body.video.uuid |
73 | } | |
f05a1c30 | 74 | |
3cd0734f | 75 | await waitJobs(servers) |
265ba139 C |
76 | }) |
77 | ||
ed56ad11 C |
78 | it('Should be able to update my display name', async function () { |
79 | this.timeout(10000) | |
80 | ||
81 | await updateMyUser({ | |
82 | url: servers[0].url, | |
83 | accessToken: servers[0].accessToken, | |
84 | displayName: 'my super display name' | |
85 | }) | |
86 | ||
87 | const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) | |
88 | user = res.body | |
57cfff78 | 89 | |
ed56ad11 C |
90 | expect(user.account.displayName).to.equal('my super display name') |
91 | ||
3cd0734f | 92 | await waitJobs(servers) |
ed56ad11 C |
93 | }) |
94 | ||
2422c46b | 95 | it('Should be able to update my description', async function () { |
37024082 | 96 | this.timeout(10_000) |
2422c46b C |
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 | ||
3cd0734f | 109 | await waitJobs(servers) |
2422c46b C |
110 | }) |
111 | ||
265ba139 | 112 | it('Should be able to update my avatar', async function () { |
37024082 | 113 | this.timeout(10_000) |
265ba139 C |
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 | |
57cfff78 C |
126 | userAvatarFilename = user.account.avatar.path |
127 | ||
128 | await testImage(servers[0].url, 'avatar2-resized', userAvatarFilename, '.png') | |
265ba139 | 129 | |
3cd0734f | 130 | await waitJobs(servers) |
265ba139 C |
131 | }) |
132 | ||
ed56ad11 | 133 | it('Should have updated my profile on other servers too', async function () { |
a66c2e32 C |
134 | let createdAt: string | Date |
135 | ||
265ba139 | 136 | for (const server of servers) { |
9fff08cf | 137 | const body = await server.accountsCommand.list({ sort: '-createdAt' }) |
265ba139 | 138 | |
9fff08cf | 139 | const resList = body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port) |
a66c2e32 C |
140 | expect(resList).not.to.be.undefined |
141 | ||
9fff08cf | 142 | const account = await server.accountsCommand.get({ accountName: resList.name + '@' + resList.host }) |
a66c2e32 C |
143 | |
144 | if (!createdAt) createdAt = account.createdAt | |
265ba139 | 145 | |
a66c2e32 C |
146 | expect(account.name).to.equal('root') |
147 | expect(account.host).to.equal('localhost:' + servers[0].port) | |
148 | expect(account.displayName).to.equal('my super display name') | |
149 | expect(account.description).to.equal('my super description updated') | |
150 | expect(createdAt).to.equal(account.createdAt) | |
265ba139 | 151 | |
79bd2632 | 152 | if (server.serverNumber === 1) { |
a66c2e32 | 153 | expect(account.userId).to.be.a('number') |
79bd2632 | 154 | } else { |
a66c2e32 | 155 | expect(account.userId).to.be.undefined |
79bd2632 C |
156 | } |
157 | ||
a66c2e32 | 158 | await testImage(server.url, 'avatar2-resized', account.avatar.path, '.png') |
265ba139 C |
159 | } |
160 | }) | |
161 | ||
6b738c7a C |
162 | it('Should list account videos', async function () { |
163 | for (const server of servers) { | |
57cfff78 | 164 | const res = await getAccountVideos(server.url, server.accessToken, 'user1@localhost:' + servers[0].port, 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 | ||
37024082 RK |
173 | it('Should search through account videos', async function () { |
174 | this.timeout(10_000) | |
175 | ||
176 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'Kami no chikara' }) | |
177 | ||
178 | await waitJobs(servers) | |
179 | ||
180 | for (const server of servers) { | |
181 | const res = await getAccountVideos(server.url, server.accessToken, 'user1@localhost:' + servers[0].port, 0, 5, undefined, { | |
182 | search: 'Kami' | |
183 | }) | |
184 | ||
185 | expect(res.body.total).to.equal(1) | |
186 | expect(res.body.data).to.be.an('array') | |
187 | expect(res.body.data).to.have.lengthOf(1) | |
188 | expect(res.body.data[0].uuid).to.equal(resVideo.body.video.uuid) | |
189 | } | |
190 | }) | |
191 | ||
f05a1c30 | 192 | it('Should remove the user', async function () { |
37024082 | 193 | this.timeout(10_000) |
f05a1c30 C |
194 | |
195 | for (const server of servers) { | |
9fff08cf | 196 | const body = await server.accountsCommand.list({ sort: '-createdAt' }) |
f05a1c30 | 197 | |
9fff08cf | 198 | const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) |
6b738c7a C |
199 | expect(accountDeleted).not.to.be.undefined |
200 | ||
a5461888 C |
201 | const { data } = await server.channelsCommand.list() |
202 | const videoChannelDeleted = data.find(a => a.displayName === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port) | |
6b738c7a | 203 | expect(videoChannelDeleted).not.to.be.undefined |
f05a1c30 C |
204 | } |
205 | ||
206 | await removeUser(servers[0].url, userId, servers[0].accessToken) | |
207 | ||
3cd0734f | 208 | await waitJobs(servers) |
f05a1c30 C |
209 | |
210 | for (const server of servers) { | |
9fff08cf | 211 | const body = await server.accountsCommand.list({ sort: '-createdAt' }) |
f05a1c30 | 212 | |
9fff08cf | 213 | const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) |
6b738c7a C |
214 | expect(accountDeleted).to.be.undefined |
215 | ||
a5461888 C |
216 | const { data } = await server.channelsCommand.list() |
217 | const videoChannelDeleted = data.find(a => a.name === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port) | |
6b738c7a | 218 | expect(videoChannelDeleted).to.be.undefined |
f05a1c30 C |
219 | } |
220 | }) | |
221 | ||
222 | it('Should not have actor files', async () => { | |
223 | for (const server of servers) { | |
57cfff78 | 224 | await checkActorFilesWereRemoved(userAvatarFilename, server.internalServerNumber) |
f05a1c30 C |
225 | } |
226 | }) | |
227 | ||
228 | it('Should not have video files', async () => { | |
229 | for (const server of servers) { | |
48f07b4a | 230 | await checkVideoFilesWereRemoved(videoUUID, server.internalServerNumber) |
f05a1c30 C |
231 | } |
232 | }) | |
233 | ||
f4800714 C |
234 | it('Should have an empty tmp directory', async function () { |
235 | for (const server of servers) { | |
236 | await checkTmpIsEmpty(server) | |
237 | } | |
238 | }) | |
239 | ||
7c3b7976 C |
240 | after(async function () { |
241 | await cleanupTests(servers) | |
265ba139 C |
242 | }) |
243 | }) |