]>
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' | |
f05a1c30 C |
6 | import { checkVideoFilesWereRemoved, createUser, doubleFollow, flushAndRunMultipleServers, removeUser, userLogin, wait } from '../../utils' |
7 | import { flushTests, getMyUserInformation, killallServers, ServerInfo, testImage, updateMyAvatar, uploadVideo } from '../../utils/index' | |
8 | import { checkActorFilesWereRemoved, getAccount, getAccountsList } from '../../utils/users/accounts' | |
265ba139 C |
9 | import { setAccessTokensToServers } from '../../utils/users/login' |
10 | ||
11 | const expect = chai.expect | |
12 | ||
13 | describe('Test users with multiple servers', function () { | |
14 | let servers: ServerInfo[] = [] | |
f05a1c30 C |
15 | let user |
16 | let userUUID | |
17 | let userId | |
18 | let videoUUID | |
19 | let userAccessToken | |
265ba139 C |
20 | |
21 | before(async function () { | |
22 | this.timeout(120000) | |
23 | ||
24 | servers = await flushAndRunMultipleServers(3) | |
25 | ||
26 | // Get the access tokens | |
27 | await setAccessTokensToServers(servers) | |
28 | ||
29 | // Server 1 and server 2 follow each other | |
30 | await doubleFollow(servers[0], servers[1]) | |
31 | // Server 1 and server 3 follow each other | |
32 | await doubleFollow(servers[0], servers[2]) | |
33 | // Server 2 and server 3 follow each other | |
34 | await doubleFollow(servers[1], servers[2]) | |
35 | ||
36 | // The root user of server 1 is propagated to servers 2 and 3 | |
37 | await uploadVideo(servers[0].url, servers[0].accessToken, {}) | |
38 | ||
f05a1c30 C |
39 | const user = { |
40 | username: 'user1', | |
41 | password: 'password' | |
42 | } | |
43 | const resUser = await createUser(servers[0].url, servers[0].accessToken, user.username, user.password) | |
44 | userUUID = resUser.body.user.uuid | |
45 | userId = resUser.body.user.id | |
46 | userAccessToken = await userLogin(servers[0], user) | |
47 | ||
48 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, {}) | |
49 | videoUUID = resVideo.body.uuid | |
50 | ||
265ba139 C |
51 | await wait(5000) |
52 | }) | |
53 | ||
54 | it('Should be able to update my avatar', async function () { | |
55 | this.timeout(10000) | |
56 | ||
57 | const fixture = 'avatar2.png' | |
58 | ||
59 | await updateMyAvatar({ | |
60 | url: servers[0].url, | |
61 | accessToken: servers[0].accessToken, | |
62 | fixture | |
63 | }) | |
64 | ||
65 | const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) | |
f05a1c30 | 66 | user = res.body |
265ba139 | 67 | |
7b0956ec | 68 | await testImage(servers[0].url, 'avatar2-resized', user.account.avatar.path, '.png') |
265ba139 C |
69 | |
70 | await wait(5000) | |
71 | }) | |
72 | ||
73 | it('Should have updated my avatar on other servers too', async function () { | |
74 | for (const server of servers) { | |
75 | const resAccounts = await getAccountsList(server.url, '-createdAt') | |
76 | ||
77 | const rootServer1List = resAccounts.body.data.find(a => a.name === 'root' && a.host === 'localhost:9001') as Account | |
78 | expect(rootServer1List).not.to.be.undefined | |
79 | ||
80 | const resAccount = await getAccount(server.url, rootServer1List.id) | |
81 | const rootServer1Get = resAccount.body as Account | |
82 | expect(rootServer1Get.name).to.equal('root') | |
83 | expect(rootServer1Get.host).to.equal('localhost:9001') | |
84 | ||
7b0956ec | 85 | await testImage(server.url, 'avatar2-resized', rootServer1Get.avatar.path, '.png') |
265ba139 C |
86 | } |
87 | }) | |
88 | ||
f05a1c30 C |
89 | it('Should remove the user', async function () { |
90 | this.timeout(10000) | |
91 | ||
92 | for (const server of servers) { | |
93 | const resAccounts = await getAccountsList(server.url, '-createdAt') | |
94 | ||
95 | const userServer1List = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:9001') as Account | |
96 | expect(userServer1List).not.to.be.undefined | |
97 | } | |
98 | ||
99 | await removeUser(servers[0].url, userId, servers[0].accessToken) | |
100 | ||
101 | await wait(5000) | |
102 | ||
103 | for (const server of servers) { | |
104 | const resAccounts = await getAccountsList(server.url, '-createdAt') | |
105 | ||
106 | const userServer1List = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:9001') as Account | |
107 | expect(userServer1List).to.be.undefined | |
108 | } | |
109 | }) | |
110 | ||
111 | it('Should not have actor files', async () => { | |
112 | for (const server of servers) { | |
113 | await checkActorFilesWereRemoved(userUUID, server.serverNumber) | |
114 | } | |
115 | }) | |
116 | ||
117 | it('Should not have video files', async () => { | |
118 | for (const server of servers) { | |
119 | await checkVideoFilesWereRemoved(videoUUID, server.serverNumber) | |
120 | } | |
121 | }) | |
122 | ||
265ba139 C |
123 | after(async function () { |
124 | killallServers(servers) | |
125 | ||
126 | // Keep the logs if the test failed | |
127 | if (this[ 'ok' ]) { | |
128 | await flushTests() | |
129 | } | |
130 | }) | |
131 | }) |