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