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