]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
5 | import { Account } from '../../../../shared/models/actors' | |
6 | import { | |
7 | checkTmpIsEmpty, | |
8 | checkVideoFilesWereRemoved, | |
9 | cleanupTests, | |
10 | createUser, | |
11 | doubleFollow, | |
12 | flushAndRunMultipleServers, | |
13 | getAccountVideos, | |
14 | getVideoChannelsList, | |
15 | removeUser, | |
16 | updateMyUser, | |
17 | userLogin | |
18 | } from '../../../../shared/extra-utils' | |
19 | import { getMyUserInformation, ServerInfo, testImage, updateMyAvatar, uploadVideo } from '../../../../shared/extra-utils/index' | |
20 | import { checkActorFilesWereRemoved, getAccount, getAccountsList } from '../../../../shared/extra-utils/users/accounts' | |
21 | import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' | |
22 | import { User } from '../../../../shared/models/users' | |
23 | import { VideoChannel } from '../../../../shared/models/videos' | |
24 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | |
25 | ||
26 | const expect = chai.expect | |
27 | ||
28 | describe('Test users with multiple servers', function () { | |
29 | let servers: ServerInfo[] = [] | |
30 | let user: User | |
31 | let userId: number | |
32 | let videoUUID: string | |
33 | let userAccessToken: string | |
34 | let userAvatarFilename: string | |
35 | ||
36 | before(async function () { | |
37 | this.timeout(120_000) | |
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 | ||
54 | { | |
55 | const user = { | |
56 | username: 'user1', | |
57 | password: 'password' | |
58 | } | |
59 | const res = await createUser({ | |
60 | url: servers[0].url, | |
61 | accessToken: servers[0].accessToken, | |
62 | username: user.username, | |
63 | password: user.password | |
64 | }) | |
65 | userId = res.body.user.id | |
66 | userAccessToken = await userLogin(servers[0], user) | |
67 | } | |
68 | ||
69 | { | |
70 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, {}) | |
71 | videoUUID = resVideo.body.video.uuid | |
72 | } | |
73 | ||
74 | await waitJobs(servers) | |
75 | }) | |
76 | ||
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 | |
88 | ||
89 | expect(user.account.displayName).to.equal('my super display name') | |
90 | ||
91 | await waitJobs(servers) | |
92 | }) | |
93 | ||
94 | it('Should be able to update my description', async function () { | |
95 | this.timeout(10_000) | |
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 | |
105 | expect(user.account.displayName).to.equal('my super display name') | |
106 | expect(user.account.description).to.equal('my super description updated') | |
107 | ||
108 | await waitJobs(servers) | |
109 | }) | |
110 | ||
111 | it('Should be able to update my avatar', async function () { | |
112 | this.timeout(10_000) | |
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) | |
123 | user = res.body | |
124 | ||
125 | userAvatarFilename = user.account.avatar.path | |
126 | ||
127 | await testImage(servers[0].url, 'avatar2-resized', userAvatarFilename, '.png') | |
128 | ||
129 | await waitJobs(servers) | |
130 | }) | |
131 | ||
132 | it('Should have updated my profile on other servers too', async function () { | |
133 | let createdAt: string | Date | |
134 | ||
135 | for (const server of servers) { | |
136 | const resAccounts = await getAccountsList(server.url, '-createdAt') | |
137 | ||
138 | const resList = resAccounts.body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port) as Account | |
139 | expect(resList).not.to.be.undefined | |
140 | ||
141 | const resAccount = await getAccount(server.url, resList.name + '@' + resList.host) | |
142 | const account = resAccount.body as Account | |
143 | ||
144 | if (!createdAt) createdAt = account.createdAt | |
145 | ||
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) | |
151 | ||
152 | if (server.serverNumber === 1) { | |
153 | expect(account.userId).to.be.a('number') | |
154 | } else { | |
155 | expect(account.userId).to.be.undefined | |
156 | } | |
157 | ||
158 | await testImage(server.url, 'avatar2-resized', account.avatar.path, '.png') | |
159 | } | |
160 | }) | |
161 | ||
162 | it('Should list account videos', async function () { | |
163 | for (const server of servers) { | |
164 | const res = await getAccountVideos(server.url, server.accessToken, 'user1@localhost:' + servers[0].port, 0, 5) | |
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 | ||
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 | ||
192 | it('Should remove the user', async function () { | |
193 | this.timeout(10_000) | |
194 | ||
195 | for (const server of servers) { | |
196 | const resAccounts = await getAccountsList(server.url, '-createdAt') | |
197 | ||
198 | const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) as Account | |
199 | expect(accountDeleted).not.to.be.undefined | |
200 | ||
201 | const resVideoChannels = await getVideoChannelsList(server.url, 0, 10) | |
202 | const videoChannelDeleted = resVideoChannels.body.data.find(a => { | |
203 | return a.displayName === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port | |
204 | }) as VideoChannel | |
205 | expect(videoChannelDeleted).not.to.be.undefined | |
206 | } | |
207 | ||
208 | await removeUser(servers[0].url, userId, servers[0].accessToken) | |
209 | ||
210 | await waitJobs(servers) | |
211 | ||
212 | for (const server of servers) { | |
213 | const resAccounts = await getAccountsList(server.url, '-createdAt') | |
214 | ||
215 | const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) as Account | |
216 | expect(accountDeleted).to.be.undefined | |
217 | ||
218 | const resVideoChannels = await getVideoChannelsList(server.url, 0, 10) | |
219 | const videoChannelDeleted = resVideoChannels.body.data.find(a => { | |
220 | return a.name === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port | |
221 | }) as VideoChannel | |
222 | expect(videoChannelDeleted).to.be.undefined | |
223 | } | |
224 | }) | |
225 | ||
226 | it('Should not have actor files', async () => { | |
227 | for (const server of servers) { | |
228 | await checkActorFilesWereRemoved(userAvatarFilename, server.internalServerNumber) | |
229 | } | |
230 | }) | |
231 | ||
232 | it('Should not have video files', async () => { | |
233 | for (const server of servers) { | |
234 | await checkVideoFilesWereRemoved(videoUUID, server.internalServerNumber) | |
235 | } | |
236 | }) | |
237 | ||
238 | it('Should have an empty tmp directory', async function () { | |
239 | for (const server of servers) { | |
240 | await checkTmpIsEmpty(server) | |
241 | } | |
242 | }) | |
243 | ||
244 | after(async function () { | |
245 | await cleanupTests(servers) | |
246 | }) | |
247 | }) |