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