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