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