]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
265ba139 | 2 | |
265ba139 | 3 | import 'mocha' |
9fff08cf | 4 | import * as chai from 'chai' |
2422c46b | 5 | import { |
9fff08cf | 6 | checkActorFilesWereRemoved, |
f4800714 | 7 | checkTmpIsEmpty, |
57cfff78 C |
8 | checkVideoFilesWereRemoved, |
9 | cleanupTests, | |
254d3579 | 10 | createMultipleServers, |
4c7e60bc | 11 | doubleFollow, |
254d3579 | 12 | PeerTubeServer, |
83903cb6 | 13 | saveVideoInServers, |
9fff08cf C |
14 | setAccessTokensToServers, |
15 | testImage, | |
9fff08cf C |
16 | waitJobs |
17 | } from '@shared/extra-utils' | |
83903cb6 | 18 | import { MyUser } from '@shared/models' |
265ba139 C |
19 | |
20 | const expect = chai.expect | |
21 | ||
22 | describe('Test users with multiple servers', function () { | |
254d3579 | 23 | let servers: PeerTubeServer[] = [] |
83903cb6 C |
24 | |
25 | let user: MyUser | |
6b738c7a | 26 | let userId: number |
83903cb6 | 27 | |
6b738c7a C |
28 | let videoUUID: string |
29 | let userAccessToken: string | |
57cfff78 | 30 | let userAvatarFilename: string |
265ba139 C |
31 | |
32 | before(async function () { | |
37024082 | 33 | this.timeout(120_000) |
265ba139 | 34 | |
254d3579 | 35 | servers = await createMultipleServers(3) |
265ba139 C |
36 | |
37 | // Get the access tokens | |
38 | await setAccessTokensToServers(servers) | |
39 | ||
40 | // Server 1 and server 2 follow each other | |
41 | await doubleFollow(servers[0], servers[1]) | |
42 | // Server 1 and server 3 follow each other | |
43 | await doubleFollow(servers[0], servers[2]) | |
44 | // Server 2 and server 3 follow each other | |
45 | await doubleFollow(servers[1], servers[2]) | |
46 | ||
47 | // The root user of server 1 is propagated to servers 2 and 3 | |
89d241a7 | 48 | await servers[0].videos.upload() |
265ba139 | 49 | |
6b738c7a | 50 | { |
83903cb6 C |
51 | const username = 'user1' |
52 | const created = await servers[0].users.create({ username }) | |
7926c5f9 | 53 | userId = created.id |
83903cb6 | 54 | userAccessToken = await servers[0].login.getAccessToken(username) |
6b738c7a C |
55 | } |
56 | ||
6b738c7a | 57 | { |
89d241a7 | 58 | const { uuid } = await servers[0].videos.upload({ token: userAccessToken }) |
d23dd9fb | 59 | videoUUID = uuid |
83903cb6 | 60 | |
764b1a14 C |
61 | await waitJobs(servers) |
62 | ||
83903cb6 | 63 | await saveVideoInServers(servers, videoUUID) |
6b738c7a | 64 | } |
265ba139 C |
65 | }) |
66 | ||
ed56ad11 C |
67 | it('Should be able to update my display name', async function () { |
68 | this.timeout(10000) | |
69 | ||
89d241a7 | 70 | await servers[0].users.updateMe({ displayName: 'my super display name' }) |
57cfff78 | 71 | |
89d241a7 | 72 | user = await servers[0].users.getMyInfo() |
ed56ad11 C |
73 | expect(user.account.displayName).to.equal('my super display name') |
74 | ||
3cd0734f | 75 | await waitJobs(servers) |
ed56ad11 C |
76 | }) |
77 | ||
2422c46b | 78 | it('Should be able to update my description', async function () { |
37024082 | 79 | this.timeout(10_000) |
2422c46b | 80 | |
89d241a7 | 81 | await servers[0].users.updateMe({ description: 'my super description updated' }) |
2422c46b | 82 | |
89d241a7 | 83 | user = await servers[0].users.getMyInfo() |
ed56ad11 | 84 | expect(user.account.displayName).to.equal('my super display name') |
2422c46b C |
85 | expect(user.account.description).to.equal('my super description updated') |
86 | ||
3cd0734f | 87 | await waitJobs(servers) |
2422c46b C |
88 | }) |
89 | ||
265ba139 | 90 | it('Should be able to update my avatar', async function () { |
37024082 | 91 | this.timeout(10_000) |
265ba139 C |
92 | |
93 | const fixture = 'avatar2.png' | |
94 | ||
89d241a7 | 95 | await servers[0].users.updateMyAvatar({ fixture }) |
265ba139 | 96 | |
89d241a7 | 97 | user = await servers[0].users.getMyInfo() |
57cfff78 C |
98 | userAvatarFilename = user.account.avatar.path |
99 | ||
100 | await testImage(servers[0].url, 'avatar2-resized', userAvatarFilename, '.png') | |
265ba139 | 101 | |
3cd0734f | 102 | await waitJobs(servers) |
265ba139 C |
103 | }) |
104 | ||
ed56ad11 | 105 | it('Should have updated my profile on other servers too', async function () { |
a66c2e32 C |
106 | let createdAt: string | Date |
107 | ||
265ba139 | 108 | for (const server of servers) { |
89d241a7 | 109 | const body = await server.accounts.list({ sort: '-createdAt' }) |
265ba139 | 110 | |
9fff08cf | 111 | const resList = body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port) |
a66c2e32 C |
112 | expect(resList).not.to.be.undefined |
113 | ||
89d241a7 | 114 | const account = await server.accounts.get({ accountName: resList.name + '@' + resList.host }) |
a66c2e32 C |
115 | |
116 | if (!createdAt) createdAt = account.createdAt | |
265ba139 | 117 | |
a66c2e32 C |
118 | expect(account.name).to.equal('root') |
119 | expect(account.host).to.equal('localhost:' + servers[0].port) | |
120 | expect(account.displayName).to.equal('my super display name') | |
121 | expect(account.description).to.equal('my super description updated') | |
122 | expect(createdAt).to.equal(account.createdAt) | |
265ba139 | 123 | |
79bd2632 | 124 | if (server.serverNumber === 1) { |
a66c2e32 | 125 | expect(account.userId).to.be.a('number') |
79bd2632 | 126 | } else { |
a66c2e32 | 127 | expect(account.userId).to.be.undefined |
79bd2632 C |
128 | } |
129 | ||
a66c2e32 | 130 | await testImage(server.url, 'avatar2-resized', account.avatar.path, '.png') |
265ba139 C |
131 | } |
132 | }) | |
133 | ||
6b738c7a C |
134 | it('Should list account videos', async function () { |
135 | for (const server of servers) { | |
c0e8b12e | 136 | const { total, data } = await server.videos.listByAccount({ handle: 'user1@localhost:' + servers[0].port }) |
6b738c7a | 137 | |
d23dd9fb C |
138 | expect(total).to.equal(1) |
139 | expect(data).to.be.an('array') | |
140 | expect(data).to.have.lengthOf(1) | |
141 | expect(data[0].uuid).to.equal(videoUUID) | |
6b738c7a C |
142 | } |
143 | }) | |
144 | ||
37024082 RK |
145 | it('Should search through account videos', async function () { |
146 | this.timeout(10_000) | |
147 | ||
89d241a7 | 148 | const created = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: 'Kami no chikara' } }) |
37024082 RK |
149 | |
150 | await waitJobs(servers) | |
151 | ||
152 | for (const server of servers) { | |
c0e8b12e | 153 | const { total, data } = await server.videos.listByAccount({ handle: 'user1@localhost:' + servers[0].port, search: 'Kami' }) |
d23dd9fb C |
154 | |
155 | expect(total).to.equal(1) | |
156 | expect(data).to.be.an('array') | |
157 | expect(data).to.have.lengthOf(1) | |
158 | expect(data[0].uuid).to.equal(created.uuid) | |
37024082 RK |
159 | } |
160 | }) | |
161 | ||
f05a1c30 | 162 | it('Should remove the user', async function () { |
37024082 | 163 | this.timeout(10_000) |
f05a1c30 C |
164 | |
165 | for (const server of servers) { | |
89d241a7 | 166 | const body = await server.accounts.list({ sort: '-createdAt' }) |
f05a1c30 | 167 | |
9fff08cf | 168 | const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) |
6b738c7a C |
169 | expect(accountDeleted).not.to.be.undefined |
170 | ||
89d241a7 | 171 | const { data } = await server.channels.list() |
a5461888 | 172 | const videoChannelDeleted = data.find(a => a.displayName === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port) |
6b738c7a | 173 | expect(videoChannelDeleted).not.to.be.undefined |
f05a1c30 C |
174 | } |
175 | ||
89d241a7 | 176 | await servers[0].users.remove({ userId }) |
f05a1c30 | 177 | |
3cd0734f | 178 | await waitJobs(servers) |
f05a1c30 C |
179 | |
180 | for (const server of servers) { | |
89d241a7 | 181 | const body = await server.accounts.list({ sort: '-createdAt' }) |
f05a1c30 | 182 | |
9fff08cf | 183 | const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) |
6b738c7a C |
184 | expect(accountDeleted).to.be.undefined |
185 | ||
89d241a7 | 186 | const { data } = await server.channels.list() |
a5461888 | 187 | const videoChannelDeleted = data.find(a => a.name === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port) |
6b738c7a | 188 | expect(videoChannelDeleted).to.be.undefined |
f05a1c30 C |
189 | } |
190 | }) | |
191 | ||
192 | it('Should not have actor files', async () => { | |
193 | for (const server of servers) { | |
57cfff78 | 194 | await checkActorFilesWereRemoved(userAvatarFilename, server.internalServerNumber) |
f05a1c30 C |
195 | } |
196 | }) | |
197 | ||
198 | it('Should not have video files', async () => { | |
199 | for (const server of servers) { | |
83903cb6 | 200 | await checkVideoFilesWereRemoved({ server, video: server.store.videoDetails }) |
f05a1c30 C |
201 | } |
202 | }) | |
203 | ||
f4800714 C |
204 | it('Should have an empty tmp directory', async function () { |
205 | for (const server of servers) { | |
206 | await checkTmpIsEmpty(server) | |
207 | } | |
208 | }) | |
209 | ||
7c3b7976 C |
210 | after(async function () { |
211 | await cleanupTests(servers) | |
265ba139 C |
212 | }) |
213 | }) |