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